← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1155: Add new function into commons.js and a small modification for list.js

 

------------------------------------------------------------
revno: 1155
committer: hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2009-12-03 14:32:07 +0700
message:
  Add new function into commons.js and a small modification for list.js
modified:
  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/lists.js
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/preview.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-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	2009-11-12 17:59:58 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/commons.js	2009-12-03 07:32:07 +0000
@@ -284,6 +284,19 @@
 }
 
 /**
+ * Gets the attribute value from the given DOM element.
+ * 
+ * @param parentElement the DOM object.
+ * @param attributeName the name of the attribute.
+ */
+function getElementAttribute( parentElement, childElementName, childAttributeName )
+{
+	var textNode = parentElement.getElementsByTagName( childElementName )[0];
+    
+    return textNode ? textNode.getAttribute( childAttributeName ) : null; 
+}
+
+/**
  * Gets the value from the given DOM element.
  * 
  * @param rootElement the DOM object.

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/lists.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/lists.js	2009-10-19 13:19:26 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/util/lists.js	2009-12-03 07:32:07 +0000
@@ -208,7 +208,7 @@
 
     for ( var i = list.options.length - 1; i >= 0; i-- ) {
         if ( list.options[ i ].selected ) {
-            if ( i <= list.options.length - 1 ) { // Cannot move down the option at the bottom
+            if ( i < list.options.length - 1 ) { // Cannot move down the option at the bottom
                 var subsequentOption = new Option( list.options[ i + 1 ].text, list.options[ i + 1 ].value );
                 var currentOption = new Option( list.options[ i ].text, list.options[ i ].value );
 

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java	2009-11-30 04:26:38 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java	2009-12-03 07:32:07 +0000
@@ -41,8 +41,6 @@
 import jxl.format.Colour;
 import jxl.format.Pattern;
 
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.CellReference;
 import org.hisp.dhis.reportexcel.utils.StringUtils;
 
 /**
@@ -214,7 +212,7 @@
         throws Exception
     {
         FileInputStream fis = new FileInputStream( this.PATH_FILE_NAME );
-        HSSFWorkbook hssfwb = new HSSFWorkbook( fis );
+        org.apache.poi.ss.usermodel.Workbook hssfwb = new org.apache.poi.hssf.usermodel.HSSFWorkbook ( fis );
 
         if ( bWriteDescription )
         {
@@ -282,7 +280,7 @@
                 {
                     bFormula = false;
 
-                    CellReference cellReference = new CellReference( i, j );
+                    org.apache.poi.hssf.util.CellReference cellReference = new org.apache.poi.hssf.util.CellReference( i, j );
                     org.apache.poi.ss.usermodel.Row rowRef = sheet.getRow( cellReference.getRow() );
                     org.apache.poi.ss.usermodel.Cell cellRef = rowRef.getCell( cellReference.getCol() );
 

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/preview.js'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/preview.js	2009-11-30 04:26:38 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/preview.js	2009-12-03 07:32:07 +0000
@@ -4,12 +4,15 @@
 
 function reportChanged() {
 	
-	window.location.href="selectExportReportParam.action?reportGroup=" + $("#group").val() + "&reportId=" + $("#report").val();
+	window.location.href="selectExportReportParam.action?reportGroup=" + getListValue("group") + "&reportId=" + getListValue("report");
 }
 
 function previewReport() {
 	
-	var url = "reportId=" + $('#report').val() + "&periodId=" + $('#period').val() + "&sheetId=-1";
+	aKey	= null;
+	aMerged = null;
+	
+	var url = "reportId=" + getListValue('report') + "&periodId=" + getListValue('period');
 	
 	if ( byId('availableOrgunitGroups') != null ) {
 	
@@ -27,6 +30,7 @@
 	request.send( url );
 	
 }
+
 function previewReportReceived( reportXML ) {
 
 	setMergedNumberForEachCell( reportXML );
@@ -52,10 +56,11 @@
 }
 
 function getMergedNumberForEachCell( sKey ) {
+
 	for (var i = 0 ; i < aKey.length ; i ++) {
 	
 		if ( sKey == aKey[i] ) {
-
+		
 			return Number(aMerged[i]);
 		}
 	}
@@ -70,52 +75,53 @@
 	var _rows 		= "";
 	var _cols 		= "";
 	var _sheets		= parentElement.getElementsByTagName( 'sheet' );
-	var _title		= parentElement.getElementsByTagName( 'name' )[0].firstChild.nodeValue;	
-	
-	for (var s = 0 ; s < _sheets.length ; s ++) {
-	
+	var _title		= getElementValue(parentElement, 'name');
+	
+	for (var s = 0 ; s < _sheets.length ; s ++)
+	{
 		_rows = _sheets[s].getElementsByTagName( 'row' );
 
 		_sHTML = "<table class='formatTablePreview'>";
 		
-		for (var i = 0 ; i < _rows.length ; i ++) {
-		
-			_index		= 0;
-			_sHTML += "<tr>";
-			
-			_cols = _rows[i].getElementsByTagName( 'col' );
-			
-			for (var j 	= 0 ; j < _cols.length ; ) {
-				
+		for (var i = 0 ; i < _rows.length ; i ++)
+		{
+			_index	 = 0;
+			_sHTML 	+= "<tr>";
+			
+			_cols 	 = _rows[i].getElementsByTagName( 'col' );
+			
+			for (var j 	= 0 ; j < _cols.length ; )
+			{
 				var _number	= _cols[j].getAttribute( 'no' );
 				
 				// Printing out the unformatted cells
-				for (; _index < _number ; _index ++) {
-					
+				for (; _index < _number ; _index ++)
+				{
 					_sHTML += "<td/>";
 				}
 
-				if ( _index == _number ) {
-					
-					var _no_of_merged_cell = 1;
-					var _sData		 = _cols[j].getElementsByTagName( 'data' )[0].firstChild.nodeValue;					
-					var _align		 = _cols[j].getElementsByTagName( 'format' )[0].getAttribute( 'align' );
+				if ( _index == _number )
+				{
+					var _colspan 	= 1;
+					var _sData		= getElementValue( _cols[j], 'data' );				
+					var _align		= getElementAttribute( _cols[j], 'format', 'align' );
 				
 					// If this cell is merged - Key's form: Sheet#Row#Col
-					_sPattern 			=  s + "#" + i + "#" + _number;
-					_no_of_merged_cell 	= getMergedNumberForEachCell( _sPattern );
+					_sPattern 		=  s + "#" + i + "#" + _number;
+					_colspan 		= getMergedNumberForEachCell( _sPattern );
 					
 					// Jumping for <For Loop> AND <Empty Cells>
-					j 		= Number(j) + Number(_no_of_merged_cell);
-					_index 	= Number(_index) + Number(_no_of_merged_cell);
+					j 		= Number(j) + Number(_colspan);
+					_index 	= Number(_index) + Number(_colspan);
 
-					_sHTML += "<td align='" + _align + "' colspan='" + _no_of_merged_cell;
+					_sHTML += "<td align='" + _align + "' colspan='" + _colspan;
 					
-					if ( isNaN(_sData) == false ) {
-						
+					if ( isNaN(_sData) == false )
+					{
 						_sHTML += "' class='formatNumberPreview";
 					}
-					else {
+					else
+					{
 						_sHTML += "' class='formatStringPreview";
 					}
 					_sHTML += "'>"+ _sData + "</td>";