dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31472
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16036: minor xhr chaining fixes in data-entry
------------------------------------------------------------
revno: 16036
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-07-09 12:04:06 +0700
message:
minor xhr chaining fixes in data-entry
modified:
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-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 2014-07-08 14:52:55 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2014-07-09 05:04:06 +0000
@@ -1938,15 +1938,11 @@
function updateForms()
{
- DAO.store.open().done( function() {
- purgeLocalForms().done(function() {
- updateExistingLocalForms().done(function() {
- downloadRemoteForms();
- });
- });
-
- dhis2.de.loadOptionSets();
- });
+ DAO.store.open()
+ .then(purgeLocalForms)
+ .then(updateExistingLocalForms)
+ .then(downloadRemoteForms)
+ .then(dhis2.de.loadOptionSets);
}
function purgeLocalForms()
@@ -1976,7 +1972,9 @@
function updateExistingLocalForms()
{
- return dhis2.de.storageManager.getAllForms().done(function( formIds ) {
+ var def = $.Deferred();
+
+ dhis2.de.storageManager.getAllForms().done(function( formIds ) {
var formVersions = dhis2.de.storageManager.getAllFormVersions();
$.safeEach( formIds, function( idx, item )
@@ -1986,14 +1984,21 @@
if ( remoteVersion == null || localVersion == null || remoteVersion != localVersion )
{
- dhis2.de.storageManager.downloadForm( item, remoteVersion );
+ dhis2.de.storageManager.downloadForm( item, remoteVersion )
}
} );
+
+ def.resolve();
});
+
+ return def.promise();
}
function downloadRemoteForms()
{
+ var def = $.Deferred();
+ var chain = [];
+
$.safeEach( dhis2.de.dataSets, function( idx, item )
{
var remoteVersion = item.version;
@@ -2002,11 +2007,17 @@
{
dhis2.de.storageManager.formExists( idx ).done(function( value ) {
if( !value ) {
- dhis2.de.storageManager.downloadForm( idx, remoteVersion );
+ chain.push(dhis2.de.storageManager.downloadForm( idx, remoteVersion ));
}
});
}
} );
+
+ $.when.apply($, chain).then(function() {
+ def.resolve();
+ });
+
+ return def.promise();
}
// -----------------------------------------------------------------------------