← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2018: add commons function, get dataelement/indicator/group...

 

------------------------------------------------------------
revno: 2018
committer: Tran Thanh Tri <Tran Thanh Tri@compaq>
branch nick: trunk
timestamp: Tue 2010-08-31 15:31:58 +0700
message:
  add commons function, get dataelement/indicator/group...
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.ajax.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/jquery.ext.js
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/dataelementExpressionBuilderForm.vm
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/indicatorExpressionBuilderForm.vm


--
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/util/commons.ajax.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.ajax.js	2010-08-31 08:12:53 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.ajax.js	2010-08-31 08:31:58 +0000
@@ -4,13 +4,17 @@
 
 function DataDictionary()
 {
+	var ALL_KEY = 'all';
+	
 	var dataElementsGroups = new Array();
 	
-	var dataElements = new Array();
+	var dataElementGroupList = new Array();	
 	
 	var indicatorGroups = new Array();
 	
-	var indicators = new Array();
+	var indicatorGroupList = new Array();	
+	
+	var categoryOptionComboList = new Array();
 	
 	this.loadDataElementGroups = function( target )
 	{
@@ -20,8 +24,8 @@
 		{
 			jQuery.getJSON('../dhis-web-commons-ajax-json/getDataElementGroups.action'
 				, function( json ){
-					target.append('<option value="100">ALL</option>');
-					dataElementsGroups.push( new DataElementGroup(100, 'ALL') );
+					target.append('<option value="' + ALL_KEY + '">ALL</option>');
+					dataElementsGroups.push( new DataElementGroup(ALL_KEY, 'ALL') );
 					jQuery.each( json.dataElementGroups, function(i, item){
 						dataElementsGroups.push( new DataElementGroup(item.id, item.name) );
 						target.append('<option value="' + item.id + '">' + item.name + '</option>');
@@ -34,6 +38,38 @@
 		}
 	}
 	
+	this.loadAllDataElements = function( target )
+	{
+		this.loadDataElementsByGroup( ALL_KEY, target);
+	}
+	
+	this.loadDataElementsByGroup = function( id,target )
+	{
+		target.children().remove();
+		
+		var des = dataElementGroupList[id];
+		
+		if( des == null )
+		{	
+			des = new Array();
+			
+			jQuery.getJSON('../dhis-web-commons-ajax-json/getDataElements.action'	
+				,{id:id}
+				, function( json ){
+					jQuery.each( json.dataElements, function(i, item){
+						des.push( new DataElement(item.id, item.name) );
+						target.append('<option value="' + item.id + '">' + item.name + '</option>');
+					});
+					dataElementGroupList[id] = des;
+			});
+		}else{
+			jQuery.each( des, function(i, item){
+				target.append('<option value="' + item.id + '">' + item.name + '</option>');
+			});		
+		}
+	}
+	
+	
 	this.loadIndicatorGroups = function( target )
 	{
 		target.children().remove();
@@ -42,6 +78,8 @@
 		{
 			jQuery.getJSON('../dhis-web-commons-ajax-json/getIndicatorGroups.action'
 				, function( json ){
+					target.append('<option value="' + ALL_KEY + '">ALL</option>');
+					indicatorGroups.push( new IndicatorGroup( ALL_KEY, 'ALL') );
 					jQuery.each( json.indicatorGroups, function(i, item){
 						indicatorGroups.push( new IndicatorGroup(item.id, item.name) );
 						target.append('<option value="' + item.id + '">' + item.name + '</option>');
@@ -54,163 +92,78 @@
 		}	
 	}
 	
-	this.loadDataElements = function( target )
+	this.loadAllIndicators = function( target )
 	{
-		target.children().remove();
-		
-		if( dataElements.length == 0 )
-		{
-			if(this.id == 100) this.id = '';
-			jQuery.getJSON('../dhis-web-commons-ajax-json/getDataElements.action'								
-				, function( json ){
-					jQuery.each( json.dataElements, function(i, item){
-						dataElements.push( new DataElement(item.id, item.name) );
-						target.append('<option value="' + item.id + '">' + item.name + '</option>');
-					});					
-			});
-		}else{
-			jQuery.each( dataElements, function(i, item){
-				target.append('<option value="' + item.id + '">' + item.name + '</option>');
-			});		
-		}
+		this.loadIndicatorsByGroup( ALL_KEY, target);
 	}
 	
-	this.loadIndicators = function( target )
+	this.loadIndicatorsByGroup = function( id,target )
 	{
 		target.children().remove();
 		
-		if( indicators.length == 0 )
-		{
-			jQuery.getJSON('../dhis-web-commons-ajax-json/getIndicators.action'
-				, {id: this.id }					
+		var ins = indicatorGroupList[id];
+		
+		if( ins == null )
+		{	
+			ins = new Array();
+			
+			jQuery.getJSON('../dhis-web-commons-ajax-json/getIndicators.action'	
+				,{id:id}
 				, function( json ){
 					jQuery.each( json.indicators, function(i, item){
-						indicators.push( new Indicator(item.id, item.name) );
-						target.append('<option value="' + item.id + '">' + item.name + '</option>');
-					});					
-			});
-		}else{
-			jQuery.each( indicators, function(i, item){
-				target.append('<option value="' + item.id + '">' + item.name + '</option>');
-			});		
-		}	
+						ins.push( new Indicator(item.id, item.name) );
+						target.append('<option value="' + item.id + '">' + item.name + '</option>');
+					});
+					indicatorGroupList[id] = ins;
+			});
+		}else{
+			jQuery.each( ins, function(i, item){
+				target.append('<option value="' + item.id + '">' + item.name + '</option>');
+			});		
+		}
+	}	
+	
+	this.loadCategoryOptionComboByDE = function( id, target )
+	{
+		target.children().remove();
+		
+		var options = categoryOptionComboList[id];
+		
+		if( options == null )
+		{	
+			options = new Array();
+			
+			jQuery.getJSON('../dhis-web-commons-ajax-json/getCategoryOptionCombos.action'	
+				,{id:id}
+				, function( json ){
+					jQuery.each( json.categoryOptionCombos, function(i, item){
+						options.push( new OptionCombo(item.id, item.name) );
+						target.append('<option value="' + item.id + '">' + item.name + '</option>');
+					});
+					categoryOptionComboList[id] = options;
+			});
+		}else{
+			jQuery.each( options, function(i, item){
+				target.append('<option value="' + item.id + '">' + item.name + '</option>');
+			});		
+		}
+		
 	}
 	
 }
 
 var DataDictionary = new DataDictionary();
 
-
-
-
-function DataElementGroups()
-{
-	var groups = new Array();
-	
-	this.load = function( target )
-	{
-		target.children().remove();
-		
-		if( groups.length == 0 )
-		{
-			jQuery.getJSON('../dhis-web-commons-ajax-json/getDataElementGroups.action'
-				, function( json ){
-					target.append('<option value="100">ALL</option>');
-					groups.push( new DataElementGroup(100, 'ALL') );
-					jQuery.each( json.dataElementGroups, function(i, item){
-						groups.push( new DataElementGroup(item.id, item.name) );
-						target.append('<option value="' + item.id + '">' + item.name + '</option>');
-					});					
-			});
-		}else{
-			jQuery.each( groups, function(i, item){
-				target.append('<option value="' + item.id + '">' + item.name + '</option>');
-			});		
-		}			
-	}		
-	
-	this.members = function()
-	{
-		return groups;
-	}
-	
-	this.getDataElementGroup = function( id )
-	{
-		var result = null;
-		jQuery.each( groups, function(i, item){
-			if( id == item.id ) result = item;
-		});		
-		return result;
-	}
-	
-}
-
 function DataElementGroup( id_, name_ )
 {
 	this.id = id_;
-	this.name = name_;	
-	var elements = new Array();
-	
-	this.members = function( target )
-	{
-		target.children().remove();
-		
-		if( elements.length == 0 )
-		{
-			if(this.id == 100) this.id = '';
-			jQuery.getJSON('../dhis-web-commons-ajax-json/getDataElements.action'
-				, {id: this.id }					
-				, function( json ){
-					jQuery.each( json.dataElements, function(i, item){
-						elements.push( new DataElement(item.id, item.name) );
-						target.append('<option value="' + item.id + '">' + item.name + '</option>');
-					});					
-			});
-		}else{
-			jQuery.each( elements, function(i, item){
-				target.append('<option value="' + item.id + '">' + item.name + '</option>');
-			});		
-		}		
-	}
-	
-	this.getDataElement = function( id )
-	{
-		var result = null;
-		jQuery.each( elements, function(i, item){
-			if( id == item.id ) result = item;
-		});
-		
-		return result;
-	}		
+	this.name = name_;		
 }	
 
 function DataElement( id_, name_ )
 {
 	this.id = id_;
 	this.name = name_;
-	
-	var optionCombos = new Array();
-	
-	this.getCategoryOptionCombos = function( target )
-	{
-		target.children().remove();
-		
-		if( optionCombos.length == 0 )
-		{
-			jQuery.getJSON('../dhis-web-commons-ajax-json/getCategoryOptionCombos.action'
-				, {id: this.id }					
-				, function( json ){
-					jQuery.each( json.categoryOptionCombos, function(i, item){
-						optionCombos.push( new OptionCombo(item.id, item.name) );
-						target.append('<option value="' + item.id + '">' + item.name + '</option>');
-					});					
-			});
-		}else{
-			jQuery.each( optionCombos, function(i, item){
-				target.append('<option value="' + item.id + '">' + item.name + '</option>');
-			});		
-		}
-	}
 }
 
 function OptionCombo( id_, name_ )
@@ -219,89 +172,10 @@
 	this.name = name_;
 }
 
-var DATA_ELEMENT_GROUPS = new DataElementGroups();
-
-//====================================================================================
-// DATAELEMENT & DATA ELEMENT GROUP & CATEGORY OPTION COMBO
-//====================================================================================
-
-function IndicatorGroups()
-{
-	var groups = new Array();
-	
-	this.load = function( target )
-	{
-		target.children().remove();
-		
-		if( groups.length == 0 )
-		{
-			jQuery.getJSON('../dhis-web-commons-ajax-json/getIndicatorGroups.action'
-				, function( json ){
-					jQuery.each( json.indicatorGroups, function(i, item){
-						groups.push( new IndicatorGroup(item.id, item.name) );
-						target.append('<option value="' + item.id + '">' + item.name + '</option>');
-					});					
-			});
-		}else{
-			jQuery.each( groups, function(i, item){
-				target.append('<option value="' + item.id + '">' + item.name + '</option>');
-			});		
-		}			
-	}		
-	
-	this.members = function()
-	{
-		return groups;
-	}
-	
-	this.getIndicatorGroup = function( id )
-	{
-		var result = null;
-		jQuery.each( groups, function(i, item){
-			if( id == item.id ) result = item;
-		});
-		
-		return result;
-	}
-	
-}
-
 function IndicatorGroup( id_, name_ )
 {
 	this.id = id_;
-	this.name = name_;	
-	var elements = new Array();
-	
-	this.members = function( target )
-	{
-		target.children().remove();
-		
-		if( elements.length == 0 )
-		{
-			jQuery.getJSON('../dhis-web-commons-ajax-json/getIndicators.action'
-				, {id: this.id }					
-				, function( json ){
-					jQuery.each( json.indicators, function(i, item){
-						elements.push( new Indicator(item.id, item.name) );
-						target.append('<option value="' + item.id + '">' + item.name + '</option>');
-					});					
-			});
-		}else{
-			jQuery.each( elements, function(i, item){
-				target.append('<option value="' + item.id + '">' + item.name + '</option>');
-			});		
-		}		
-	}
-	
-	this.getIndicator = function( id )
-	{
-		var result = null;
-		jQuery.each( elements, function(i, item){
-			if( id == item.id ) result = item;
-		});
-		
-		return result;
-	}		
+	this.name = name_;		
 }	
 
 function Indicator( id_, name_ )
@@ -310,7 +184,4 @@
 	this.name = name_;	
 }
 
-var INDICATOR_GROUPS = new IndicatorGroups();
-
-
 

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.js	2010-08-31 08:12:53 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.js	2010-08-31 08:31:58 +0000
@@ -308,7 +308,7 @@
  * @param parentElement the DOM object.
  * @param childElementName the name of the element.
  */
-function getElementValue( parentElement, childElementName )
+function getElementaValue( parentElement, childElementName )
 {
     var textNode = parentElement.getElementsByTagName( childElementName )[0].firstChild;
     
@@ -1018,8 +1018,64 @@
 	container.show(  jQuery.blockUI({message:null}));
 	
 }
+/**
+* load All Data Element Groups into select combo box
+* @param selectorJQueryString is String fo jQuery selector, this string is anything but it must valid with jQuery format. This component will contain list of result* 
+*/
 
 function loadDataElementGroups( selectorJQueryString )
 {
 	DataDictionary.loadDataElementGroups( jQuery( selectorJQueryString ) );
-}
\ No newline at end of file
+}
+/**
+* load data elements by data element group
+* @param selectorJQueryString is String fo jQuery selector, this string is anything but it must valid with jQuery format. This component will contain list of result* 
+* @param id is data element group id
+*/
+function loadDataElementsByGroup( id, selectorJQueryString )
+{
+	DataDictionary.loadDataElementsByGroup( id, jQuery( selectorJQueryString ) );
+}
+/**
+* load All Data Elements into select combo box
+* @param selectorJQueryString is String fo jQuery selector, this string is anything but it must valid with jQuery format. This component will contain list of result* 
+*/
+function loadAllDataElements( selectorJQueryString )
+{
+	DataDictionary.loadAllDataElements( jQuery( selectorJQueryString ) );
+}
+/**
+* load Category Option Combo of data element
+* @param selectorJQueryString is String fo jQuery selector, this string is anything but it must valid with jQuery format. This component will contain list of result* 
+* @param id is data element id
+*/
+function loadCategoryOptionComboByDE( id, selectorJQueryString)
+{
+	DataDictionary.loadCategoryOptionComboByDE( id, jQuery( selectorJQueryString ) );
+}
+/**
+* load all indicator groups into select combo box
+* @param selectorJQueryString is String fo jQuery selector, this string is anything but it must valid with jQuery format. This component will contain list of result* 
+*/
+function loadIndicatorGroups( selectorJQueryString )
+{
+	DataDictionary.loadIndicatorGroups( jQuery( selectorJQueryString ) );
+}
+/**
+* load indicators by group
+* @param selectorJQueryString is String fo jQuery selector, this string is anything but it must valid with jQuery format. This component will contain list of result* 
+* @param id is indicator group id
+*/
+function loadIndicatorsByGroup( id, selectorJQueryString )
+{
+	DataDictionary.loadIndicatorsByGroup( id, jQuery( selectorJQueryString ));
+}
+/**
+* load all indicator into select combo box
+* @param selectorJQueryString is String fo jQuery selector, this string is anything but it must valid with jQuery format. This component will contain list of result* 
+*/
+function loadAllIndicators( selectorJQueryString )
+{
+	DataDictionary.loadAllIndicators( jQuery( selectorJQueryString ) );
+}
+

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/jquery.ext.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/jquery.ext.js	2010-08-31 08:12:53 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/jquery.ext.js	2010-08-31 08:31:58 +0000
@@ -1,29 +1,5 @@
 jQuery.extend({
 	postJSON: function( url, data, callback ) {
 		return jQuery.post(url, data, callback, "json");
-	},
-	loadDataElementGroups: function( target ){
-		DATA_ELEMENT_GROUPS.load( jQuery( target ) );
-	},
-	loadDataElementByGroup: function( groupId, target ){
-		var group = DATA_ELEMENT_GROUPS.getDataElementGroup( groupId );
-		if( group == null ){
-			group = new DataElementGroup( groupId );
-		}
-		group.members( jQuery( target ) );
-	},
-	loadCategoryOptionCombos: function( dataElementId, target ){
-		var dataElement = new DataElement( dataElementId );
-		dataElement.getCategoryOptionCombos( jQuery(target) ); 
-	},
-	loadIndicatorGroups: function( target ){
-		INDICATOR_GROUPS.load( jQuery( target ) );
-	},
-	loadIndicatorByGroup: function( groupId, target ){
-		var group = INDICATOR_GROUPS.getIndicatorGroup( groupId );
-		if( group == null ){
-			group = new IndicatorGroup( groupId );
-		}
-		group.members( jQuery( target ) );
 	}
 });
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/dataelementExpressionBuilderForm.vm'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/dataelementExpressionBuilderForm.vm	2010-08-31 08:12:53 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/dataelementExpressionBuilderForm.vm	2010-08-31 08:31:58 +0000
@@ -48,7 +48,7 @@
 	
 	function deExpressionBuilderForm()
 	{
-		jQuery.loadDataElementGroups("#dataelement select[id=groupSelect]") ;	
+		loadDataElementGroups("#dataelement select[id=groupSelect]") ;	
 		
 		setFieldValue( 'dataelement textarea[id=formula]', getFieldValue('expression') );
 		
@@ -57,12 +57,12 @@
 	
 	function getDataElements( id, target )
 	{
-		jQuery.loadDataElementByGroup( id, target );
+		loadDataElementsByGroup( id, target );
 	}
 	
 	function getOptionCombos( id, targetId )
 	{
-		jQuery.loadCategoryOptionCombos( id, targetId );
+		loadCategoryOptionComboByDE( id, targetId );
 	}
 	
 </script>

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/indicatorExpressionBuilderForm.vm'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/indicatorExpressionBuilderForm.vm	2010-08-31 08:12:53 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/report/indicatorExpressionBuilderForm.vm	2010-08-31 08:31:58 +0000
@@ -30,14 +30,14 @@
 	
 	function inExpressionBuilderForm()
 	{
-		jQuery.loadIndicatorGroups( "#indicator select[id=groupSelect]");		
+		loadIndicatorGroups( "#indicator select[id=groupSelect]");		
 		
 		showPopupWindowById( 'indicator', 510, 340 );
 	}
 		
 	function getIndicators( id, target)
 	{
-		jQuery.loadIndicatorByGroup( id, target );
+		loadIndicatorsByGroup( id, target );
 	}
 	
 </script>