← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21010: GIS plugin fixes.

 

------------------------------------------------------------
revno: 21010
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-11-10 15:39:22 +0100
message:
  GIS plugin fixes.
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/plugin.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/map.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/plugin.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/plugin.html	2015-10-24 21:03:02 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/plugin.html	2015-11-10 14:39:22 +0000
@@ -7,9 +7,9 @@
     <link rel="stylesheet" type="text/css" href="//localhost:8080/dhis-web-commons/javascripts/ext/resources/css/ext-all-gray.css"/>
 -->
 
-    <script src="//localhost:8080/dhis-web-commons/javascripts/ext/ext-all.js"></script>
+    <script src="//localhost:8888/dhis-web-commons/javascripts/ext/ext-all.js"></script>
     <script src="//maps.google.com/maps/api/js?sensor=false"></script>
-    <script src="//localhost:8080/dhis-web-commons/javascripts/openlayers/OpenLayers.js"></script>
+    <script src="//localhost:8888/dhis-web-commons/javascripts/openlayers/OpenLayers.js"></script>
     <script src="scripts/map.js"></script>
 
     <style>
@@ -27,25 +27,24 @@
 
     <script>
 		Ext.onReady(function() {
-			var url = "http://localhost:8080";;
+			var url = "http://localhost:8888";;
 
-			//GIS.plugin.getMap({
-				//url: url,
-				//el: "map1",
-				//id: "jzxTpTUdISq",
-                //crossDomain: true,
-                //username: "system",
-                //password: "System123",
-                //dashboard: true,
-                //mapViews: [{
-                    //userOrgUnit: ['fdc6uOvgoji']
-                //}]
-			//});
+			GIS.plugin.getMap({
+				url: url,
+				el: "map1",
+				id: "zDP78aJU8nX",
+                crossDomain: true,
+                username: 'admin',
+                password: 'district',
+                dashboard: true
+			});
 
 			GIS.plugin.getMap({
 				url: url,
 				el: "map2",
-                crossDomain: false,
+                crossDomain: true,
+                username: 'admin',
+                password: 'district',
                 dashboard: true,
 				hideLegend: true,
                 baseLayer: 'none',

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/map.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/map.js	2015-10-24 21:03:02 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/map.js	2015-11-10 14:39:22 +0000
@@ -2786,28 +2786,16 @@
                 getOptionSets();
             };
 
-			if (Ext.isObject(GIS.app)) {
-				Ext.Ajax.request({
-					url: gis.init.contextPath + '/api/analytics/events/query/' + view.program.id + '.json' + paramString,
-					disableCaching: false,
-					failure: function(r) {
-                        gis.alert(r);
-					},
-					success: function(r) {
-						success(Ext.decode(r.responseText));
-					}
-				});
-			}
-			else if (Ext.isObject(GIS.plugin)) {
-				Ext.data.JsonP.request({
-					url: gis.init.contextPath + '/api/analytics/events/query/' + view.program.id + '.jsonp' + paramString,
-					disableCaching: false,
-					scope: this,
-					success: function(r) {
-						success(r);
-					}
-				});
-			}
+            gis.ajax({
+                url: gis.init.contextPath + '/api/analytics/events/query/' + view.program.id + '.json' + paramString,
+                disableCaching: false,
+                failure: function(r) {
+                    gis.alert(r);
+                },
+                success: function(r) {
+                    success(Ext.decode(r.responseText));
+                }
+            });
 		};
 
 		loadLegend = function(view) {
@@ -2972,7 +2960,6 @@
 
 		loadOrganisationUnits = function(view) {
             var items = view.rows[0].items,
-                isPlugin = GIS.plugin && !GIS.app,
                 url = function() {
                     var params = '?ou=ou:';
 
@@ -2991,7 +2978,7 @@
                         }
                     }
 
-                    return gis.init.contextPath + '/api/geoFeatures.' + (isPlugin ? 'jsonp' : 'json') + params + '&includeGroupSets=true';
+                    return gis.init.contextPath + '/api/geoFeatures.json' + params + '&includeGroupSets=true';
                 }(),
                 success,
                 failure;
@@ -3023,24 +3010,13 @@
                 gis.alert(GIS.i18n.coordinates_could_not_be_loaded);
             };
 
-            if (GIS.plugin && !GIS.app) {
-                Ext.data.JsonP.request({
-                    url: url,
-                    disableCaching: false,
-                    success: function(r) {
-                        success(r);
-                    }
-                });
-            }
-            else {
-                Ext.Ajax.request({
-                    url: url,
-                    disableCaching: false,
-                    success: function(r) {
-                        success(Ext.decode(r.responseText));
-                    }
-                });
-            }
+            gis.ajax({
+                url: url,
+                disableCaching: false,
+                success: function(r) {
+                    success(r);
+                }
+            });
         };
 
 		loadData = function(view, features) {
@@ -3059,7 +3035,7 @@
 
 		loadLegend = function(view) {
             var isPlugin = GIS.plugin && !GIS.app,
-                type = isPlugin ? 'jsonp' : 'json',
+                type = 'json',
                 url = gis.init.contextPath + '/api/organisationUnitGroupSets/' + view.organisationUnitGroupSet.id + '.' + type + '?fields=organisationUnitGroups[id,name,symbol]',
                 success;
 
@@ -3092,22 +3068,12 @@
                 afterLoad(view);
             };
 
-            if (isPlugin) {
-                Ext.data.JsonP.request({
-                    url: url,
-                    success: function(r) {
-                        success(r);
-                    }
-                });
-            }
-            else {
-                Ext.Ajax.request({
-                    url: url,
-                    success: function(r) {
-                        success(Ext.decode(r.responseText));
-                    }
-                });
-            }
+            gis.ajax({
+                url: url,
+                success: function(r) {
+                    success(r);
+                }
+            });
 		};
 
 		addCircles = function(view) {
@@ -3257,7 +3223,6 @@
 
 		loadOrganisationUnits = function(view) {
 			var items = view.rows[0].items,
-                isPlugin = GIS.plugin && !GIS.app,
                 url = function() {
                     var params = '?ou=ou:';
 
@@ -3276,13 +3241,13 @@
                         }
                     }
 
-                    return gis.init.contextPath + '/api/geoFeatures.' + (isPlugin ? 'jsonp' : 'json') + params;
+                    return gis.init.contextPath + '/api/geoFeatures.json' + params;
                 }(),
                 success,
                 failure;
 
             success = function(r) {
-                var geojson = gis.util.geojson.decode(r, 'DESC'),
+                var geojson = gis.util.geojson.decode(Ext.decode(r.responseText), 'DESC'),
                     format = new OpenLayers.Format.GeoJSON(),
                     features = gis.util.map.getTransformedFeatureArray(format.read(geojson)),
                     colors = ['black', 'blue', 'red', 'green', 'yellow'],
@@ -3340,27 +3305,13 @@
                 gis.alert(GIS.i18n.coordinates_could_not_be_loaded);
             };
 
