← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11024: (GIS) Detailed data elements included in favorites.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 11024 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-05-27 19:28:54 +0200
message:
  (GIS) Detailed data elements included in favorites.
modified:
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.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-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js	2013-05-27 13:08:55 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js	2013-05-27 17:27:24 +0000
@@ -501,7 +501,7 @@
 			isLoaded: false,
 			pageSize: 10,
 			page: 1,
-			defaultUrl: gis.baseUrl + gis.conf.url.path_api + 'maps.json?viewClass=detailed&links=false',
+			defaultUrl: gis.baseUrl + gis.conf.url.path_api + 'maps.json?links=false',
 			loadStore: function(url) {
 				this.proxy.url = url || this.defaultUrl;
 
@@ -1823,7 +1823,8 @@
 			createButton = Ext.create('Ext.button.Button', {
 				text: GIS.i18n.create,
 				handler: function() {
-					var name = nameTextfield.getValue(),
+					var dimConf = gis.conf.finals.dimension,
+						name = nameTextfield.getValue(),
 						layers = gis.util.map.getVisibleVectorLayers(),
 						layer,
 						lonlat = gis.olmap.getCenter(),
@@ -1837,6 +1838,12 @@
 								layer = layers[i];
 								view = layer.widget.getView();
 
+								// Operand
+								if (view.valueType === dimConf.dataElement.value && Ext.isObject(view.dataElement) && Ext.isString(view.dataElement.id) && view.dataElement.id.indexOf('-') !== -1) {
+									view.dataElementOperand = {id: view.dataElement.id.replace('-', '.')};
+									view.dataElement = null;
+								}
+
 								// add
 								view.layer = layer.id;
 
@@ -2017,16 +2024,6 @@
 							}
 						};
 
-							//var el = Ext.get(record.data.id);
-							//if (el) {
-								//el = el.parent('td');
-								//el.addClsOnOver('link');
-								//el.gis = gis;
-								//el.map = {id: record.data.id};
-								//el.dom.setAttribute('onclick', 'Ext.get(this).gis.map = Ext.get(this).map; GIS.core.MapLoader(Ext.get(this).gis).load();');
-							//}
-						//};
-
 						Ext.defer(fn, 100);
 
 						return '<div id="' + record.data.id + '">' + value + '</div>';
@@ -2324,7 +2321,7 @@
 			],
 			listeners: {
 				show: function() {
-					this.setPosition(115, 37);
+					this.setPosition(115, 33);
 				}
 			}
 		});
@@ -3006,7 +3003,7 @@
 			},
 			listeners: {
 				show: function() {
-					this.setPosition(185, 37);
+					this.setPosition(185, 33);
 				}
 			}
 		});
@@ -3506,6 +3503,9 @@
 			getView,
 			validateView,
 
+		// Convenience
+			dimConf = gis.conf.finals.dimension,
+
 			panel;
 
 		// Stores
