Merge authors: Jan Henrik Ă˜verland (janhenrik-overland) ------------------------------------------------------------ revno: 18578 [merge] committer: Jan Henrik Overland <janhenrik.overl...@gmail.com> branch nick: dhis2 timestamp: Wed 2015-03-11 12:00:18 +0100 message: EV option set fix. modified: dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.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-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js 2015-03-11 10:40:33 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js 2015-03-11 10:59:10 +0000 @@ -7936,7 +7936,6 @@ } }; - // dhis2 dhis2.util.namespace('dhis2.er'); @@ -8141,10 +8140,10 @@ url: '.', disableCaching: false, success: function() { + var store = dhis2.er.store; // check if idb has any option sets - dhis2.er.store.count('optionSets').done( function(count) { - var store = dhis2.er.store; + store.count('optionSets').done( function(count) { if (count === 0) { Ext.Ajax.request({ === modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.js' --- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.js 2015-03-10 11:32:27 +0000 +++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.js 2015-03-11 10:59:10 +0000 @@ -7279,6 +7279,17 @@ } }; + // dhis2 + dhis2.util.namespace('dhis2.ev'); + + dhis2.ev.store = dhis2.ev.store || new dhis2.storage.Store({ + name: 'dhis2', + adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter], + objectStores: ['optionSets'] + }); + + dhis2.ev.store.open(); + // requests Ext.Ajax.request({ url: 'manifest.webapp', @@ -7326,15 +7337,6 @@ init.namePropertyUrl = namePropertyUrl; - // dhis2 - dhis2.util.namespace('dhis2.ev'); - - dhis2.ev.store = dhis2.ev.store || new dhis2.storage.Store({ - name: 'dhis2', - adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter], - objectStores: ['optionSets'] - }); - // calendar (function() { var dhis2PeriodUrl = '../dhis-web-commons/javascripts/dhis2/dhis2.period.js', @@ -7469,58 +7471,86 @@ // option sets requests.push({ - url: contextPath + '/api/optionSets.json?fields=id,version&paging=false', - success: function(r) { - var optionSets = Ext.decode(r.responseText).optionSets || [], - store = dhis2.ev.store, - ids = [], - url = '', - callbacks = 0, - checkOptionSet, - updateStore; - - updateStore = function() { - if (++callbacks === optionSets.length) { - if (!ids.length) { - fn(); - return; - } - - for (var i = 0; i < ids.length; i++) { - url += '&filter=id:eq:' + ids[i]; - } - + url: '.', + disableCaching: false, + success: function() { + var store = dhis2.ev.store; + + // check if idb has any option sets + store.count('optionSets').done( function(count) { + + if (count === 0) { Ext.Ajax.request({ - url: contextPath + '/api/optionSets.json?fields=id,name,version,options[code,name]&paging=false' + url, + url: contextPath + '/api/optionSets.json?fields=id,name,version,options[code,name]&paging=false', success: function(r) { var sets = Ext.decode(r.responseText).optionSets; - store.setAll('optionSets', sets).done(fn); - } - }); - } - }; - - registerOptionSet = function(optionSet) { - store.get('optionSets', optionSet.id).done( function(obj) { - if (!Ext.isObject(obj) || obj.version !== optionSet.version) { - ids.push(optionSet.id); - } - - updateStore(); - }); - }; - - if (optionSets.length) { - store.open().done( function() { - for (var i = 0; i < optionSets.length; i++) { - registerOptionSet(optionSets[i]); - } - }); - } - else { - fn(); - } + if (sets.length) { + store.setAll('optionSets', sets).done(fn); + } + else { + fn(); + } + } + }); + } + else { + Ext.Ajax.request({ + url: contextPath + '/api/optionSets.json?fields=id,version&paging=false', + success: function(r) { + var optionSets = Ext.decode(r.responseText).optionSets || [], + ids = [], + url = '', + callbacks = 0, + checkOptionSet, + updateStore; + + updateStore = function() { + if (++callbacks === optionSets.length) { + if (!ids.length) { + fn(); + return; + } + + for (var i = 0; i < ids.length; i++) { + url += '&filter=id:eq:' + ids[i]; + } + + Ext.Ajax.request({ + url: contextPath + '/api/optionSets.json?fields=id,name,version,options[code,name]&paging=false' + url, + success: function(r) { + var sets = Ext.decode(r.responseText).optionSets; + + store.setAll('optionSets', sets).done(fn); + } + }); + } + }; + + registerOptionSet = function(optionSet) { + store.get('optionSets', optionSet.id).done( function(obj) { + if (!Ext.isObject(obj) || obj.version !== optionSet.version) { + ids.push(optionSet.id); + } + + updateStore(); + }); + }; + + if (optionSets.length) { + store.open().done( function() { + for (var i = 0; i < optionSets.length; i++) { + registerOptionSet(optionSets[i]); + } + }); + } + else { + fn(); + } + } + }); + } + }); } });
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp