=== 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); + } + }); + } } };