← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6155: Using jQuery insteads of Request object in dhis-web-reporting.

 

------------------------------------------------------------
revno: 6155
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-03-04 11:12:20 +0700
message:
  Using jQuery insteads of Request object in dhis-web-reporting.
modified:
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/lists.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-reporting/src/main/webapp/dhis-web-reporting/javascript/lists.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/lists.js	2011-06-23 14:38:00 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/lists.js	2012-03-04 04:12:20 +0000
@@ -9,19 +9,18 @@
 
     if ( dataElementGroupId != null )
     {
-        var url = "../dhis-web-commons-ajax/getDataElements.action?id=" + dataElementGroupId + "&aggregate=true";
-
-        var request = new Request();
-        request.setResponseTypeXML( 'dataElement' );
-        request.setCallbackSuccess( getDataElementsReceived );
-        request.send( url );
+		$.post( '../dhis-web-commons-ajax/getDataElements.action',
+		{
+			id: dataElementGroupId,
+			aggregate: 'true'
+		},getDataElementsReceived );
     }
 }
 
 function getDataElementsReceived( xmlObject )
 {
-    var availableDataElements = document.getElementById( "availableDataElements" );
-    var selectedDataElements = document.getElementById( "selectedDataElements" );
+    var availableDataElements = byId( "availableDataElements" );
+    var selectedDataElements = byId( "selectedDataElements" );
 
     clearList( availableDataElements );
 
@@ -48,19 +47,17 @@
 
     if ( categoryComboId != null )
     {
-        var url = "getCategoryComboDataElements.action?categoryComboId=" + categoryComboId;
-
-        var request = new Request();
-        request.setResponseTypeXML( 'dataElement' );
-        request.setCallbackSuccess( getCategoryComboDataElementsReceived );
-        request.send( url );
+		$.post( 'getCategoryComboDataElements.action',
+		{
+			categoryComboId: categoryComboId
+		},getCategoryComboDataElementsReceived );
     }
 }
 
 function getCategoryComboDataElementsReceived( xmlObject )
 {
-    var availableDataElements = document.getElementById( "availableDataElements" );
-    var selectedDataElements = document.getElementById( "selectedDataElements" );
+    var availableDataElements = byId( "availableDataElements" );
+    var selectedDataElements = byId( "selectedDataElements" );
 
     clearList( availableDataElements );
     clearList( selectedDataElements );
@@ -81,17 +78,15 @@
 
 function getIndicators()
 {
-    var indicatorGroupList = document.getElementById( "indicatorGroupId" );
+    var indicatorGroupList = byId( "indicatorGroupId" );
     var indicatorGroupId = indicatorGroupList.options[indicatorGroupList.selectedIndex].value;
 
     if ( indicatorGroupId != null )
     {
-        var url = "../dhis-web-commons-ajax/getIndicators.action?id=" + indicatorGroupId;
-
-        var request = new Request();
-        request.setResponseTypeXML( 'indicator' );
-        request.setCallbackSuccess( getIndicatorsReceived );
-        request.send( url );
+		$.post( '../dhis-web-commons-ajax/getIndicators.action',
+		{
+			id: indicatorGroupId
+		},getIndicatorsReceived );
     }
 }
 
@@ -126,19 +121,17 @@
 
     if ( organisationUnitLevel != null )
     {
-        var url = "../dhis-web-commons-ajax/getOrganisationUnits.action?level=" + organisationUnitLevel;
-
-        var request = new Request();
-        request.setResponseTypeXML( 'organisationUnit' );
-        request.setCallbackSuccess( getOrganisationUnitsReceived );
-        request.send( url );
+		$.post( '../dhis-web-commons-ajax/getOrganisationUnits.action',
+		{
+			level: organisationUnitLevel
+		},getOrganisationUnitsReceived );
     }
 }
 
 function getOrganisationUnitsReceived( xmlObject )
 {
-    var availableOrganisationUnits = document.getElementById( "availableOrganisationUnits" );
-    var selectedOrganisationUnits = document.getElementById( "selectedOrganisationUnits" );
+    var availableOrganisationUnits = byId( "availableOrganisationUnits" );
+    var selectedOrganisationUnits = byId( "selectedOrganisationUnits" );
 
     clearList( availableOrganisationUnits );
 
@@ -159,61 +152,26 @@
     }
 }
 
