← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1368: Function Excel Management - Working in process...

 

------------------------------------------------------------
revno: 1368
committer: hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2010-01-29 15:21:40 +0700
message:
  Function Excel Management - Working in process...
modified:
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/DeleteExcelTemplateAction.java
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/ExcelTemplateListAction.java
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml
  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_vi_VN.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/excelTemplateList.vm
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/exceltemplate.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/filemanager/action/DeleteExcelTemplateAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/DeleteExcelTemplateAction.java	2010-01-27 05:33:50 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/DeleteExcelTemplateAction.java	2010-01-29 08:21:40 +0000
@@ -11,6 +11,11 @@
 
 import com.opensymphony.xwork2.Action;
 
+/**
+ * @author Chau Thu Tran
+ * @version $Id
+ * @since 2010-01-27
+ */
 public class DeleteExcelTemplateAction
     implements Action
 {
@@ -19,7 +24,7 @@
     // -------------------------------------------
 
     private SystemSettingManager systemSettingManager;
-    
+
     private ReportExcelService reportService;
 
     // -------------------------------------------
@@ -27,13 +32,13 @@
     // -------------------------------------------
 
     private String fileName;
-    
+
     // -------------------------------------------
     // Output
     // -------------------------------------------
 
     private String message;
-    
+
     private I18n i18n;
 
     // -------------------------------------------
@@ -64,7 +69,7 @@
     {
         this.fileName = fileName;
     }
-    
+
     // -------------------------------------------
     // Action implementation
     // -------------------------------------------
@@ -74,24 +79,30 @@
         throws Exception
     {
         message = "";
+
+        Collection<ReportExcel> reports = reportService.getALLReportExcel();
         
-        Collection<ReportExcel> reports =  reportService.getALLReportExcel();
-        for(ReportExcel report : reports){
+        for ( ReportExcel report : reports )
+        {
             String name = report.getExcelTemplateFile();
-            if(name.equals( fileName )){
+            
+            if ( name.equals( fileName ) )
+            {
                 message += " - " + report.getName() + "<br>";
             }
         }
-        
-        if(message.length()>0){
+
+        if ( message.length() > 0 )
+        {
             message = i18n.getString( "report_user_template" ) + "<br>" + message;
+            
             return ERROR;
         }
-        
+
         String templateDirectory = (String) systemSettingManager
             .getSystemSetting( SystemSettingManager.KEY_REPORT_TEMPLATE_DIRECTORY );
-
-        FileUtils.delete(  templateDirectory + File.separator + fileName );
+        
+        FileUtils.delete( templateDirectory + File.separator + fileName );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/ExcelTemplateListAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/ExcelTemplateListAction.java	2010-01-26 09:04:04 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/ExcelTemplateListAction.java	2010-01-29 08:21:40 +0000
@@ -4,13 +4,21 @@
 import java.util.ArrayList;
 import java.util.Collection;
 
+import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.options.SystemSettingManager;
+import org.hisp.dhis.reportexcel.action.ActionSupport;
+import org.hisp.dhis.reportexcel.state.SelectionManager;
 import org.hisp.dhis.reportexcel.utils.FileUtils;
 
-import com.opensymphony.xwork2.Action;
+/**
+ * @author Chau Thu Tran
+ * @author Dang Duy Hieu
+ * @version $Id
+ * @since 2010-01-27
+ */
 
 public class ExcelTemplateListAction
-    implements Action
+    extends ActionSupport
 {
     // -------------------------------------------
     // Dependency
@@ -18,6 +26,18 @@
 
     private SystemSettingManager systemSettingManager;
 
+    public void setSystemSettingManager( SystemSettingManager systemSettingManager )
+    {
+        this.systemSettingManager = systemSettingManager;
+    }
+
+    private SelectionManager selectionManager;
+
+    public void setSelectionManager( SelectionManager selectionManager )
+    {
+        this.selectionManager = selectionManager;
+    }
+
     // -------------------------------------------
     // Output
     // -------------------------------------------
@@ -27,14 +47,26 @@
     // Getter && Setter
     // -------------------------------------------
 
+    private String newFileUploaded;
+
+    public String getNewFileUploaded()
+    {
+        return newFileUploaded;
+    }
+
     public Collection<File> getTemplateFiles()
     {
         return templateFiles;
     }
 
-    public void setSystemSettingManager( SystemSettingManager systemSettingManager )
-    {
-        this.systemSettingManager = systemSettingManager;
+    public String getMessage()
+    {
+        return message;
+    }
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
     }
 
     // -------------------------------------------
@@ -45,12 +77,28 @@
     public String execute()
         throws Exception
     {
+        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        // Get the path of newly uploaded file
+        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        
+        String newUploadedPath = selectionManager.getUploadFilePath();
+        
+        if ( !newUploadedPath.isEmpty() && (newUploadedPath != null) )
+        {
+            newFileUploaded = new File( newUploadedPath ).getName();
+        }
+
+        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+        // Get the list of files
+        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
         String templateDirectory = (String) systemSettingManager
             .getSystemSetting( SystemSettingManager.KEY_REPORT_TEMPLATE_DIRECTORY );
-        
+
         templateFiles = FileUtils.getListFile( new File( templateDirectory ) );
 
         return SUCCESS;
     }
 
+
 }

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml	2010-01-26 09:04:04 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml	2010-01-29 08:21:40 +0000
@@ -1250,6 +1250,7 @@
 		class="org.hisp.dhis.reportexcel.filemanager.action.ExcelTemplateListAction"
 		scope="prototype">
 		<property name="systemSettingManager" ref="org.hisp.dhis.options.SystemSettingManager" />
+		<property name="selectionManager" ref="org.hisp.dhis.reportexcel.state.SelectionManager" />
 	</bean>
 
 	<bean
@@ -1259,5 +1260,13 @@
 		<property name="systemSettingManager" ref="org.hisp.dhis.options.SystemSettingManager" />
 		<property name="reportService" ref="org.hisp.dhis.reportexcel.ReportExcelService" />
 	</bean>
-
+	
+	<bean
+		id="org.hisp.dhis.reportexcel.filemanager.action.UploadExcelTemplateAction"
+		class="org.hisp.dhis.reportexcel.filemanager.action.UploadExcelTemplateAction"
+		scope="prototype">
+		<property name="systemSettingManager" ref="org.hisp.dhis.options.SystemSettingManager" />
+		<property name="selectionManager" ref="org.hisp.dhis.reportexcel.state.SelectionManager" />
+	</bean>
+	
 </beans>

=== 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	2010-01-26 09:04:04 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties	2010-01-29 08:21:40 +0000
@@ -182,3 +182,8 @@
 levels						= Level
 no_item						= Don't have any items chosen
 excel_template_management   = Excel Template Management
+file_exists                 = File is existing
+confirm_override            = Do you sure want to override this file? 
+upload_successful           = Uploading is successful!
+override_successful         = Overriding is successful!
+cannot_write_file_being_used = Unable to write to this file as being used by another program
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties	2010-01-26 09:04:04 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties	2010-01-29 08:21:40 +0000
@@ -182,4 +182,9 @@
 input_sheet_no				= Ch\u01b0a nh\u1eadp sheet
 choose_excel_group          = Ch\u01b0a ch\u1ecdn nh\u00f3m
 choose_report               = Ch\u01b0a ch\u1ecdn b\u00e1o c\u00e1o
-excel_template_management   = Qu\u1ea3n l\u00fd c\u00e1c t\u1eadp tin excel m\u1eabu
\ No newline at end of file
+excel_template_management   = Qu\u1ea3n l\u00fd c\u00e1c t\u1eadp tin excel m\u1eabu
+confirm_override            = B\u1ea1n c\u00f3 mu\u1ed1n ghi \u0111\u00e8 l\u00ean t\u1eadp tin \u0111\u00e3 c\u00f3?
+file_exists                 = T\u1eadp tin excel n\u00e0y \u0111ang t\u1ed3n t\u1ea1i!
+upload_successful           = T\u1ea3i t\u1eadp tin th\u00e0nh c\u00f4ng!
+override_successful         = T\u1eadp tin n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c ghi \u0111\u00e8!
+cannot_write_file_being_used = Kh\u00f4ng th\u1ec3 ghi l\u00ean t\u1eadp tin n\u00e0y v\u00ec \u0111ang \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng b\u1edfi m\u1ed9t ch\u01b0\u01a1ng tr\u00ecnh kh\u00e1c
\ 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	2010-01-28 15:23:28 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml	2010-01-29 08:21:40 +0000
@@ -1232,6 +1232,13 @@
 			<param name="requiredAuthorities">F_EXCEL_TEMPLATE_MANAGEMENT_DELETE</param>
 		</action>
 		
+		<action name="uploadExcelTemplate"
+			class="org.hisp.dhis.reportexcel.filemanager.action.UploadExcelTemplateAction">
+			<result name="success" type="chain">
+				listAllExcelTemplates</result>
+			<param name="requiredAuthorities">F_EXCEL_TEMPLATE_MAMAGEMENT_DELETE</param>
+			<interceptor-ref name="fileUploadStack" />
+		</action>
 		
 	</package>
 </struts>

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/excelTemplateList.vm'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/excelTemplateList.vm	2010-01-26 09:04:04 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/excelTemplateList.vm	2010-01-29 08:21:40 +0000
@@ -1,12 +1,27 @@
 <h2>$i18n.getString('excel_template_management')</h2>
+
+<table>
+<form name="uploadForm" id="uploadForm" action="uploadExcelTemplate.action" onsubmit="return validateUploadExcelTemplate(document.getElementById('upload').value, 1);" method="post" enctype="multipart/form-data">
+	<tr>
+		<td width="18%" style=" width:25% ">$i18n.getString( 'select_excel_file' ):</td>
+		<td width="82%">
+			<input type="file" id="upload" name="upload" onChange="enable('uploadButton');" />
+			<input name="uploadButton" id="uploadButton" type="submit" value="$i18n.getString( 'upload_file' )" disabled />    
+		</td>   
+	</tr>
+</form>
+</table>
 <table width=100%>
 	<tr>
 		<td>
 			$i18n.getString( "filter_by_name" ): <input type="text" onkeyup="filterValues( this.value , 1)" style="width:300px"/>
 		</td>
+		<td>
+
+		</td>
 		<td align=right>
 			<input type="button" onclick="mode='add'; openAddTemplateFile()" value="$i18n.getString('add')" style="width:100px"/>
-			<input type="button" value="$i18n.getString( "cancel" )" onclick="window.location='administration.action'" style="width:100px">
+			<input type="button" value="$i18n.getString( "cancel" )" onclick="window.location='administration.action'" style="width:100px"/>
 		</td>
 	</tr>
 </table>
@@ -14,7 +29,7 @@
 <table width="100%">
 	<tr>
 		<th>$i18n.getString('name')</th>
-		<th width="110px">$i18n.getString('operations')</th>		
+		<th width="110px">$i18n.getString('operations')</th>
 	</tr>
 	<tbody id="list">
 	#set( $mark = false )
@@ -22,12 +37,11 @@
 		<tr #alternate( $mark )>
 			<td>$encoder.htmlEncode( $templateFile.name )</td>
 			<td align="left">
-				<a href="openExcelTemplateAssociations.action?templateFileId=$templateFile.id" title="$i18n.getString( 'associations' )"><img src="../images/assign.png" alt="$i18n.getString( 'associations' )"></a>
-				<a href="javascript:deleteExcelTemplate('$templateFile.id');" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"></a>
-				<a href="javascript:mode = 'edit'; openUpdateExcelTemplate( '$templateFile.id' );" title="$i18n.getString( 'edit' )"><img src="../images/edit.png" alt="$i18n.getString( 'edit' )"></a>
+				<a href="openExcelTemplateAssociations.action?templateFileId=$templateFile.name" title="$i18n.getString( 'associations' )"><img src="../images/assign.png" alt="$i18n.getString( 'associations' )"></a>
+				<a href="javascript:deleteExcelTemplate('$templateFile.name');" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"></a>
+				<a href="javascript:mode = 'edit'; openUpdateExcelItemGroup( '$templateFile.name' );" title="$i18n.getString( 'edit' )"><img src="../images/edit.png" alt="$i18n.getString( 'edit' )"></a>
 			</td>
 		</tr>
-		
 		#if( $mark )
 			#set( $mark = false )
 		#else
@@ -37,12 +51,6 @@
 	</tbody>
 </table>
 
-<script language="javascript">
-	var i18n_confirm_delete = '$encoder.jsEscape($i18n.getString( 'confirm_delete' ) , "'")';
-</script>
-
-<span id="message" style="top:100px;right:5px;position:fixed;width:200px;z-index:10002" onclick="javascript:hideById(this.id);"></span>
-
 <div id="divExcelTemplateList" style="position:fixed;display:none;width:609px;z-index:11;background-color: white;border: medium solid silver;height:209px;padding:20px">
 	<div id="close" style="position:absolute;top:2px;right:2px;cursor: pointer;color:red;" onclick="hideById('divExcelTemplateList');deleteDivEffect();">[x]</div>
 	<input type="hidden" value="" id="id"/>
@@ -57,16 +65,26 @@
 		</tr>
 	</table>
 	<p align="center">
-	<input type="button" value="$i18n.getString('ok')" id="excelTemplateList" onClick="validateExcelItemGroup()"/>
+	<input type="button" value="$i18n.getString('ok')" id="excelTemplateButtonAdd" onClick="validateExcelTemplate()"/>
 	<input type="button" value="$i18n.getString('cancel')" onclick="hideById('divExcelTemplateList');deleteDivEffect();"/>
 	</p>
 </div>
+
+<span id="message" style="top:100px;right:5px;position:fixed;width:300px;z-index:10002" onclick="javascript:hideById(this.id);"></span>
+
 <script language="javascript">
+
 	var mode = 'add';
 	var i18n_confirm_delete = '$encoder.jsEscape($i18n.getString( 'confirm_delete' ) , "'")';
-
-</script>
-
-<span id="message" style="top:100px;right:5px;position:fixed;width:200px;z-index:10002" onclick="javascript:hideById(this.id);"></span>
-
-
+	var i18n_confirm_override = '$encoder.jsEscape($i18n.getString( 'confirm_override' ) , "'")';
+
+	#if ( $message )
+	
+		$(document).ready( function() {
+		
+			setMessage( '<b>' + '$newFileUploaded' + '</b><br/>' + '$i18n.getString( "$message" )' );
+		});
+		
+	#end
+
+</script>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/exceltemplate.js'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/exceltemplate.js	2010-01-26 08:43:26 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/exceltemplate.js	2010-01-29 08:21:40 +0000
@@ -6,7 +6,9 @@
 *	Delete Excel Template
 */
 function deleteExcelTemplate( fileName ) {
+
 	if ( window.confirm(i18n_confirm_delete) ) {
+	
 		var request = new Request();
 		request.setResponseTypeXML( 'xmlObject' );
 		request.setCallbackSuccess( deleteExcelTemplateReceived );
@@ -20,10 +22,32 @@
 	
 	if ( type == 'error' )
 	{
-		setMessage(xmlObject.firstChild.nodeValue);
+		setMessage( xmlObject.firstChild.nodeValue );
 	}
 	else
 	{
-		window.location.href = 'excelTemplateList.action';
+		window.location.href = 'listAllExcelTemplates.action';
 	}
+}
+
+function validateUploadExcelTemplate ( fileName, columnIndex ) {
+
+    var list = byId( 'list' );
+    
+    var rows = list.getElementsByTagName( 'tr' );
+    
+    for ( var i = 0; i < rows.length; i++ )
+    {
+        var cell = rows[i].getElementsByTagName( 'td' )[columnIndex-1];
+        var value = cell.firstChild.nodeValue;
+		
+        if ( value.toLowerCase().indexOf( fileName.toLowerCase() ) != -1 )
+        {
+            // file is existsing
+			return window.confirm( i18n_confirm_override );
+        }
+    }
+      
+	// normally upload
+	return true;
 }
\ No newline at end of file