dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36272
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18577: ER option set fix.
Merge authors:
Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 18577 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-03-11 11:52:56 +0100
message:
ER option set fix.
modified:
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/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-10 16:08:14 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-reports/scripts/app.js 2015-03-11 10:40:33 +0000
@@ -7946,6 +7946,8 @@
objectStores: ['optionSets']
});
+ dhis2.er.store.open();
+
// requests
Ext.Ajax.request({
url: 'manifest.webapp',
@@ -8136,58 +8138,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.er.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() {
+
+ // check if idb has any option sets
+ dhis2.er.store.count('optionSets').done( function(count) {
+ var store = dhis2.er.store;
+
+ 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();
+ }
+ }
+ });
+ }
+ });
}
});