← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15929: support optionSets in smartphone aggregate entry

 

------------------------------------------------------------
revno: 15929
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-07-01 18:59:57 +0800
message:
  support optionSets in smartphone aggregate entry
modified:
  dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm
  dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/dhis-web-mobile-resources/js/dhis2.storage.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm	2014-07-01 09:03:58 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm	2014-07-01 10:59:57 +0000
@@ -176,6 +176,7 @@
         _.template(tmpl, {
           'form': form,
           'valueMap': valueMap,
+          optionSets: fm.optionSets(),
           periodName: Selected.periodName,
           orgUnitName: Selected.orgUnitName
         })
@@ -376,7 +377,15 @@
                     <label for='<%= fieldId %>'><%= field.label %></label>
 
                     <% if( field.type == 'TEXT' ) { %>
-                        <input type="text" id='<%= fieldId %>' name='<%= fieldId %>' data-dataElement='<%= field.dataElement %>' data-categoryOptionCombo='<%= field.categoryOptionCombo %>' maxlength="255" value="<%= value %>" />
+                        <% if( field.optionSet ) { %>
+                            <select type="" id='<%= fieldId %>' name='<%= fieldId %>' data-dataElement='<%= field.dataElement %>' data-categoryOptionCombo='<%= field.categoryOptionCombo %>' maxlength="255">
+                            <% for( var i=0,len=optionSets[field.optionSet].length; i<len; i++) { %>
+                                <option value="<%= optionSets[field.optionSet][i] %>" <% if( value == optionSets[field.optionSet][i] ) { %> selected="selected" <% } %>> <%= optionSets[field.optionSet][i] %></option>
+                            <% } %>
+                            </select>
+                        <% } else { %>
+                            <input type="text" id='<%= fieldId %>' name='<%= fieldId %>' data-dataElement='<%= field.dataElement %>' data-categoryOptionCombo='<%= field.categoryOptionCombo %>' maxlength="255" value="<%= value %>" />
+                        <% } %>
                     <% } else if( field.type == 'LONG_TEXT' ) { %>
                         <input type="text" id='<%= fieldId %>' name='<%= fieldId %>' data-dataElement='<%= field.dataElement %>' data-categoryOptionCombo='<%= field.categoryOptionCombo %>' maxlength="255" value="<%= value %>" />
                     <% } else if( field.type == 'DATE' ) { %>

=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/dhis-web-mobile-resources/js/dhis2.storage.js'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/dhis-web-mobile-resources/js/dhis2.storage.js	2014-07-01 10:10:50 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/dhis-web-mobile-resources/js/dhis2.storage.js	2014-07-01 10:59:57 +0000
@@ -37,13 +37,14 @@
 
 dhis2.storage.FormManager.prototype.getMetaData = function () {
     return $.ajax({
-        url         : '../api/currentUser/assignedDataSets',
+        url         : '../api/currentUser/assignedDataSets?optionSets=true',
         dataType    : 'json',
         cache       : false
     }).success(function ( data ) {
         // clear out old localStorage, some phones doesn't like it when you overwrite old keys
         localStorage.removeItem('mobileOrganisationUnits');
         localStorage.removeItem('mobileForms');
+        localStorage.removeItem('mobileOptionSets');
 
         if( data.organisationUnits ) {
             localStorage.setItem('mobileOrganisationUnits', JSON.stringify(data.organisationUnits));
@@ -56,6 +57,12 @@
         } else {
             localStorage.setItem('mobileForms', JSON.stringify({}));
         }
+
+        if( data.optionSets ) {
+            localStorage.setItem('mobileOptionSets', JSON.stringify(data.optionSets));
+        } else {
+            localStorage.setItem('mobileOptionSets', JSON.stringify({}));
+        }
     });
 };
 
@@ -83,6 +90,22 @@
     return this.organisationUnit(id).dataSets;
 };
 
+dhis2.storage.FormManager.prototype.optionSets = function() {
+    if( this._optionSets === undefined ) {
+        var optionSets = localStorage.getItem('mobileOptionSets');
+
+        if( optionSets != null && optionSets != "null" ) {
+            this._optionSets = JSON.parse(optionSets);
+        }
+    }
+
+    return this._optionSets;
+};
+
+dhis2.storage.FormManager.prototype.optionSet = function( id ) {
+  return this.optionSets()[id];
+};
+
 dhis2.storage.FormManager.prototype.forms = function () {
     if( this._forms === undefined ) {
         var form = localStorage.getItem('mobileForms');