-            if (isPlugin) {
-                Ext.data.JsonP.request({
-                    url: url,
-                    disableCaching: false,
-                    success: function(r) {
-                        success(r);
-                    }
-                });
-            }
-            else {
-                Ext.Ajax.request({
-                    url: url,
-                    disableCaching: false,
-                    success: function(r) {
-                        success(Ext.decode(r.responseText));
-                    },
-                    failure: function() {
-                        failure();
-                    }
-                });
-            }
+            gis.ajax({
+                url: url,
+                disableCaching: false,
+                success: function(r) {
+                    success(r);
+                }
+            });
 		};
 
 		loadData = function(view, features) {
@@ -3620,7 +3571,6 @@
 
 		loadOrganisationUnits = function(view) {
 			var items = view.rows[0].items,
-                isPlugin = GIS.plugin && !GIS.app,
                 url = function() {
                     var params = '?ou=ou:';
 
@@ -3639,13 +3589,13 @@
                         }
                     }
 
-                    return gis.init.contextPath + '/api/geoFeatures.' + (isPlugin ? 'jsonp' : 'json') + params;
+                    return gis.init.contextPath + '/api/geoFeatures.json' + params;
                 }(),
                 success,
                 failure;
 
             success = function(r) {
-                var geojson = gis.util.geojson.decode(r),
+                var geojson = gis.util.geojson.decode(Ext.decode(r.responseText)),
                     format = new OpenLayers.Format.GeoJSON(),
                     features = gis.util.map.getTransformedFeatureArray(format.read(geojson));
 
@@ -3671,27 +3621,16 @@
                 gis.alert(GIS.i18n.coordinates_could_not_be_loaded);
             };
 