@@ -3522,11 +3522,15 @@
 			},
 			isLoaded: false,
 			loadFn: function(fn) {
-				if (this.isLoaded) {
-					fn.call();
-				}
-				else {
-					this.load(fn);
+				if (Ext.isFunction(fn)) {
+					if (this.isLoaded) {
+						fn.call();
+					}
+					else {
+						this.load({
+							callback: fn
+						});
+					}
 				}
 			},
 			listeners: {
@@ -3561,7 +3565,7 @@
 			sortStore: function() {
 				this.sort('name', 'ASC');
 			},
-			setTotalsProxy: function(uid) {
+			setTotalsProxy: function(uid, preventLoad, callbackFn) {
 				var path;
 
 				if (Ext.isString(uid)) {
@@ -3585,14 +3589,20 @@
 					}
 				});
 
-				this.load({
-					scope: this,
-					callback: function() {
-						this.sortStore();
-					}
-				});
+				if (!preventLoad) {
+					this.load({
+						scope: this,
+						callback: function() {
+							this.sortStore();
+
+							if (Ext.isFunction(callbackFn)) {
+								callbackFn();
+							}
+						}
+					});
+				}
 			},
-			setDetailsProxy: function(uid) {
+			setDetailsProxy: function(uid, preventLoad, callbackFn) {
 				if (Ext.isString(uid)) {
 					this.setProxy({
 						type: 'ajax',
@@ -3603,17 +3613,23 @@
 						}
 					});
 
-					this.load({
-						scope: this,
-						callback: function() {
-							this.each(function(r) {
-								r.set('id', r.data.dataElementId + '-' + r.data.optionComboId);
-								r.set('name', r.data.operandName);
-							});
-
-							this.sortStore();
-						}
-					});
+					if (!preventLoad) {
+						this.load({
+							scope: this,
+							callback: function() {
+								this.each(function(r) {
+									r.set('id', r.data.dataElementId + '-' + r.data.optionComboId);
+									r.set('name', r.data.operandName);
+								});
+
+								this.sortStore();
+
+								if (Ext.isFunction(callbackFn)) {
+									callbackFn();
+								}
+							}
+						});
+					}
 				}
 				else {
 					alert('Invalid parameter');
@@ -3824,17 +3840,17 @@
 			labelWidth: gis.conf.layout.widget.itemlabel_width,
 			hidden: true,
 			store: gis.store.dataElementGroups,
-			loadAvailable: function() {
+			loadAvailable: function(preventLoad) {
 				var store = dataElementsByGroupStore,
 					detailLevel = dataElementDetailLevel.getValue(),
 					value = this.getValue();
 
-				if (value !== null) {
+				if (value) {
 					if (detailLevel === gis.conf.finals.dimension.dataElement.objectName) {
-						store.setTotalsProxy(value);
+						store.setTotalsProxy(value, preventLoad);
 					}
 					else {
-						store.setDetailsProxy(value);
+						store.setDetailsProxy(value, preventLoad);
 					}
 				}
 			},
@@ -3905,6 +3921,10 @@
 			displayField: 'text',
 			width: 65 - 2,
 			value: gis.conf.finals.dimension.dataElement.objectName,
+			onSelect: function() {
+				dataElementGroup.loadAvailable();
+				dataElement.clearValue();
+			},
 			store: {
 				fields: ['id', 'text'],
 				data: [
@@ -3914,8 +3934,7 @@
 			},
 			listeners: {
 				select: function(cb) {
-					dataElementGroup.loadAvailable();
-					dataElement.clearValue();
+					cb.onSelect();
 				}
 			}
 		});
@@ -4261,22 +4280,42 @@
 			// Indicator and data element
 			valueTypeToggler(view.valueType);
 
-			var	indeGroupView = view.valueType === gis.conf.finals.dimension.indicator.id ? indicatorGroup : dataElementGroup,
+			var	indeGroupView = view.valueType === dimConf.indicator.id ? indicatorGroup : dataElementGroup,
 				indeGroupStore = indeGroupView.store,
-				indeGroupValue = view.valueType === gis.conf.finals.dimension.indicator.id ? view.indicatorGroup.id : view.dataElementGroup.id,
-
-				indeStore = view.valueType === gis.conf.finals.dimension.indicator.id ? indicatorsByGroupStore : dataElementsByGroupStore,
-				indeView = view.valueType === gis.conf.finals.dimension.indicator.id ? indicator : dataElement,
-				indeValue = view.valueType === gis.conf.finals.dimension.indicator.id ? view.indicator.id : view.dataElement.id;
-
-			indeGroupStore.loadFn( function() {
-				indeGroupView.setValue(indeGroupValue);
-			});
-
-			indeStore.proxy.url = gis.baseUrl + gis.conf.url.path_api + view.valueType + 'Groups/' + indeGroupValue + '.json?links=false&paging=false';
-			indeStore.loadFn( function() {
-				indeView.setValue(indeValue);
-			});
+				indeGroupRecord = view.valueType === dimConf.indicator.id ? view.indicatorGroup : view.dataElementGroup,
+
+				indeStore = view.valueType === dimConf.indicator.id ? indicatorsByGroupStore : dataElementsByGroupStore,
+				indeView = view.valueType === dimConf.indicator.id ? indicator : dataElement,
+				indeRecord = view.valueType === dimConf.indicator.id ? view.indicator : view.dataElement;
+
+			// in/de group
+			indeGroupStore.removeAll();
+			indeGroupStore.add(indeGroupRecord);
+			indeGroupView.setValue(indeGroupRecord.id);
+
+			// in/de/dc
+			if (view.valueType === dimConf.dataElement.id) {
+				if (Ext.isObject(view.dataElement) && Ext.isString(view.dataElement.id) && view.dataElement.id.indexOf('-') !== -1) {
+					dataElementDetailLevel.setValue(dimConf.operand.objectName);
+					indeStore.setDetailsProxy(indeGroupRecord.id, false, function() {
+						indeView.setValue(indeRecord.id);
+					});
+				}
+				else {
+					dataElementDetailLevel.setValue(dimConf.dataElement.objectName);
+					indeStore.setTotalsProxy(indeGroupRecord.id, false, function() {
+						indeView.setValue(indeRecord.id);
+					});
+				}
+			}
+			else {
+				indeStore.proxy.url = gis.baseUrl + '/api/indicatorGroups/' + indeGroupRecord.id + '.json?links=false&paging=false';
+				indeStore.load({
+					callback: function() {
+						indeView.setValue(indeRecord.id);
+					}
+				});
+			}
 
 			// Period
 			periodType.setValue(view.periodType);
@@ -4844,7 +4883,6 @@
 				{
 					xtype: 'form',
 					cls: 'el-border-0',
-					width: 270,
 					items: [
 						{
 							html: GIS.i18n.organisationunit_groupset,

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js	2013-05-24 15:50:45 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js	2013-05-27 17:01:17 +0000
@@ -953,6 +953,22 @@
 		Ext.data.JsonP.request({
 			url: gis.baseUrl + gis.conf.url.path_api + 'maps/' + gis.map.id + '.jsonp?links=false',
 			success: function(r) {
+
+				// Operand
+				if (Ext.isArray(r.mapViews)) {
+					for (var i = 0, view; i < r.mapViews.length; i++) {
+						view = r.mapViews[i];
+
+						if (view) {
+							if (Ext.isObject(view.dataElementOperand) && Ext.isString(view.dataElementOperand.id)) {
+								view.dataElement = Ext.clone(view.dataElementOperand);
+								view.dataElement.id = view.dataElement.id.replace('.', '-');
+								delete view.dataElementOperand;
+							}
+						}
+					}
+				}
+
 				gis.map = r;
 				setMap();
 			},
@@ -1208,7 +1224,8 @@
 		loadData,
 		loadLegend,
 		afterLoad,
-		loader;
+		loader,
+		dimConf = gis.conf.finals.dimension;
 
 	compareView = function(view, doExecute) {
 		var src = layer.core.view;
@@ -1241,13 +1258,13 @@
 			return gis.conf.finals.widget.loadtype_organisationunit;
 		}
 		else {
-			if (view.valueType === gis.conf.finals.dimension.indicator.id && view.indicator.id !== src.indicator.id) {
+			if (view.valueType === dimConf.indicator.id && view.indicator.id !== src.indicator.id) {
 				if (doExecute) {
 					loadData(view);
 				}
 				return gis.conf.finals.widget.loadtype_data;
 			}
-			if (view.valueType === gis.conf.finals.dimension.dataElement.id && view.dataElement.id !== src.dataElement.id) {
+			if (view.valueType === dimConf.dataElement.id && view.dataElement.id !== src.dataElement.id) {
 				if (doExecute) {
 					loadData(view);
 				}
@@ -1341,10 +1358,10 @@
 		paramString += 'dimension=ou:LEVEL-' + view.organisationUnitLevel.level + '-' + view.parentOrganisationUnit.id;
 
 		// dx
-		if (Ext.isString(view[type].id) && view[type].id.indexOf('-') !== -1) {
+		if (view[type] && Ext.isString(view[type].id) && view[type].id.indexOf('-') !== -1) {
 			paramString += '&dimension=co&dimension=dx:' + view[type].id.substr(0, view[type].id.indexOf('-'));
 		}
-		else {
+		else if (view[type] && Ext.isString(view[type].id)) {
 			paramString += '&dimension=dx:' + view[type].id;
 		}