← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12431: various updates to anonymous data-entry

 

------------------------------------------------------------
revno: 12431
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-10-04 16:18:28 +0200
message:
  various updates to anonymous data-entry
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.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/javascript/anonymousRegistration.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-10-04 13:06:47 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-10-04 14:18:28 +0000
@@ -33,36 +33,35 @@
         return;
     }
 
-    var deferred1 = $.Deferred();
-    var deferred2 = $.Deferred();
-    var promise = deferred2.promise();
-
-    _.each( _.values( metaData.programs ), function ( el, idx ) {
-        var psid = el.programStages[0].id;
-        var data = createProgramStage( psid );
-
-        promise = promise.then( function () {
-            return $.ajax( {
-                url: 'dataentryform.action',
-                data: data,
-                dataType: 'html',
-                cache: false
-            } ).done( function ( data ) {
-                    var obj = {};
-                    obj.id = psid;
-                    obj.form = data;
-                    DAO.store.set( 'programStages', obj );
-                } );
+    var def = $.Deferred();
+    var promise = def.promise();
+
+    _.each( _.values( metaData.programs ), function ( el ) {
+        var id = el.programStages[0].id;
+        promise = promise.then( makeProgramStageRequest( id ));
+    } );
+
+    def.resolve( metaData );
+
+    return promise;
+}
+
+function makeProgramStageRequest( id ) {
+    return function() {
+        var data = createProgramStage( id );
+
+        return $.ajax( {
+            url: 'dataentryform.action',
+            data: data,
+            dataType: 'html',
+            cache: false
+        } ).done( function ( data ) {
+            var obj = {};
+            obj.id = id;
+            obj.form = data;
+            DAO.store.set( 'programStages', obj );
         } );
-    } );
-
-    promise = promise.then( function () {
-        deferred1.resolve( metaData );
-    } );
-
-    deferred2.resolve();
-
-    return deferred1.promise();
+    }
 }
 
 function loadOptionSets( metaData ) {
@@ -854,6 +853,9 @@
         if ( confirm( i18n_comfirm_delete_event ) ) {
             DAO.store.delete( 'dataValues', programStageId ).always( function () {
                 updateOfflineEvents();
+
+                // needed, seemed that from time-to-time the events are updated too early, could be idb related
+                setTimeout(updateOfflineEvents, 400);
             } );
         }
     } else {