-            if (isPlugin) {
-                Ext.data.JsonP.request({
-                    url: url,
-                    disableCaching: false,
-                    success: function(r) {
-                        success(r);
-                    }
-                });
-            }
-            else {
-                Ext.Ajax.request({
-                    url: url,
-                    disableCaching: false,
-                    success: function(r) {
-                        success(Ext.decode(r.responseText));
-                    },
-                    failure: function() {
-                        failure();
-                    }
-                });
-            }
+            gis.ajax({
+                url: url,
+                disableCaching: false,
+                success: function(r) {
+                    success(r);
+                },
+                failure: function() {
+                    failure();
+                }
+            });
 		};
 
 		loadData = function(view, features) {
@@ -3814,28 +3753,16 @@
 				loadLegend(view);
 			};
 
-			if (Ext.isObject(GIS.app)) {
-				Ext.Ajax.request({
-					url: gis.init.contextPath + '/api/analytics.json' + paramString,
-					disableCaching: false,
-					failure: function(r) {
-                        gis.alert(r);
-					},
-					success: function(r) {
-						success(Ext.decode(r.responseText));
-					}
-				});
-			}
-			else if (Ext.isObject(GIS.plugin)) {
-				Ext.data.JsonP.request({
-					url: gis.init.contextPath + '/api/analytics.jsonp' + paramString,
-					disableCaching: false,
-					scope: this,
-					success: function(r) {
-						success(r);
-					}
-				});
-			}
+            gis.ajax({
+                url: gis.init.contextPath + '/api/analytics.json' + paramString,
+                disableCaching: false,
+                failure: function(r) {
+                    gis.alert(r);
+                },
+                success: function(r) {
+                    success(Ext.decode(r.responseText));
+                }
+            });
 		};
 
 		loadLegend = function(view) {
@@ -3906,7 +3833,7 @@
             };
 
             loadLegendSet = function(view) {
-                Ext.Ajax.request({
+                gis.ajax({
 					url: gis.init.contextPath + '/api/legendSets/' + view.legendSet.id + '.json?fields=' + gis.conf.url.legendSetFields.join(','),
 					scope: this,
                     disableCaching: false,
@@ -3958,7 +3885,7 @@
                     return;
                 }
 
-                Ext.Ajax.request({
+                gis.ajax({
                     url: gis.init.contextPath + '/api/' + elementUrl + '.json?fields=legendSet[id,name]&paging=false&filter=id:eq:' + id,
                     success: function(r) {
                         var elements = Ext.decode(r.responseText)[elementUrl],
@@ -4440,7 +4367,7 @@
 
 			util.geojson = {};
 
-			util.geojson.decode = function(organisationUnits, levelOrder) {
+			util.geojson.decode = function(geoFeatures, levelOrder) {
 				var geojson = {
                     type: 'FeatureCollection',
                     crs: {
@@ -4451,14 +4378,14 @@
                     },
                     features: []
 				};
-
+                
                 levelOrder = levelOrder || 'ASC';
 
                 // sort
-                util.array.sort(organisationUnits, levelOrder, 'le');
+                util.array.sort(geoFeatures, levelOrder, 'le');
 
-				for (var i = 0, ou, gpid = '', gppg = ''; i < organisationUnits.length; i++) {
-                    ou = organisationUnits[i];
+				for (var i = 0, ou, gpid = '', gppg = ''; i < geoFeatures.length; i++) {
+                    ou = geoFeatures[i];
 
                     // grand parent
                     if (Ext.isString(ou.pg) && ou.pg.length) {
@@ -7197,8 +7124,7 @@
 				util = gis.util,
                 type = 'json',
                 headerMap = {
-                    json: 'application/json',
-                    jsonp: 'application/javascript'
+                    json: 'application/json'
                 },
                 headers = {
                     'Content-Type': headerMap[type],