← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11678: wip, ouwt switch to new storage engine (async done). Also fixed some issues with saving in data-e...

 

------------------------------------------------------------
revno: 11678
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-08-16 13:10:51 +0200
message:
  wip, ouwt switch to new storage engine (async done). Also fixed some issues with saving in data-entry.
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/cacheManifest.vm
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.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-caseentry/src/main/webapp/dhis-web-caseentry/cacheManifest.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/cacheManifest.vm	2013-08-06 06:40:06 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/cacheManifest.vm	2013-08-16 11:10:51 +0000
@@ -1,5 +1,5 @@
 CACHE MANIFEST
-# 2.13-SNAPSHOT V4
+# 2.13-SNAPSHOT V5
 NETWORK:
 *
 CACHE:

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm	2013-08-14 11:04:31 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm	2013-08-16 11:10:51 +0000
@@ -1,5 +1,5 @@
 CACHE MANIFEST
-# 2.13-SNAPSHOT V5
+# 2.13-SNAPSHOT V6
 NETWORK:
 *
 CACHE:

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js	2013-08-15 14:46:44 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js	2013-08-16 11:10:51 +0000
@@ -1,5 +1,6 @@
 // -----------------------------------------------------------------------------
 // Author:   Torgeir Lorange Ostby
+// Author:   Morten Olav Hansen
 // -----------------------------------------------------------------------------
 
 /*
@@ -134,37 +135,45 @@
     };
 
     this.getOrganisationUnits = function() {
-        var organisationUnits = {};
+        var def = $.Deferred();
 
         dhis2.ou.store.getAll( 'ou' ).done( function( all ) {
+            var ous = {};
+
             $.each( all, function( i, item ) {
-                organisationUnits[item.id] = item;
+                ous[item.id] = item;
             } );
+
+            def.resolveWith( window, [ ous ]);
         } );
 
-        return organisationUnits;
+        return def.promise();
     };
 
-    this.setOrganisationUnits = function( organisationUnits ) {
-        organisationUnits = organisationUnits ? _.values( organisationUnits ) : [];
-        return dhis2.ou.store.setAll( 'ou', organisationUnits );
+    this.setOrganisationUnits = function( ous ) {
+        ous = ous ? _.values( ous ) : [];
+        return dhis2.ou.store.setAll( 'ou', ous );
     };
 
     this.getPartialOrganisationUnits = function() {
-        var organisationUnits = {};
+        var def = $.Deferred();
 
         dhis2.ou.store.getAll( 'ouPartial' ).done( function( all ) {
+            var ous = {};
+
             $.each( all, function( i, item ) {
-                organisationUnits[item.id] = item;
+                ous[item.id] = item;
             } );
+
+            def.resolveWith( window, [ ous ]);
         } );
 
-        return organisationUnits;
+        return def.promise();
     };
 
-    this.setPartialOrganisationUnits = function( organisationUnits ) {
-        organisationUnits = organisationUnits ? _.values( organisationUnits ) : [];
-        return dhis2.ou.store.setAll( 'ouPartial', organisationUnits );
+    this.setPartialOrganisationUnits = function( ous ) {
+        ous = ous ? _.values( ous ) : [];
+        return dhis2.ou.store.setAll( 'ouPartial', ous );
     };
 
     this.ajaxOrganisationUnits = function( versionOnly, format ) {
@@ -200,13 +209,18 @@
                 }
             }
 
-            organisationUnits = selection.getOrganisationUnits();
-            $.extend( organisationUnits, selection.getPartialOrganisationUnits() );
-
-            selection.sync();
-            subtree.reloadTree();
-
-            $( "#ouwt_loader" ).hide();
+            selection.getOrganisationUnits().done( function( all ) {
+                $.extend( organisationUnits, all );
+
+                selection.getPartialOrganisationUnits().done( function( all ) {
+                    $.extend( organisationUnits, all );
+
+                    selection.sync();
+                    subtree.reloadTree();
+
+                    $( "#ouwt_loader" ).hide();
+                } );
+            } );
         }
 
         function update_required( remoteVersion, remoteRoots ) {
@@ -419,25 +433,27 @@
                 ids.push( item );
                 names.push( name );
             } );
+
+            listenerFunction( ids, names, children );
         } else {
+            selected = selected[0];
+
             // we only support includeChildren for single selects
             if( includeChildren ) {
                 children = organisationUnits[selected].c;
             }
 
-            $.extend( organisationUnits, selection.getPartialOrganisationUnits() );
-
-            var name = organisationUnits[selected].n;
-            ids.push( +selected );
-            names.push( name );
-        }
-
-        if( !multipleSelectionAllowed ) {
-            subtree.getChildren( selected ).done( function() {
-                listenerFunction( ids, names, children );
+            selection.getPartialOrganisationUnits().done( function( all ) {
+                $.extend( organisationUnits, all );
+
+                var name = organisationUnits[selected].n;
+                ids.push( +selected );
+                names.push( name );
+
+                subtree.getChildren( selected ).done( function() {
+                    listenerFunction( ids, names, children );
+                } );
             } );
-        } else {
-            listenerFunction( ids, names, children );
         }
     };
 
@@ -473,15 +489,16 @@
                 data: { byName: name }
             } ).done(function( data ) {
                 if( data.realRoot === undefined ) {
-                    var partialOrganisationUnits = selection.getPartialOrganisationUnits();
-                    $.extend( partialOrganisationUnits, data.organisationUnits );
-                    selection.setPartialOrganisationUnits( partialOrganisationUnits );
+                    selection.getPartialOrganisationUnits().done(function(all) {
+                        $.extend( all, data.organisationUnits );
 
-                    $.extend( organisationUnits, data.organisationUnits );
-                    selection.findByName();
+                        selection.setPartialOrganisationUnits( all ).done(function() {
+                            $.extend( organisationUnits, data.organisationUnits );
+                            selection.findByName();
+                            $( '#searchField' ).css( 'background-color', '#ffc5c5' );
+                        });
+                    });
                 }
-
-                $( '#searchField' ).css( 'background-color', '#ffc5c5' );
             } ).fail( function() {
                 $( '#searchField' ).css( 'background-color', '#ffc5c5' );
             } );
@@ -635,11 +652,13 @@
 
     this.getChildren = function( parentId ) {
         return $.post( '../dhis-web-commons-ajax-json/getOrganisationUnitTree.action?parentId=' + parentId, function( data ) {
-                var partialOrganisationUnits = selection.getPartialOrganisationUnits();
-                $.extend( partialOrganisationUnits, data.organisationUnits );
-                selection.setPartialOrganisationUnits( partialOrganisationUnits );
+                selection.getPartialOrganisationUnits().done(function(all) {
+                    $.extend( all, data.organisationUnits );
 
-                $.extend( organisationUnits, data.organisationUnits );
+                    selection.setPartialOrganisationUnits( all ).done(function() {
+                        $.extend( organisationUnits, data.organisationUnits );
+                    });
+                });
             }
         );
     };

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2013-08-12 20:59:22 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2013-08-16 11:10:51 +0000
@@ -182,7 +182,7 @@
 
                 if ( valueNo < min )
                 {
-                    var valueSaver = new ValueSaver( dataElementId, optionComboId, currentOrganisationUnitId, periodId,
+                    var valueSaver = new ValueSaver( dataElementId, optionComboId, getCurrentOrganisationUnit(), periodId,
                             value, fieldId, COLOR_ORANGE );
                     valueSaver.save();
 
@@ -192,7 +192,7 @@
 
                 if ( valueNo > max )
                 {
-                    var valueSaver = new ValueSaver( dataElementId, optionComboId, currentOrganisationUnitId, periodId,
+                    var valueSaver = new ValueSaver( dataElementId, optionComboId, getCurrentOrganisationUnit(), periodId,
                             value, fieldId, COLOR_ORANGE );
                     valueSaver.save();
 
@@ -204,7 +204,7 @@
     }
 
     var valueSaver = new ValueSaver( dataElementId, optionComboId, 
-    	currentOrganisationUnitId, periodId, value, fieldId, COLOR_GREEN );
+    	getCurrentOrganisationUnit(), periodId, value, fieldId, COLOR_GREEN );
     valueSaver.save();
 
     updateIndicators(); // Update indicators for custom form
@@ -222,7 +222,7 @@
     var periodId = $( '#selectedPeriodId' ).val();
 
     var valueSaver = new ValueSaver( dataElementId, optionComboId, 
-    	currentOrganisationUnitId, periodId, value, fieldId, COLOR_GREEN );
+    	getCurrentOrganisationUnit(), periodId, value, fieldId, COLOR_GREEN );
     valueSaver.save();
 }
 
@@ -239,7 +239,7 @@
     var periodId = $( '#selectedPeriodId' ).val();
 
     var valueSaver = new ValueSaver( dataElementId, optionComboId,
-    	currentOrganisationUnitId, periodId, value, fieldId, COLOR_GREEN );
+        getCurrentOrganisationUnit(), periodId, value, fieldId, COLOR_GREEN );
     valueSaver.save();
 }
 

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2013-08-15 14:45:52 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2013-08-16 11:10:51 +0000
@@ -80,6 +80,14 @@
 
 var DAO = DAO || {};
 
+function getCurrentOrganisationUnit() {
+    if( $.isArray( currentOrganisationUnitId ) ) {
+        return currentOrganisationUnitId[0];
+    }
+
+    return currentOrganisationUnitId;
+}
+
 DAO.store = new dhis2.storage.Store( {
     name: 'dhis2',
     adapters: [ dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter ],
@@ -115,8 +123,11 @@
     $( '#orgUnitTree' ).one( 'ouwtLoaded', function()
     {
         log( 'Ouwt loaded' );
-        organisationUnits = selection.getOrganisationUnits();
-        loadMetaData();
+
+        selection.getOrganisationUnits().done(function(all) {
+            organisationUnits = all;
+            loadMetaData();
+        });
     } );
 
     $( document ).bind( 'dhis2.online', function( event, loggedIn )
@@ -521,7 +532,7 @@
 
 function loadForm( dataSetId, multiOrg )
 {
-    currentOrganisationUnitId = selection.getSelected();
+    currentOrganisationUnitId = selection.getSelected()[0];
 
     if ( !multiOrg && storageManager.formExists( dataSetId ) )
     {
@@ -552,7 +563,7 @@
         $( '#contentDiv' ).load( 'loadForm.action', 
         {
             dataSetId : dataSetId,
-            multiOrganisationUnit: multiOrg ? currentOrganisationUnitId : 0
+            multiOrganisationUnit: multiOrg ? getCurrentOrganisationUnit() : 0
         }, 
         function() 
         {
@@ -672,7 +683,7 @@
     }
     else
     {
-        split.organisationUnitId = currentOrganisationUnitId;
+        split.organisationUnitId = getCurrentOrganisationUnit();
         split.dataElementId = id.split( '-' )[0];
         split.optionComboId = id.split( '-' )[1];
     }
@@ -733,7 +744,7 @@
  */
 function getSortedDataSetList( orgUnit )
 {
-    var associationSet = orgUnit !== undefined ? organisationUnitAssociationSetMap[orgUnit] : organisationUnitAssociationSetMap[currentOrganisationUnitId];
+    var associationSet = orgUnit !== undefined ? organisationUnitAssociationSetMap[orgUnit] : organisationUnitAssociationSetMap[getCurrentOrganisationUnit()];
     var orgUnitDataSets = dataSetAssociationSets[associationSet];
 
     var dataSetList = [];
@@ -1022,7 +1033,8 @@
     $( '#undoButton' ).attr( 'disabled', 'disabled' );
     $( '#infoDiv' ).css( 'display', 'none' );
 
-    currentOrganisationUnitId = selection.getSelected();
+    currentOrganisationUnitId = selection.getSelected()[0];
+
     insertDataValues();
     displayEntryFormCompleted();
 }
