← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13560: GIS, event layer, program attributes.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 13560 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-01-03 12:43:47 +0100
message:
  GIS, event layer, program attributes.
modified:
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/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-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	2014-01-03 10:19:10 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js	2014-01-03 11:40:12 +0000
@@ -4037,10 +4037,9 @@
 			emptyText: 'Select program',
 			forceSelection: true,
 			queryMode: 'remote',
-			//width: gis.conf.layout.widget.item_width,
 			columnWidth: 0.5,
 			style: 'margin:1px 1px 2px 0',
-			//labelWidth: gis.conf.layout.widget.itemlabel_width,
+			storage: {},
 			store: programStore,
             getRecord: function() {
                 return {
@@ -4114,19 +4113,58 @@
 			loadDataElements(stageId);
 		};
 
-		loadDataElements = function(param) {
-			if (Ext.isString(param)) {
-				Ext.Ajax.request({
-					url: gis.init.contextPath + '/api/programStages/' + param + '.json?links=false&paging=false',
-					success: function(r) {
-						var dataElements = Ext.Array.pluck(Ext.decode(r.responseText).programStageDataElements, 'dataElement');
-
-						dataElementsByStageStore.loadData(dataElements);
-					}
-				});
-			}
-			else if (Ext.isArray(param)) {
-				dataElementsByStageStore.loadData(param);
+		loadDataElements = function(item, programId) {
+			var dataElements,
+				load,
+				fn;
+
+			programId = programId || program.getValue() || null;
+
+			load = function(attributes, dataElements) {
+				var data = Ext.Array.clean([].concat(attributes || [], dataElements || []));
+				dataElementsByStageStore.loadData(data);
+			};
+
+			fn = function(attributes) {
+
+				// data elements			
+				if (Ext.isString(item)) {
+					Ext.Ajax.request({
+						url: gis.init.contextPath + '/api/programStages/' + item + '.json?links=false&paging=false',
+						success: function(r) {
+							var dataElements = Ext.Array.pluck(Ext.decode(r.responseText).programStageDataElements, 'dataElement');
+							load(attributes, dataElements);
+						}
+					});
+				}
+				else if (Ext.isArray(item)) {
+					load(attributes, item);
+				}
+			};
+
+			// attributes
+			if (programId) {
+				if (program.storage[programId]) {
+					fn(program.storage[programId]);
+				}
+				else {
+					Ext.Ajax.request({
+						url: gis.init.contextPath + '/api/programs/' + programId + '.json?viewClass=withoutOrganisationUnits&links=false',
+						success: function(r) {
+							var attributes = Ext.decode(r.responseText).attributes;
+
+							if (attributes) {
+								for (var i = 0; i < attributes.length; i++) {
+									attributes[i].type = attributes[i].valueType;
+								}
+								
+								program.storage[programId] = attributes;
+							}
+
+							fn(attributes);
+						}
+					});
+				}
 			}
 		};