=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/base.vm' --- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/base.vm 2012-10-19 10:23:18 +0000 +++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/base.vm 2012-10-19 22:31:07 +0000 @@ -1,6 +1,6 @@ - + DHIS2 === modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.vm' --- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.vm 2012-10-19 12:24:40 +0000 +++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.vm 2012-10-19 22:31:07 +0000 @@ -1,43 +1,42 @@
=== 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 2012-10-19 18:54:09 +0000 +++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/dhis-web-mobile-resources/js/dhis2.storage.js 2012-10-19 22:31:07 +0000 @@ -34,28 +34,15 @@ this._id = _.uniqueId('formManager'); }; -dhis2.storage.FormManager.prototype.initialize = function ( args ) { - $.ajax({ +dhis2.storage.FormManager.prototype.getMetaData = function () { + console.log('get metadata'); + + return $.ajax({ url : '../api/currentUser/forms', dataType : 'json' - }).success(function ( data ) { + }).done(function ( data ) { localStorage['organisationUnits'] = JSON.stringify(data.organisationUnits); localStorage['forms'] = JSON.stringify(data.forms); - - if(args.success) { - args.success.call(null, data); - } - }).error(function () { - // offline ? reuse meta-data already present - console.log("unable to load meta-data"); - - if(args.error) { - args.error.call(); - } - }).complete(function() { - if(args.complete) { - args.complete.call(); - } }); }; @@ -119,34 +106,31 @@ }); }; -dhis2.storage.FormManager.prototype.uploadDataValueSets = function( args ) { +dhis2.storage.makeUploadDataValueSetRequest = function( dataValueSet ) { + return $.ajax({ + url: '../api/dataValueSets', + type: 'POST', + contentType: 'application/json', + data: JSON.stringify( dataValueSet ) + }); +}; + +dhis2.storage.FormManager.prototype.uploadDataValueSets = function() { var dataValueSets = this.dataValueSets(); + var deferreds = []; _.each(dataValueSets, function( dataValueSet, idx ) { - $.ajax({ - url: '../api/dataValueSets', - type: 'POST', - contentType: 'application/json', - data: JSON.stringify(dataValueSet), - async: false - }).success(function() { - delete dataValueSets[idx]; - - if( args.success ) { - args.success.call(); - } - }).error(function() { - }); - }); - - // filter out undefined dataValues (successfully uploaded); - dataValueSets = _.filter(dataValueSets, function(dv) { return dv !== undefined; }); - - localStorage['dataValueSets'] = JSON.stringify( dataValueSets ); - - if( args.done) { - args.done.call(); - } + deferreds.push(dhis2.storage.makeUploadDataValueSetRequest( dataValueSet).success(function() { + delete dataValueSets[idx]; + }) + ); + }); + + return $.when.apply( null, deferreds ).always(function() { + // filter out undefined dataValues (successfully uploaded); + dataValueSets = _.filter(dataValueSets, function(dv) { return dv !== undefined; }); + localStorage['dataValueSets'] = JSON.stringify( dataValueSets ); + }); }; // global storage manager instance