@@ -1058,7 +1070,7 @@
 	    {
 	        periodId : periodId,
 	        dataSetId : dataSetId,
-	        organisationUnitId : currentOrganisationUnitId[0],
+	        organisationUnitId : getCurrentOrganisationUnit(),
             multiOrganisationUnit: multiOrganisationUnit
 	    },
 	    dataType: 'json',
@@ -1205,7 +1217,7 @@
 
     var dataElementName = getDataElementName( dataElementId );
     var optionComboName = getOptionComboName( optionComboId );
-    var organisationUnitName = organisationUnits[currentOrganisationUnitId].n;
+    var organisationUnitName = organisationUnits[getCurrentOrganisationUnit()].n;
 
     $( '#currentOrganisationUnit' ).html( organisationUnitName );
     $( '#currentDataElement' ).html( dataElementName + ' ' + optionComboName );
@@ -1545,7 +1557,7 @@
 	        dataElementId : dataElementId,
 	        optionComboId : optionComboId,
 	        periodId : periodId,
-	        organisationUnitId : currentOrganisationUnitId
+	        organisationUnitId : getCurrentOrganisationUnit()
 	    }, 
 	    function( response, status, xhr )
 	    {
@@ -2026,7 +2038,7 @@
         var params = {
             'periodId' : $( '#selectedPeriodId' ).val(),
             'dataSetId' : $( '#selectedDataSetId' ).val(),
-            'organisationUnitId' : currentOrganisationUnitId
+            'organisationUnitId' : getCurrentOrganisationUnit()
         };
 
         return params;