← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12602: (DV) Plugin fixes.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 12602 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-10-13 15:09:38 +0200
message:
  (DV) Plugin fixes.
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/chart.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/table.js
  dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/plugin.js
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/plugin.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-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/chart.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/chart.js	2013-10-10 11:15:21 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/chart.js	2013-10-13 13:09:02 +0000
@@ -2440,7 +2440,6 @@
 
     // PLUGIN
 
-    
 	// chart tips css
 	var css = '.dv-chart-tips { border-radius: 2px; padding: 0px 3px 1px; border: 2px solid #777; background-color: #f1f1f1; } \n';
 	css += '.dv-chart-tips .x-tip-body { background-color: #f1f1f1; font-size: 13px; font-weight: normal; color: #444; -webkit-text-stroke: 0; } \n';
@@ -2453,11 +2452,79 @@
 
 	Ext.util.CSS.createStyleSheet(css);
 
+	// i18n
+	DV.i18n = {
+		target: 'Target',
+		base: 'Base',
+		trend: 'Trend'
+	};
+
     // plugin
     DV.plugin = {};
 
-	DV.plugin.getChart = function(config) {
+	var init = {},
+		configs = [],
+		isInitialized = false,
+		getInit,
+		execute;
+
+	getInit = function(config) {
+		var requests = [],
+			callbacks = 0,
+			fn;
+
+		init.user = {};
+
+		fn = function() {
+			if (++callbacks === requests.length) {
+				for (var i = 0; i < configs.length; i++) {
+					execute(configs[i]);
+				}
+			}
+		};
+
+		requests.push({
+			url: config.url + '/api/system/info',
+			success: function(r) {
+				init.contextPath = r.contextPath;
+				fn();
+			}
+		});
+
+		requests.push({
+			url: config.url + '/api/organisationUnits.jsonp?userOnly=true&viewClass=detailed&links=false',
+			success: function(r) {
+				var ou = r.organisationUnits[0];
+				init.user.ou = ou.id;
+				init.user.ouc = Ext.Array.pluck(ou.children, 'id');
+				fn();
+			}
+		});
+
+		requests.push({
+			url: config.url + '/api/mapLegendSets.jsonp?viewClass=detailed&links=false&paging=false',
+			success: function(r) {
+				init.legendSets = r.mapLegendSets;
+				fn();
+			}
+		});
+
+		requests.push({
+			url: config.url + '/api/dimensions.jsonp?links=false&paging=false',
+			success: function(r) {
+				init.dimensions = r.dimensions;
+				fn();
+			}
+		});
+
+		for (var i = 0; i < requests.length; i++) {
+			Ext.data.JsonP.request(requests[i]);
+		}
+	};
+
+	execute = function(config) {
 		var validateConfig,
+            extendInstance,
 			createViewport,
 			initialize,
 			dv;
@@ -2476,6 +2543,13 @@
 			return true;
 		};
 
+        extendInstance = function(dv) {
+            var util = dv.util || {},
+                init = dv.init || {};
+
+            init.el = config.el;
+		};
+
 		createViewport = function() {
 			var el = Ext.get(dv.init.el),
 				setFavorite,
@@ -2506,38 +2580,37 @@
 		};
 
 		initialize = function() {
-
 			if (!validateConfig(config)) {
 				return;
 			}
 
-			Ext.data.JsonP.request({
-				url: config.url + '/dhis-web-visualizer/initialize.action',
-				success: function(r) {
-					var init = r;
-
-					DV.i18n = init.i18n;
-
-					dv = DV.core.getInstance(init);
-
-					dv.init.el = config.el;
-					dv.isPlugin = true;
-					dv.viewport = createViewport();
-
-					if (config.uid) {
-						dv.engine.loadChart(config.uid, dv);
-					}
-					else {
-						layout = dv.api.layout.Layout(config);
-
-						if (!layout) {
-							return;
-						}
-
-						dv.engine.createChart(layout, dv);
-					}
+			dv = DV.core.getInstance(Ext.clone(init));
+			extendInstance(dv);
+
+			dv.isPlugin = true;
+			dv.viewport = createViewport();
+
+			if (config.uid) {
+				dv.engine.loadChart(config.uid, dv);
+			}
+			else {
+				layout = dv.api.layout.Layout(config);
+
+				if (!layout) {
+					return;
 				}
-			});
+
+				dv.engine.createChart(layout, dv);
+			}
 		}();
 	};
+
+	DV.plugin.getChart = function(config) {
+		configs.push(config);
+
+		if (!isInitialized) {
+			isInitialized = true;
+			getInit(config);
+		}
+	};
 });

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/table.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/table.js	2013-10-13 12:41:41 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/plugin/table.js	2013-10-13 13:09:02 +0000
@@ -2740,7 +2740,7 @@
 
 	// PLUGIN
 
