← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18580: GIS option set fix.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 18580 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-03-11 12:04:38 +0100
message:
  GIS option set fix.
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/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-mapping/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/app.js	2015-03-10 11:32:27 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/app.js	2015-03-11 11:03:46 +0000
@@ -9382,6 +9382,17 @@
 			}
 		};
 
+        // dhis2
+        dhis2.util.namespace('dhis2.gis');
+
+        dhis2.gis.store = dhis2.gis.store || new dhis2.storage.Store({
+            name: 'dhis2',
+            adapters: [dhis2.storage.IndexedDBAdapter, dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter],
+            objectStores: ['optionSets']
+        });
+
+        dhis2.gis.store.open();
+
 		// requests
 		Ext.Ajax.request({
 			url: 'manifest.webapp',
@@ -9429,15 +9440,6 @@
 
                                         init.namePropertyUrl = namePropertyUrl;
 
-                                        // dhis2
-                                        dhis2.util.namespace('dhis2.gis');
-
-                                        dhis2.gis.store = dhis2.gis.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',
@@ -9647,58 +9649,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.gis.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.gis.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();
+                                                                }
+                                                            }
+                                                        });
+                                                    }
+                                                });
                                             }
                                         });