-function getOrganisationUnitsToSelected()
-{
-    var organisationUnitLevelList = document.getElementById( "organisationUnitLevel" );
-    var organisationUnitLevel = organisationUnitLevelList.options[organisationUnitLevelList.selectedIndex].value;
-
-    if ( organisationUnitLevel != null )
-    {
-        var url = "../dhis-web-commons-ajax/getOrganisationUnits.action?level=" + organisationUnitLevel;
-
-        var request = new Request();
-        request.setResponseTypeXML( 'organisationUnit' );
-        request.setCallbackSuccess( getOrganisationUnitsToSelectedReceived );
-        request.send( url );
-    }
-}
-
-function getOrganisationUnitsToSelectedReceived( xmlObject )
-{
-    var selectedOrganisationUnits = document.getElementById( "selectedOrganisationUnits" );
-
-    clearList( selectedOrganisationUnits );
-
-    var organisationUnits = xmlObject.getElementsByTagName( "organisationUnit" );
-
-    for ( var i = 0; i < organisationUnits.length; i++ )
-    {
-        var id = organisationUnits[i].getElementsByTagName( "id" )[0].firstChild.nodeValue;
-        var organisationUnitName = organisationUnits[i].getElementsByTagName( "name" )[0].firstChild.nodeValue;
-
-        var option = document.createElement( "option" );
-        option.value = id;
-        option.text = organisationUnitName;
-        selectedOrganisationUnits.add( option, null );
-    }
-}
-
 function getOrganisationUnitChildren()
 {
-    var organisationUnitList = document.getElementById( "availableOrganisationUnits" );
-    var organisationUnitId = organisationUnitList.options[organisationUnitList.selectedIndex].value;
-
-    if ( organisationUnitId != null )
-    {
-        var url = "../dhis-web-commons-ajax/getOrganisationUnitChildren.action?id=" + organisationUnitId;
-
-        var request = new Request();
-        request.setResponseTypeXML( 'organisationUnit' );
-        request.setCallbackSuccess( getOrganisationUnitChildrenReceived );
-        request.send( url );
-    }
+    var organisationUnitList = byId( "availableOrganisationUnits" );
+	if( organisationUnitList.selectedIndex != -1 )
+	{
+		var organisationUnitId = organisationUnitList.options[organisationUnitList.selectedIndex].value;
+
+		if ( organisationUnitId != null )
+		{
+			$.post( '../dhis-web-commons-ajax/getOrganisationUnitChildren.action',
+				{
+					id: organisationUnitId
+				},getOrganisationUnitChildrenReceived );
+		}
+	}
 }
 
 function getOrganisationUnitChildrenReceived( xmlObject )
 {
-    var selectedOrganisationUnits = document.getElementById( "selectedOrganisationUnits" );
+    var selectedOrganisationUnits = byId( "selectedOrganisationUnits" );
 
     var organisationUnits = xmlObject.getElementsByTagName( "organisationUnit" );
 
@@ -232,39 +190,3 @@
         }
     }
 }
-
-function getPeriodsToSelected()
-{
-    var periodTypeList = document.getElementById( "periodTypeId" );
-    var periodTypeId = periodTypeList.options[periodTypeList.selectedIndex].value;
-
-    if ( periodTypeId != null )
-    {
-        var url = "../dhis-web-commons-ajax/getPeriods.action?name=" + periodTypeId;
-
-        var request = new Request();
-        request.setResponseTypeXML( 'period' );
-        request.setCallbackSuccess( getPeriodsToSelectedReceived );
-        request.send( url );
-    }
-}
-
-function getPeriodsToSelectedReceived( xmlObject )
-{
-    var selectedPeriods = document.getElementById( "selectedPeriods" );
-
-    clearList( selectedPeriods );
-
-    var periods = xmlObject.getElementsByTagName( "period" );
-
-    for ( var i = 0; i < periods.length; i++ )
-    {
-        var id = periods[i].getElementsByTagName( "id" )[0].firstChild.nodeValue;
-        var periodName = periods[i].getElementsByTagName( "name" )[0].firstChild.nodeValue;
-
-        var option = document.createElement( "option" );
-        option.value = id;
-        option.text = periodName;
-        selectedPeriods.add( option, null );
-    }
-}