← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1157: Change JQuery by DHIS library - work in process

 

------------------------------------------------------------
revno: 1157
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2009-12-03 15:35:53 +0700
message:
  Change JQuery by DHIS library - work in process
modified:
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/individual/action/GenerateIndividualReportExcelAction.java
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/GetImportingParamsAction.java
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/individualReportExcel.vm
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.js
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/individual.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-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/individual/action/GenerateIndividualReportExcelAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/individual/action/GenerateIndividualReportExcelAction.java	2009-11-18 04:14:34 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/individual/action/GenerateIndividualReportExcelAction.java	2009-12-03 08:35:53 +0000
@@ -37,6 +37,8 @@
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.expression.ExpressionService;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.reportexcel.export.action.GenerateReportSupport;
@@ -59,6 +61,8 @@
 
     private ExpressionService expressionService;
 
+    public I18nFormat format;
+    
     // ---------------------------------------------------------------------------------------------------
     // Inputs && Outputs
     // ---------------------------------------------------------------------------------------------------
@@ -66,6 +70,12 @@
     private String[] operands;
 
     private Integer[] periods;
+    
+    private OrganisationUnit organisationUnit;
+    
+    public String message;
+
+    public I18n i18n;
 
     // ---------------------------------------------------------------------------------------------------
     // Getters && Setters
@@ -76,7 +86,23 @@
         this.dataValueService = dataValueService;
     }
 
-    public void setExpressionService( ExpressionService expressionService )
+    public String getMessage() {
+		return message;
+	}
+
+	public void setFormat(I18nFormat format) {
+		this.format = format;
+	}
+
+	public void setI18n(I18n i18n) {
+		this.i18n = i18n;
+	}
+
+	public OrganisationUnit getOrganisationUnit() {
+		return organisationUnit;
+	}
+
+	public void setExpressionService( ExpressionService expressionService )
     {
         this.expressionService = expressionService;
     }