-	// css
+		// css
 	css = 'table.pivot { \n font-family: arial,sans-serif,ubuntu,consolas; \n } \n';
 	css += '.td-nobreak { \n white-space: nowrap; \n } \n';
 	css += '.td-hidden { \n display: none; \n } \n';
@@ -2805,7 +2805,7 @@
 		});
 
 		requests.push({
-			url: config.url + '/api/organisationUnits.json?userOnly=true&viewClass=detailed&links=false',
+			url: config.url + '/api/organisationUnits.jsonp?userOnly=true&viewClass=detailed&links=false',
 			success: function(r) {
 				var ou = r.organisationUnits[0];
 				init.user.ou = ou.id;
@@ -2815,7 +2815,7 @@
 		});
 
 		requests.push({
-			url: config.url + '/api/mapLegendSets.json?viewClass=detailed&links=false&paging=false',
+			url: config.url + '/api/mapLegendSets.jsonp?viewClass=detailed&links=false&paging=false',
 			success: function(r) {
 				init.legendSets = r.mapLegendSets;
 				fn();
@@ -2823,7 +2823,7 @@
 		});
 
 		requests.push({
-			url: config.url + '/api/dimensions.json?links=false&paging=false',
+			url: config.url + '/api/dimensions.jsonp?links=false&paging=false',
 			success: function(r) {
 				init.dimensions = r.dimensions;
 				fn();
@@ -2928,8 +2928,4 @@
 			getInit(config);
 		}
 	};
-
-	DHIS = Ext.isObject(DHIS) ? DHIS : {};
-
-	DHIS.getTable = PT.plugin.getTable;
 });

=== modified file 'dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/plugin.js'
--- dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/plugin.js	2013-10-13 12:41:41 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/plugin.js	2013-10-13 13:09:02 +0000
@@ -65,7 +65,7 @@
 		});
 
 		requests.push({
-			url: config.url + '/api/organisationUnits.json?userOnly=true&viewClass=detailed&links=false',
+			url: config.url + '/api/organisationUnits.jsonp?userOnly=true&viewClass=detailed&links=false',
 			success: function(r) {
 				var ou = r.organisationUnits[0];
 				init.user.ou = ou.id;
@@ -75,7 +75,7 @@
 		});
 
 		requests.push({
-			url: config.url + '/api/mapLegendSets.json?viewClass=detailed&links=false&paging=false',
+			url: config.url + '/api/mapLegendSets.jsonp?viewClass=detailed&links=false&paging=false',
 			success: function(r) {
 				init.legendSets = r.mapLegendSets;
 				fn();
@@ -83,7 +83,7 @@
 		});
 
 		requests.push({
-			url: config.url + '/api/dimensions.json?links=false&paging=false',
+			url: config.url + '/api/dimensions.jsonp?links=false&paging=false',
 			success: function(r) {
 				init.dimensions = r.dimensions;
 				fn();
@@ -188,8 +188,4 @@
 			getInit(config);
 		}
 	};
-
-	DHIS = Ext.isObject(DHIS) ? DHIS : {};
-
-	DHIS.getTable = PT.plugin.getTable;
 });

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/plugin.js'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/plugin.js	2013-10-08 17:07:19 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/plugin.js	2013-10-13 13:09:02 +0000
@@ -12,11 +12,79 @@
 
 	Ext.util.CSS.createStyleSheet(css);
 
+	// i18n
+	DV.i18n = {
+		target: 'Target',
+		base: 'Base',
+		trend: 'Trend'
+	};
+
     // plugin
     DV.plugin = {};
 
-	DV.plugin.getChart = function(config) {
+	var init = {},
+		configs = [],
+		isInitialized = false,
+		getInit,
+		execute;
+
+	getInit = function(config) {
+		var requests = [],
+			callbacks = 0,
+			fn;
+
+		init.user = {};
+
+		fn = function() {
+			if (++callbacks === requests.length) {
+				for (var i = 0; i < configs.length; i++) {
+					execute(configs[i]);
+				}
+			}
+		};
+
+		requests.push({
+			url: config.url + '/api/system/info',
+			success: function(r) {
+				init.contextPath = r.contextPath;
+				fn();
+			}
+		});
+
+		requests.push({
+			url: config.url + '/api/organisationUnits.jsonp?userOnly=true&viewClass=detailed&links=false',
+			success: function(r) {
+				var ou = r.organisationUnits[0];
+				init.user.ou = ou.id;
+				init.user.ouc = Ext.Array.pluck(ou.children, 'id');
+				fn();
+			}
+		});
+
+		requests.push({
+			url: config.url + '/api/mapLegendSets.jsonp?viewClass=detailed&links=false&paging=false',
+			success: function(r) {
+				init.legendSets = r.mapLegendSets;
+				fn();
+			}
+		});
+
+		requests.push({
+			url: config.url + '/api/dimensions.jsonp?links=false&paging=false',
+			success: function(r) {
+				init.dimensions = r.dimensions;
+				fn();
+			}
+		});
+
+		for (var i = 0; i < requests.length; i++) {
+			Ext.data.JsonP.request(requests[i]);
+		}
+	};
+
+	execute = function(config) {
 		var validateConfig,
+            extendInstance,
 			createViewport,
 			initialize,
 			dv;
@@ -35,6 +103,13 @@
 			return true;
 		};
 
+        extendInstance = function(dv) {
+            var util = dv.util || {},
+                init = dv.init || {};
+
+            init.el = config.el;
+		};
+
 		createViewport = function() {
 			var el = Ext.get(dv.init.el),
 				setFavorite,
@@ -65,38 +140,37 @@
 		};
 
 		initialize = function() {
-
 			if (!validateConfig(config)) {
 				return;
 			}
 
-			Ext.data.JsonP.request({
-				url: config.url + '/dhis-web-visualizer/initialize.action',
-				success: function(r) {
-					var init = r;
-
-					DV.i18n = init.i18n;
-
-					dv = DV.core.getInstance(init);
-
-					dv.init.el = config.el;
-					dv.isPlugin = true;
-					dv.viewport = createViewport();
-
-					if (config.uid) {
-						dv.engine.loadChart(config.uid, dv);
-					}
-					else {
-						layout = dv.api.layout.Layout(config);
-
-						if (!layout) {
-							return;
-						}
-
-						dv.engine.createChart(layout, dv);
-					}
+			dv = DV.core.getInstance(Ext.clone(init));
+			extendInstance(dv);
+
+			dv.isPlugin = true;
+			dv.viewport = createViewport();
+
+			if (config.uid) {
+				dv.engine.loadChart(config.uid, dv);
+			}
+			else {
+				layout = dv.api.layout.Layout(config);
+
+				if (!layout) {
+					return;
 				}
-			});
+
+				dv.engine.createChart(layout, dv);
+			}
 		}();
 	};
+
+	DV.plugin.getChart = function(config) {
+		configs.push(config);
+
+		if (!isInitialized) {
+			isInitialized = true;
+			getInit(config);
+		}
+	};
 });