dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #02264
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 765: fix bug : Import Excel file
------------------------------------------------------------
revno: 765
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2009-09-25 15:20:25 +0700
message:
fix bug : Import Excel file
modified:
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/importData.vm
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.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/webapp/dhis-web-excel-reporting/importData.vm'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/importData.vm 2009-09-21 07:58:41 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/importData.vm 2009-09-25 08:20:25 +0000
@@ -2,9 +2,8 @@
#if($!fileExcel)
<div id="messageUpload"> $!message </div>
<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="$!fileExcel">
+<!-- <input type="hidden" name="uploadFileName" id="uploadFileName">-->
#end
<h2>$!encoder.htmlEncode($!organisationUnit.name)</h2>
<table width="50%">
@@ -45,7 +44,7 @@
</table>
<hr>
-<input type="button" name="preview" id="preview" onClick="javascript: getPreviewImportData();" value="$i18n.getString('preview')" disabled>
+<input type="button" name="preview" id="preview" onClick="javascript: getPreviewImportData('$!fileExcel.getName()');" 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%" >
=== 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-09-25 06:10:21 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.js 2009-09-25 08:20:25 +0000
@@ -70,4 +70,114 @@
var name = node.getElementsByTagName('name')[0].firstChild.nodeValue;
addOption('period', name, id);
}
-}
\ No newline at end of file
+}
+
+// -----------------------------------------------------------------------------
+// Import data
+// -----------------------------------------------------------------------------
+function importData(){
+
+ var reportId = document.getElementById('reportId').value;
+ var upload = document.getElementById('uploadFileName').value;
+ var periodId = document.getElementById('period').value;
+
+ 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;
+
+ if(preview == 'block'){
+
+ var reportItems = document.getElementsByName('reportItems');
+ for(var i=0;i<reportItems.length;i++){
+ if(reportItems[i].checked ){
+ url +='&reportItemIds=' + reportItems[i].value;
+ }
+ }
+ }
+
+ url += '&uploadFileName='+ upload;
+ url += '&periodId='+ periodId;
+ request.send(url);
+}
+
+function Completed( xmlObject ){
+
+ if(document.getElementById('message') != null){
+ document.getElementById('message').style.display = 'block';
+ document.getElementById('message').innerHTML = xmlObject.firstChild.nodeValue;
+ }
+}
+
+function getPreviewImportData(fileExcel){
+
+ var request = new Request();
+
+ request.setResponseTypeXML( 'xmlObject' );
+
+ request.setCallbackSuccess( getReportItemValuesReceived );
+
+ var reportId = byId("reportId").value;
+
+ request.send( "previewData.action?reportId=" + reportId +"&uploadFileName=" + fileExcel);
+}
+
+function getReportItemValuesReceived( xmlObject ){
+
+ byId('selectAll').checked = false;
+ var availableDiv = byId('showValue');
+ availableDiv.style.display = 'block';
+
+ 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');
+ // create new column
+ var newTD2 = document.createElement('td');
+ newTD2.innerHTML = reportItermValue.getElementsByTagName('name')[0].firstChild.nodeValue;
+ // create new column
+ var newTD3 = document.createElement('td');
+ var value = reportItermValue.getElementsByTagName('value')[0].firstChild.nodeValue;
+ newTD3.innerHTML = value;
+ // create new column
+ var newTD1 = document.createElement('td');
+ var id = reportItermValue.getElementsByTagName('id')[0].firstChild.nodeValue;
+ if(value!=0){
+ newTD1.innerHTML= "<input type='checkbox' name='reportItems' id='reportItems' value='" + id + "'>" ;
+ }
+
+ newTR.appendChild (newTD1);
+ newTR.appendChild (newTD2);
+ newTR.appendChild (newTD3);
+ // add row into the table
+ tBody.appendChild(newTR);
+ }
+}
+
+function selectAll(){
+
+ var select = byId('selectAll').checked;
+
+ var reportItems = document.getElementsByName('reportItems');
+
+ for(var i=0;i<reportItems.length;i++){
+ reportItems[i].checked = select;
+ }
+ }
+