@@ -100,8 +126,13 @@
     {
         statementManager.initialise();
         
-        OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit();
+        organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit();
         
+        if(organisationUnit == null){
+        	message = i18n.getString("choose_orgUnit");
+        	return ERROR;
+        }
+        	
         templateWorkbook = new HSSFWorkbook();
         
         HSSFSheet sheet = templateWorkbook.createSheet( organisationUnit.getName() ); 

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/GetImportingParamsAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/GetImportingParamsAction.java	2009-11-13 10:28:52 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/GetImportingParamsAction.java	2009-12-03 08:35:53 +0000
@@ -135,7 +135,6 @@
 
         if ( organisationUnit == null )
         {
-
             return SUCCESS;
         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties	2009-12-03 04:08:58 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties	2009-12-03 08:35:53 +0000
@@ -168,4 +168,7 @@
 enddate_null				= Please enter end date
 select_report               = [Select report]
 error						= Error
-not_null					= not null
\ No newline at end of file
+not_null					= not null
+choose_orgUnit				= Not choose organisation yet
+choose_period				= Not choose period yet
+choose_dataelement			= Not choose dataelement yet
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml	2009-11-30 04:26:38 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml	2009-12-03 08:35:53 +0000
@@ -750,6 +750,8 @@
 			class="org.hisp.dhis.reportexcel.export.individual.action.GenerateIndividualReportExcelAction">
 			<result name="success" type="velocity-xml">
 				/dhis-web-excel-reporting/responseSuccess.vm</result>
+			<result name="error" type="velocity-xml">
+				/dhis-web-excel-reporting/responseError.vm</result>
 		</action>
 
 		<action name="cleanUpReportExcel"

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/individualReportExcel.vm'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/individualReportExcel.vm	2009-11-13 10:28:52 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/individualReportExcel.vm	2009-12-03 08:35:53 +0000
@@ -109,8 +109,7 @@
 		<tr>
         <td>
           <select id="availabelPeriodTypes" name="availabelPeriodTypes" style="width:30em ;" onChange="javascript: getPeriodsByPeriodTypeName();">
-            
-			<option value="" ></option>
+           
             #foreach ( $periodType in $periodTypes )
               
             <option value="$periodType.name" >$i18n.getString( $periodType.name )</option>
@@ -169,5 +168,10 @@
 	#end
 
 	initLists();
+	
+	getPeriodsByPeriodTypeName();
+	
+	var choose_period = '$encoder.jsEscape($i18n.getString( 'choose_period' ) , "'")';
+	var choose_dataelement = '$encoder.jsEscape($i18n.getString( 'choose_dataelement' ) , "'")';
 
 </script>

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.js'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.js	2009-11-13 10:28:52 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.js	2009-12-03 08:35:53 +0000
@@ -17,22 +17,21 @@
 	request.setCallbackSuccess( importDataCompleted );
 	
 	// URL
-	url = 'importData.action?excelItemGroupId='+excelItemGroupId;
+	var params = 'excelItemGroupId='+excelItemGroupId;
 	// USER choose reportItem
 	var preview = byId('showValue').style.display;
 	
 	if(preview == 'block'){
-		
 		var excelItems = document.getElementsByName('excelItems');
 		for(var i=0;i<excelItems.length;i++){
 			if(excelItems[i].checked ){
-				url +='&excelItemIds=' + excelItems[i].value;
+				params +='&excelItemIds=' + excelItems[i].value;
 			}
 		}
 	}	
-	url += '&periodId='+ periodId;
-	
-	request.send(url); 
+	params += '&periodId='+ periodId;
+	request.sendAsPost(params);
+	request.send('importData.action'); 
 }
 
 function importDataCompleted( xmlObject ){
@@ -45,25 +44,14 @@
 // -----------------------------------------------------------------------------
 
 function getPreviewImportData(){	
-		
+	
 	var request = new Request();
-	
 	request.setResponseTypeXML( 'xmlObject' );
-	
 	request.setCallbackSuccess( getReportItemValuesReceived );
-	
-	var excelItemGroupId = byId("excelItemGroupId").value;
-	
-	request.send( "previewDataFlow.action?excelItemGroupId=" + excelItemGroupId );
-		
+	request.send( "previewDataFlow.action?excelItemGroupId=" + byId("excelItemGroupId").value );
 	
 }
 
-
-// -----------------------------------------------------------------------------
-// PREVIEW DATA FLOW RECEIVED
-// -----------------------------------------------------------------------------
-
 function getReportItemValuesReceived( xmlObject ){
 	
 	if(xmlObject.getElementsByTagName('excelItemValueByOrgUnit').length > 0 ){
@@ -145,14 +133,13 @@
 	{
 		myTable.deleteRow(i -1);
 	}
-
+	
 	for(var i=0;i<availableObjectList.length;i++){
 		
 		// get item into XML
 		var itemValue = availableObjectList.item(i);
 		
 		
-		
 		// Add new row which contains to Organisation's name
 		var newTR = document.createElement('tr');
 		var newTD = document.createElement('td');
@@ -165,7 +152,6 @@
 		tBody.appendChild(newTR);
 		
 		
-		
 		// get values
 		var valueList = itemValue.getElementsByTagName('excelItemValue');
 		for(var j=0;j<valueList.length;j++) {

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/individual.js'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/individual.js	2009-11-13 10:28:52 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/individual.js	2009-12-03 08:35:53 +0000
@@ -6,7 +6,12 @@
 	
 	clearListById('availableOptionCombos');
 	
-	$.get("getOptionCombos.action",
+	var request = new Request();
+	request.setResponseTypeXML( 'xmlObject' );
+	request.setCallbackSuccess( getOptionCombosReceived );
+	request.send( "getOptionCombos.action?dataElementId=" + byId("availableDataElements").value );
+	
+	/*$.get("getOptionCombos.action",
 		{
 		dataElementId:$("#availableDataElements").val()
 		},
@@ -30,7 +35,26 @@
 			}
 		
 		}
-	,'xml');
+	,'xml'); */
+}
+
+function getOptionCombosReceived( xmlObject ){
+	
+	xmlObject = xmlObject.getElementsByTagName('categoryOptions')[0];		
+			
+	var optionComboList = byId( "availableOptionCombos" );			
+			
+	optionComboList.options.length = 0;		
+	var optionCombos = xmlObject.getElementsByTagName( "categoryOption" );		
+	for ( var i = 0; i < optionCombos.length; i++)
+	{
+		var id = optionCombos[ i ].getAttribute('id');
+		var name = optionCombos[ i ].firstChild.nodeValue;			
+		var option = document.createElement( "option" );
+		option.value = id ;
+		option.text = name;
+		optionComboList.add( option, null );	
+	}
 }
 
 // -----------------------------------------------------------------------------
@@ -39,23 +63,20 @@
 
 function filterByDataElementGroup( selectedDataElementGroup )
 {
-	  var request = new Request();
-
-	  var requestString = 'filterAvailableDataElementsByDataElementGroup.action';
-	  
-	  var params = 'dataElementGroupId=' + selectedDataElementGroup;
-
-	  var selectedList = byId( 'selectedDataElements' );
-
-		
-	  for ( var i = 0; i < selectedList.options.length; ++i)
-	  {
+	
+	var request = new Request();
+	var requestString = 'filterAvailableDataElementsByDataElementGroup.action';
+	var params = 'dataElementGroupId=' + selectedDataElementGroup;
+	var selectedList = byId( 'selectedDataElements' );
+	
+	for ( var i = 0; i < selectedList.options.length; ++i)
+	{
 		var selectedValue = selectedList.options[i].value;
-		  
+	  
 		var id = selectedValue.substring(selectedValue.indexOf(".") + 1, selectedValue.length);
 
 		params += '&selectedDataElements=' + id;
-	  }
+	 }
 
 	  // Clear the Dataelement list
 	  var availableList = document.getElementById( 'availableDataElements' );
@@ -163,7 +184,6 @@
 		
 		byId( 'selectedDataElements' ).add(option, null );
 		
-		
 		listOptionCombo.remove( listOptionCombo.selectedIndex );
     }
 }
@@ -240,34 +260,51 @@
 // -----------------------------------------------------------------------------
 
 function generateIndividualReportExcel(){
-	
-	// get operands
-	var operands = new Array();
+	// Check operands
 	var selectedDataElements = byId('selectedDataElements').options;
-	for ( var i = 0; i < selectedDataElements.length; i++ )
+	var message = '';
+	if( selectedDataElements.length==0)
 	{
-		operands[i] = selectedDataElements[i].value;
-	}	
-	
-	// get periods
-	var periods = new Array();
+		message = choose_dataelement + '<br>';
+	}
+	// Check periods
 	selectedDataElements = byId('selectedPeriods').options;
-	for ( var i = 0; i < selectedDataElements.length; i++ )
+	if(selectedDataElements.length==0)
 	{
-		periods[i] = selectedDataElements[i].value;
+		message += choose_period + '<br>';
 	}
 	
+	if(message.length > 0 ){
+		setMessage(message);
+		return;
+	}
 	$("#loading").showAtCenter( true );	
-		$.post("generateIndividualReportExcel.action",{
-		operands:operands,
-		periods:periods
-		},function(data){		
-			window.location = "downloadFile.action?outputFormat=";
-			deleteDivEffect();
-			$("#loading").hide();		
-		},'xml');
+	
+	var request = new Request();
+	request.setResponseTypeXML( 'xmlObject' );
+	request.setCallbackSuccess( generateIndividualReportExcelReceived );
+	var params = getQueryStringFromList('selectedDataElements', 'operands');
+	params += getQueryStringFromList('selectedPeriods', 'periods');
+	request.sendAsPost(params);
+	request.send( "generateIndividualReportExcel.action");
+	
 }
 
+function generateIndividualReportExcelReceived(xmlObject){
+	
+	var type = xmlObject.getAttribute( 'type' );
+	
+	if(type=='error')
+	{
+		setMessage( xmlObject.firstChild.nodeValue);
+	}else if(type=='success')
+	{
+		window.location = "downloadFile.action?outputFormat=";
+	}
+	
+	deleteDivEffect();
+	$("#loading").hide();
+}
 // -----------------------------------------------------------------------------
 function showToolTip( e, value){
 	
@@ -303,7 +340,7 @@
 	var request = new Request();
 	request.setResponseTypeXML( 'xmlObject' );
 	request.setCallbackSuccess( responseListPeriodReceived );
-	request.send( 'getPeriodsByPeriodTypeDB.action?periodTypeName=' + $("#availabelPeriodTypes").val());
+	request.send( 'getPeriodsByPeriodTypeDB.action?periodTypeName=' + byId("availabelPeriodTypes").value);
 }
 
 function lastPeriod() {