dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #02023
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 669: New function : Import data from excel file to database
------------------------------------------------------------
revno: 669
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2009-09-11 15:08:13 +0700
message:
New function : Import data from excel file to database
removed:
local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/ViewDataFromExcelFileAction.java
modified:
local/vn/dhis-service-chr/src/main/java/org/hisp/dhis/vn/chr/jdbc/JDBCFormManager.java
local/vn/dhis-service-chr/src/main/java/org/hisp/dhis/vn/chr/statement/CreateCodeStatement.java
local/vn/dhis-web-chr-form/src/main/java/org/hisp/dhis/vn/chr/object/action/CreateCodeAction.java
local/vn/dhis-web-chr-form/src/main/resources/META-INF/dhis/beans.xml
local/vn/dhis-web-chr-form/src/main/resources/struts.xml
local/vn/dhis-web-chr-form/src/main/webapp/dhis-web-chr-form/javascripts/forms.js
local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/ImportDataAction.java
local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/UploadExcelFileAction.java
local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/ViewDataAction.java
local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/reportitem/action/AddReportItemAction.java
local/vn/dhis-web-vn-report/src/main/webapp/dhis-web-vn-report/importData.vm
local/vn/dhis-web-vn-report/src/main/webapp/dhis-web-vn-report/javascript/imports.js
local/vn/dhis-web-vn-report/src/main/webapp/dhis-web-vn-report/responseReportItemValues.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 'local/vn/dhis-service-chr/src/main/java/org/hisp/dhis/vn/chr/jdbc/JDBCFormManager.java'
--- local/vn/dhis-service-chr/src/main/java/org/hisp/dhis/vn/chr/jdbc/JDBCFormManager.java 2009-09-10 10:50:06 +0000
+++ local/vn/dhis-service-chr/src/main/java/org/hisp/dhis/vn/chr/jdbc/JDBCFormManager.java 2009-09-11 08:08:13 +0000
@@ -542,7 +542,7 @@
{
count = resultSet.getInt( 1 ) + 1;
-
+System.out.println("\n\n\n count : " + count);
if ( count < 10 )
{
return "00" + count;
@@ -562,7 +562,7 @@
{
holder.close();
}
-
+System.out.println("\n\n\n count : " + count);
return count + "";
}
}
=== modified file 'local/vn/dhis-service-chr/src/main/java/org/hisp/dhis/vn/chr/statement/CreateCodeStatement.java'
--- local/vn/dhis-service-chr/src/main/java/org/hisp/dhis/vn/chr/statement/CreateCodeStatement.java 2009-09-10 10:56:49 +0000
+++ local/vn/dhis-service-chr/src/main/java/org/hisp/dhis/vn/chr/statement/CreateCodeStatement.java 2009-09-11 08:08:13 +0000
@@ -2,13 +2,9 @@
import java.text.Format;
import java.text.SimpleDateFormat;
-import java.util.Collection;
import java.util.Date;
import org.hisp.dhis.jdbc.StatementBuilder;
-import org.hisp.dhis.user.User;
-import org.hisp.dhis.vn.chr.Egroup;
-import org.hisp.dhis.vn.chr.Element;
import org.hisp.dhis.vn.chr.Form;
public class CreateCodeStatement extends FormStatement
@@ -41,13 +37,16 @@
buffer.append( "FROM" + SPACE + form.getName().toLowerCase() + SPACE);
// WHERE
Date date = new Date();
- Format formatter = new SimpleDateFormat( "yyyy-MM" );
- String period = formatter.format(date);
+ // year
+ Format formatter = new SimpleDateFormat( "yyyy" );
+ String year = formatter.format(date);
+ // month
+ formatter = new SimpleDateFormat( "MM" );
+ int month =Integer.parseInt( formatter.format(date));
- buffer.append( "WHERE" + SPACE + "createddate>=" + period + "-" + "01" + SPACE );
- buffer.append( "AND" + SPACE + "createddate<=" + period + "-" + "31" );
+ buffer.append( "WHERE" + SPACE + "createddate>='" + year + "-" + month + "-" + "01'" + SPACE );
+ buffer.append( "AND" + SPACE + "createddate<'"+ year + "-" + (month + 1) + "-" + "01'" );
statement = buffer.toString();
-
}
}
=== modified file 'local/vn/dhis-web-chr-form/src/main/java/org/hisp/dhis/vn/chr/object/action/CreateCodeAction.java'
--- local/vn/dhis-web-chr-form/src/main/java/org/hisp/dhis/vn/chr/object/action/CreateCodeAction.java 2009-09-10 10:56:49 +0000
+++ local/vn/dhis-web-chr-form/src/main/java/org/hisp/dhis/vn/chr/object/action/CreateCodeAction.java 2009-09-11 08:08:13 +0000
@@ -15,6 +15,10 @@
implements Action
{
+ // -------------------------------------------
+ // Dependency
+ // -------------------------------------------
+
private FormManager formManager;
public void setFormManager( FormManager formManager )
@@ -29,6 +33,10 @@
this.formService = formService;
}
+ // -------------------------------------------
+ // Input && Output
+ // -------------------------------------------
+
private Integer formId;
public void setFormId( Integer formId )
@@ -42,12 +50,14 @@
{
return code;
}
-
+
+ // -------------------------------------------
+ // Action Implemantation
+ // -------------------------------------------
public String execute()
throws Exception
{
- // create code : MCH<yyMM>
Date date = new Date();
Format formatter = new SimpleDateFormat( "yyMM" );
=== modified file 'local/vn/dhis-web-chr-form/src/main/resources/META-INF/dhis/beans.xml'
--- local/vn/dhis-web-chr-form/src/main/resources/META-INF/dhis/beans.xml 2009-09-10 10:50:06 +0000
+++ local/vn/dhis-web-chr-form/src/main/resources/META-INF/dhis/beans.xml 2009-09-11 08:08:13 +0000
@@ -261,7 +261,7 @@
class="org.hisp.dhis.vn.chr.object.action.SearchObjectAction" scope="prototype">
<property name="formService" ref="org.hisp.dhis.vn.chr.FormService" />
<property name="formManager" ref="org.hisp.dhis.vn.chr.jdbc.FormManager" />
- <property name="sysetmSettingManager" ref="org.hisp.dhis.options.SystemSettingManager" />
+ <property name="systemSettingManager" ref="org.hisp.dhis.options.SystemSettingManager" />
<property name="elementService" ref="org.hisp.dhis.vn.chr.ElementService" />
</bean>
=== modified file 'local/vn/dhis-web-chr-form/src/main/resources/struts.xml'
--- local/vn/dhis-web-chr-form/src/main/resources/struts.xml 2009-09-10 10:50:06 +0000
+++ local/vn/dhis-web-chr-form/src/main/resources/struts.xml 2009-09-11 08:08:13 +0000
@@ -196,7 +196,7 @@
<result name="success" type="chain">getVisibleForms</result>
<param name="page">/dhis-web-chr-form/addForm.vm</param>
<param name="menu">/dhis-web-chr-form/menu.vm</param>
- <param name="javascripts">javascripts/forms.js</param>
+ <param name="javascripts">javascripts/forms.js, javascripts/dhtmlgoodies_calendar.js, javascripts/calendar.js</param>
<param name="stylesheets">styles/dhtmlgoodies_calendar.css</param>
</action>
=== modified file 'local/vn/dhis-web-chr-form/src/main/webapp/dhis-web-chr-form/javascripts/forms.js'
--- local/vn/dhis-web-chr-form/src/main/webapp/dhis-web-chr-form/javascripts/forms.js 2009-09-10 10:50:06 +0000
+++ local/vn/dhis-web-chr-form/src/main/webapp/dhis-web-chr-form/javascripts/forms.js 2009-09-11 08:08:13 +0000
@@ -971,5 +971,5 @@
}
function createCodeReceived( xmlObject ){
- this.inputObject.value = xmlObject.getElementsByTagName("code").item[0].firstChild.nodeValue;
+ this.inputObject.value = xmlObject.getElementsByTagName("code")[0].firstChild.nodeValue;
}
\ No newline at end of file
=== modified file 'local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/ImportDataAction.java'
--- local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/ImportDataAction.java 2009-09-10 10:50:06 +0000
+++ local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/ImportDataAction.java 2009-09-11 08:08:13 +0000
@@ -6,6 +6,7 @@
*/
import java.io.File;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;
@@ -122,6 +123,13 @@
this.periodId = periodId;
}
+ public Integer[] reportItemIds;
+
+ public void setReportItemIds( Integer[] reportItemIds )
+ {
+ this.reportItemIds = reportItemIds;
+ }
+
// --------------------------------------------------------------------
// Action Implementation
// --------------------------------------------------------------------
@@ -141,9 +149,17 @@
ws.setLocale( new Locale( "en", "EN" ) );
Workbook templateWorkbook = Workbook.getWorkbook( upload, ws );
- // get reportItems of the template report
- Collection<ReportItem> reportItems = report.getReportItems();
-
+ Collection<ReportItem> reportItems = new ArrayList<ReportItem>();
+ // check reportItems inputted
+ if(reportItemIds!=null){
+ for(int i=0;i<reportItemIds.length;i++){
+ reportItems.add( reportExcelService.getReportItem( reportItemIds[i] ) );
+ }
+ }else{
+ // get reportItems of the template report
+ reportItems = report.getReportItems();
+ }
+
Sheet sheet = templateWorkbook.getSheet( 0 );
// get period
@@ -156,46 +172,48 @@
String value = ExcelUtils.readValue( reportItem.getRow(), reportItem.getColumn(), sheet );
- // Get expression of the reportItem
- Operand operand = expressionService.getOperandsInExpression( reportItem.getExpression() ).iterator()
- .next();
-
- // dateelement of the reportItem
- DataElement dataElement = dataElementService.getDataElement( operand.getDataElementId() );
-
- DataElementCategoryOptionCombo optionCombo = dataElementCategoryOptionComboService
- .getDataElementCategoryOptionCombo( operand.getOptionComboId() );
-
- // logged username
- String storedBy = currentUserService.getCurrentUsername();
-
- DataValue dataValue = dataValueService
- .getDataValue( organisationUnit, dataElement, period, optionCombo );
-
- // if dataValue is not exist, that means data not input
- // add value into database
- if ( dataValue == null )
- {
- dataValue = new DataValue( dataElement, period, organisationUnit, value + "", storedBy, new Date(),
- null, optionCombo );
- dataValueService.addDataValue( dataValue );
- }
- // if dataValue is exist, update new value
- else
- {
- dataValue.setValue( value + "" );
- dataValue.setTimestamp( new Date() );
- dataValue.setStoredBy( storedBy );
-
- dataValueService.updateDataValue( dataValue );
-
- }// end if
+ if ( !value.isEmpty() )
+ {
+ // Get expression of the reportItem
+ Operand operand = expressionService.getOperandsInExpression( reportItem.getExpression() )
+ .iterator().next();
+
+ // dateelement of the reportItem
+ DataElement dataElement = dataElementService.getDataElement( operand.getDataElementId() );
+
+ DataElementCategoryOptionCombo optionCombo = dataElementCategoryOptionComboService
+ .getDataElementCategoryOptionCombo( operand.getOptionComboId() );
+
+ // logged username
+ String storedBy = currentUserService.getCurrentUsername();
+
+ DataValue dataValue = dataValueService.getDataValue( organisationUnit, dataElement, period,
+ optionCombo );
+
+ // if dataValue is not exist, that means data not input
+ // add value into database
+ if ( dataValue == null )
+ {
+ dataValue = new DataValue( dataElement, period, organisationUnit, value + "", storedBy,
+ new Date(), null, optionCombo );
+ dataValueService.addDataValue( dataValue );
+ }
+ // if dataValue is exist, update new value
+ else
+ {
+ dataValue.setValue( value + "" );
+ dataValue.setTimestamp( new Date() );
+ dataValue.setStoredBy( storedBy );
+
+ dataValueService.updateDataValue( dataValue );
+
+ }// end if
+ }// end if value
}
}
-
+
message = i18n.getString( "success" );
return SUCCESS;
}
-
}
\ No newline at end of file
=== modified file 'local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/UploadExcelFileAction.java'
--- local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/UploadExcelFileAction.java 2009-09-09 09:19:35 +0000
+++ local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/UploadExcelFileAction.java 2009-09-11 08:08:13 +0000
@@ -10,8 +10,6 @@
import org.hisp.dhis.vn.report.action.ActionSupport;
import org.hisp.dhis.vn.report.state.ReportLocationManager;
-import com.opensymphony.xwork2.Action;
-
public class UploadExcelFileAction
extends ActionSupport
{
=== modified file 'local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/ViewDataAction.java'
--- local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/ViewDataAction.java 2009-09-10 10:56:49 +0000
+++ local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/ViewDataAction.java 2009-09-11 08:08:13 +0000
@@ -91,12 +91,14 @@
if ( reportItem.getItemType().equals( ReportItem.TYPE.DATAELEMENT ) )
{
String value = ExcelUtils.readValue( reportItem.getRow(), reportItem.getColumn(), sheet );
-
- ReportItemValue reportItemvalue = new ReportItemValue( reportItem, value );
-
- reportItemValues.add( reportItemvalue );
-
- }// end if
+
+ if ( !value.isEmpty() )
+ {
+ ReportItemValue reportItemvalue = new ReportItemValue( reportItem, value );
+
+ reportItemValues.add( reportItemvalue );
+ } // end if value
+ }// end if reportitems
}// end for
return SUCCESS;
=== removed file 'local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/ViewDataFromExcelFileAction.java'
--- local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/ViewDataFromExcelFileAction.java 2009-09-09 09:19:35 +0000
+++ local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/imports/action/ViewDataFromExcelFileAction.java 1970-01-01 00:00:00 +0000
@@ -1,123 +0,0 @@
-package org.hisp.dhis.vn.imports.action;
-
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
-import org.hisp.dhis.vn.imports.ReportItemValue;
-import org.hisp.dhis.vn.report.ReportExcelInterface;
-import org.hisp.dhis.vn.report.ReportExcelService;
-import org.hisp.dhis.vn.report.ReportItem;
-import org.hisp.dhis.vn.report.action.ActionSupport;
-import org.hisp.dhis.vn.report.state.ReportLocationManager;
-import org.hisp.dhis.vn.report.utils.ExcelUtils;
-
-import java.io.File;
-import java.util.*;
-
-import jxl.Cell;
-import jxl.Sheet;
-import jxl.Workbook;
-
-public class ViewDataFromExcelFileAction
- extends ActionSupport
-{
- // -------------------------------------------
- // Dependency
- // -------------------------------------------
-
- private ReportLocationManager reportLocationManager;
-
- private OrganisationUnitSelectionManager organisationUnitSelectionManager;
-
- private ReportExcelService reportExcelService;
-
- // -------------------------------------------
- // Input & Output
- // -------------------------------------------
-
- private String fileName;
-
- private Integer reportId;
-
- private List<ReportItemValue> values;
-
- private ReportExcelInterface report;
-
- // -------------------------------------------
- // Getter & Setter
- // -------------------------------------------
-
- public void setReportLocationManager( ReportLocationManager reportLocationManager )
- {
- this.reportLocationManager = reportLocationManager;
- }
-
- public void setReportExcelService( ReportExcelService reportExcelService )
- {
- this.reportExcelService = reportExcelService;
- }
-
- public ReportExcelInterface getReport()
- {
- return report;
- }
-
- public void setReportId( Integer reportId )
- {
- this.reportId = reportId;
- }
-
- public void setOrganisationUnitSelectionManager( OrganisationUnitSelectionManager organisationUnitSelectionManager )
- {
- this.organisationUnitSelectionManager = organisationUnitSelectionManager;
- }
-
- public void setFileName( String fileName )
- {
- this.fileName = fileName;
- }
-
- public List<ReportItemValue> getValues()
- {
- return values;
- }
-
- public String execute()
- throws Exception
- {
- this.report = reportExcelService.getReport( reportId );
-
- System.out.println("Sheet no: " + 1);
-
- this.values = new ArrayList<ReportItemValue>();
-
- System.out.println("Sheet no: " + 2);
-
- OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit();
-
- System.out.println("Sheet no: " + 3);
-
- File excel = new File( reportLocationManager.getDirectory( organisationUnit ), fileName );
-
- Workbook templateWorkbook = Workbook.getWorkbook( excel );
-
- System.out.println("Sheet no: " + 5);
-
- for ( Integer sheetNo : reportExcelService.getSheets( reportId ) )
- {
-
- Sheet sheet = templateWorkbook.getSheet( sheetNo );
-
- Collection<ReportItem> reportItems = reportExcelService.getReportItem( sheetNo, reportId );
-
- for ( ReportItem item : reportItems )
- {
- Cell cell = ExcelUtils.getValue( item.getRow(), item.getColumn(), sheet );
-
- values.add( new ReportItemValue( item, cell.getContents() ) );
- }
-
- }
-
- return SUCCESS;
- }
-}
=== modified file 'local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/reportitem/action/AddReportItemAction.java'
--- local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/reportitem/action/AddReportItemAction.java 2009-09-01 13:19:47 +0000
+++ local/vn/dhis-web-vn-report/src/main/java/org/hisp/dhis/vn/reportitem/action/AddReportItemAction.java 2009-09-11 08:08:13 +0000
@@ -65,14 +65,12 @@
private Integer reportId;
private ReportItem reportItem;
-
+
private Integer sheetNo;
// -------------------------------------------
// Getter & Setter
// -------------------------------------------
-
-
public void setReportService( ReportExcelService reportService )
{
@@ -137,13 +135,13 @@
reportItem.setItemType( itemType.trim() );
reportItem.setRow( row );
reportItem.setColumn( column );
- reportItem.setExpression( expression.trim() );
- reportItem.setPeriodType( periodType.trim() );
- reportItem.setSheetNo( (sheetNo==null?0:sheetNo) );
+ reportItem.setExpression( expression.trim() );
+ reportItem.setPeriodType( periodType.trim() );
+ reportItem.setSheetNo( (sheetNo == null ? 0 : sheetNo) );
ReportExcelInterface reportExcel = reportService.getReport( reportId.intValue() );
-
- reportExcel.addReportItem(reportItem);
+
+ reportExcel.addReportItem( reportItem );
reportService.updateReport( reportExcel );
=== modified file 'local/vn/dhis-web-vn-report/src/main/webapp/dhis-web-vn-report/importData.vm'
--- local/vn/dhis-web-vn-report/src/main/webapp/dhis-web-vn-report/importData.vm 2009-09-10 10:50:06 +0000
+++ local/vn/dhis-web-vn-report/src/main/webapp/dhis-web-vn-report/importData.vm 2009-09-11 08:08:13 +0000
@@ -4,7 +4,7 @@
<span id="message" style="top:70px;right:5px;position:fixed;width:200px;z-index:100009" onclick="hideById(this.id);"></span>
<!-- <input type="hidden" name="uploadFileName" id="uploadFileName" value="$!fileExcel">-->
-<input type="hidden" name="uploadFileName" id="uploadFileName" value="E:\data\Bieu 1 - TX.xls">
+<input type="hidden" name="uploadFileName" id="uploadFileName" value="E:\data\Bieu 1 - TX.xls" >
#end
<h2>$!encoder.htmlEncode($!organisationUnit.name)</h2>
<table width="50%">
@@ -18,7 +18,8 @@
</tr>
<tr>
<td>$i18n.getString( 'template_excel_file' )</td>
- <td><select type="text" id="reportId" name="reportId" style="min-width:20em; width:100%">
+ <td><select type="text" id="reportId" name="reportId" style="min-width:20em; width:100%" #if(!$!fileExcel) disabled #end onChange="javascript: document.getElementById('lastYear').disabled=false; document.getElementById('nextYear').disabled=false; document.getElementById('periodId').disabled=false; document.getElementById('preview').disabled=false; document.getElementById('import').disabled=false;">
+ <option value="">$i18n.getString('select_one_item')</option>
#foreach($reportExcel in $reportExcels)
<option value="$!reportExcel.id">$!encoder.htmlEncode($!reportExcel.name)</option>
#end
@@ -28,8 +29,9 @@
<tr>
<td>$i18n.getString( 'period' )</td>
<td>
- <input type="button" value="<<" onclick="lastYear();" #if(!$organisationUnit) disabled #end/><input type="button" value=">>" #if(!$organisationUnit) disabled #end onclick="nextYear()"/>
- <select name="periodId" id="periodId" style="min-width:20em; width:100%" type="text">
+ <input type="button" value="<<" id="lastYear" name="lastYear" onclick="lastYear();" disabled />
+ <input type="button" value=">>" id="nextYear" name="nextYear" onclick="nextYear()" disabled />
+ <select name="periodId" id="periodId" style="min-width:20em; width:100%" type="text" disabled >
#foreach($period in $periods)
<option value='$period.id'>$format.formatPeriod( $period )</option>
#end
@@ -43,14 +45,20 @@
</table>
<hr>
-<input type="button" name="preview" id="preview" onClick="javascript: getPreviewImportData();" value="$i18n.getString('preview')">
-<input type="button" name="import" id="import" onClick="javascript: importData();" value="$i18n.getString('import')">
-
-
-<div id='organisationUnitGroup' style="position:fixed;display:block;width:450px;z-index:10001;background-color: white;border: medium solid silver;height:200px;padding:20px;">
- <div id="close" style="position:absolute;top:2px;right:2px;cursor: pointer;color:red;" onclick="javascript:hideById('organisationUnitGroup');deleteDivEffect();">[x]</div> </div>
- <div id="showValue">
-
+<input type="button" name="preview" id="preview" onClick="javascript: getPreviewImportData();" value="$i18n.getString('preview')" disabled>
+<input type="button" name="import" id="import" onClick="javascript: importData();" value="$i18n.getString('import')" disabled>
+<br><br>
+ <div id="showValue" style="display:none; width:100%" >
+ <table id="showReportItemValues" width="100%">
+ <tr>
+ <th width="20px"><input type="checkbox" name="selectAll" id="selectAll" onClick="javascript: selectAll();"/></th>
+ <th>$i18n.getString('report')</th>
+ <th>$i18n.getString('value')</th>
+ </tr>
+ <tbody>
+
+ </tbody>
+ </table>
</div>
</body>
=== modified file 'local/vn/dhis-web-vn-report/src/main/webapp/dhis-web-vn-report/javascript/imports.js'
--- local/vn/dhis-web-vn-report/src/main/webapp/dhis-web-vn-report/javascript/imports.js 2009-09-10 10:56:49 +0000
+++ local/vn/dhis-web-vn-report/src/main/webapp/dhis-web-vn-report/javascript/imports.js 2009-09-11 08:08:13 +0000
@@ -74,6 +74,9 @@
}
}
+// -----------------------------------------------------------------------------
+// Import data
+// -----------------------------------------------------------------------------
function importData(){
var reportId = document.getElementById('reportId').value;
@@ -83,10 +86,30 @@
var request = new Request();
request.setResponseTypeXML( 'xmlObject' );
request.setCallbackSuccess( Completed );
+
+ // URL
url = 'importData.action?reportId='+reportId;
+ // USER choose reportItem
+ var preview = byId('showValue').style.display;
+
+ alert(preview);
+
+ if(preview == 'block'){
+
+ var reportItems = document.getElementsByName('reportItems');
+ alert(reportItems.length);
+ for(var i=0;i<reportItems.length;i++){
+ if(reportItems[i].checked ){
+ url +='&reportItemIds=' + reportItems[i].value;
+ }
+ }
+ }
+
url += '&uploadFileName='+ upload;
url += '&periodId='+ periodId;
+ alert(url);
+
request.send(url);
}
@@ -118,32 +141,52 @@
function getReportItemValuesReceived( xmlObject ){
- var availableDiv = byId('showValue');
- availableDiv.style.display = 'block';
- //var str_values = "<br><br><table border='1' style='width:100% '> <tr><td>Report</td><td>Value</td></tr>";
-
-
- var availableObjectList = xmlObject.getElementsByTagName('reportItemValue');
-
- var myTable = document.getElementById('showReportItemValues');
- var tBody = myTable.getElementsByTagName('tbody')[0];
+ byId('selectAll').checked = false;
+ var availableDiv = byId('showValue');
+ availableDiv.style.display = 'block';
+ //var str_values = "<br><br><table border='1' style='width:100% '> <tr><td>Report</td><td>Value</td></tr>";
+
+ var availableObjectList = xmlObject.getElementsByTagName('reportItemValue');
+
+ var myTable = document.getElementById('showReportItemValues');
+ var tBody = myTable.getElementsByTagName('tbody')[0];
+
+ for(var i = document.getElementById("showReportItemValues").rows.length; i > 1;i--)
+ {
+ document.getElementById("showReportItemValues").deleteRow(i -1);
+ }
+
+ for(var i=0;i<availableObjectList.length;i++){
+
+ // get values
+ var reportItermValue = availableObjectList.item(i);
+ // add new row
var newTR = document.createElement('tr');
- var newTD = document.createElement('td');
- newTD.innerHTML = 'This is a new row';
-
- newTR.appendChild (newTD);
+ // add new column
+ var newTD1 = document.createElement('td');
+ var id = reportItermValue.getElementsByTagName('id')[0].firstChild.nodeValue;
+ newTD1.innerHTML= "<input type='checkbox' name='reportItems' id='reportItems' value='" + id + "'>" ;
+ newTR.appendChild (newTD1);
+ // add new column
+ var newTD2 = document.createElement('td');
+ newTD2.innerHTML = reportItermValue.getElementsByTagName('name')[0].firstChild.nodeValue;
+ newTR.appendChild (newTD2);
+ // add new column
+ var newTD3 = document.createElement('td');
+ newTD3.innerHTML = reportItermValue.getElementsByTagName('value')[0].firstChild.nodeValue;
+ newTR.appendChild (newTD3);
+ // add row into the table
tBody.appendChild(newTR);
-
- for(var i=0;i<availableObjectList.length;i++){
- str_values += "<tr>";
- var reportItermValue = availableObjectList.item(i);
- str_values += "<td>" + reportItermValue.getElementsByTagName('name')[0].firstChild.nodeValue + "</td>";
- str_values += "<td>" + reportItermValue.getElementsByTagName('value')[0].firstChild.nodeValue + "</td>";
- str_values += "</tr>";
- }
-
- str_values += "</table>";
-
-
- availableDiv.innerHTML = str_values;
+ }
}
+
+function selectAll(){
+
+ var select = byId('selectAll').checked;
+
+ var reportItems = document.getElementsByName('reportItems');
+
+ for(var i=0;i<reportItems.length;i++){
+ reportItems[i].checked = select;
+ }
+ }
\ No newline at end of file
=== modified file 'local/vn/dhis-web-vn-report/src/main/webapp/dhis-web-vn-report/responseReportItemValues.vm'
--- local/vn/dhis-web-vn-report/src/main/webapp/dhis-web-vn-report/responseReportItemValues.vm 2009-09-10 10:56:49 +0000
+++ local/vn/dhis-web-vn-report/src/main/webapp/dhis-web-vn-report/responseReportItemValues.vm 2009-09-11 08:08:13 +0000
@@ -2,8 +2,9 @@
<reportItemValues>
#foreach($reportItemValue in $reportItemValues)
<reportItemValue>
+ <id>$encoder.xmlEncode($reportItemValue.reportItem.id)</id>
<name>$encoder.xmlEncode($reportItemValue.reportItem.name)</name>
- <value>$reportItemValue.value )</value>
+ <value>$reportItemValue.value</value>
</reportItemValue>
#end
</reportItemValues>
\ No newline at end of file