dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #04483
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1500: Validate Upload Excel Template - Finished.
------------------------------------------------------------
revno: 1500
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-02-25 16:05:59 +0700
message:
Validate Upload Excel Template - Finished.
added:
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/ValidateUploadExcelTemplate.java
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/ajaxfileupload.js
modified:
dhis-2/dhis-web/dhis-web-excel-reporting/pom.xml
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/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/pom.xml'
--- dhis-2/dhis-web/dhis-web-excel-reporting/pom.xml 2009-12-22 12:07:34 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/pom.xml 2010-02-25 09:05:59 +0000
@@ -10,7 +10,7 @@
</parent>
<artifactId>dhis-web-excel-reporting</artifactId>
- <packaging>war</packaging>
+ <packaging>jar</packaging>
<name>DHIS Web Excel Reporting</name>
<build>
=== 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-02-25 04:22:49 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/ExcelTemplateListAction.java 2010-02-25 09:05:59 +0000
@@ -163,7 +163,7 @@
{
newFileUploadedOrRenamed = new File( newUploadOrRenamePath ).getName();
}
-
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Get the list of files
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=== added file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/ValidateUploadExcelTemplate.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/ValidateUploadExcelTemplate.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/ValidateUploadExcelTemplate.java 2010-02-25 09:05:59 +0000
@@ -0,0 +1,106 @@
+package org.hisp.dhis.reportexcel.filemanager.action;
+
+import java.io.File;
+
+import org.hisp.dhis.i18n.I18n;
+
+import com.opensymphony.xwork2.Action;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/**
+ * @author Tran Thanh Tri
+ * @version $Id
+ */
+public class ValidateUploadExcelTemplate
+ implements Action
+{
+ private static final String TEMPLATE_TYPE = "application/vnd.ms-excel";
+
+ // -------------------------------------------------------------------------
+ // Input & Output
+ // -------------------------------------------------------------------------
+
+ private File upload;// The actual file
+
+ private String uploadContentType; // The content type of the file
+
+// private String uploadFileName; // The uploaded file name
+//
+// private String fileCaption;// The caption of the file entered by user
+
+ private String message;
+
+ private I18n i18n;
+
+ // -------------------------------------------------------------------------
+ // Getter & Setter
+ // -------------------------------------------------------------------------
+
+ public void setUpload( File upload )
+ {
+ this.upload = upload;
+ }
+
+ public void setUploadContentType( String uploadContentType )
+ {
+ this.uploadContentType = uploadContentType;
+ }
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ public void setI18n( I18n i18n )
+ {
+ this.i18n = i18n;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public String execute()
+ throws Exception
+ {
+ if ( upload == null || !upload.exists() )
+ {
+ message = i18n.getString( "upload_file_null" );
+ return ERROR;
+ }
+
+ if ( !TEMPLATE_TYPE.contains( uploadContentType ) )
+ {
+ message = i18n.getString( "file_type_not_supported" );
+ return ERROR;
+ }
+
+ 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-02-24 08:56:35 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/META-INF/dhis/beans.xml 2010-02-25 09:05:59 +0000
@@ -1310,5 +1310,11 @@
<property name="selectionManager"
ref="org.hisp.dhis.reportexcel.state.SelectionManager" />
</bean>
+
+ <bean
+ id="org.hisp.dhis.reportexcel.filemanager.action.ValidateUploadExcelTemplate"
+ class="org.hisp.dhis.reportexcel.filemanager.action.ValidateUploadExcelTemplate"
+ scope="prototype">
+ </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-02-25 04:22:49 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties 2010-02-25 09:05:59 +0000
@@ -202,3 +202,5 @@
update_successful = Updating is success !
cell_exist = Exist one cell same sheet, row and column with this.
download = Download
+upload_file_null = Upload file null
+file_type_not_supported = File type not supported
\ 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-02-25 02:16:24 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/struts.xml 2010-02-25 09:05:59 +0000
@@ -1243,7 +1243,8 @@
<result name="success" type="velocity">/main.vm</result>
<param name="page">/dhis-web-excel-reporting/excelTemplateList.vm</param>
<param name="menu">/dhis-web-excel-reporting/menu.vm</param>
- <param name="javascripts">javascript/commons.js,javascript/exceltemplate.js</param>
+ <param name="javascripts">javascript/commons.js,javascript/exceltemplate.js,
+ javascript/ajaxfileupload.js</param>
<param name="requiredAuthorities">F_EXCEL_REPORT_ADMINISTRATION</param>
</action>
@@ -1274,7 +1275,7 @@
/dhis-web-excel-reporting/responseError.vm</result>
<param name="requiredAuthorities">F_EXCEL_TEMPLATE_MANAGEMENT_RENAME</param>
</action>
-
+
<action name="updateReportExcelByTemplate"
class="org.hisp.dhis.reportexcel.filemanager.action.UpdateReportExcelByTemplateAction">
<result name="success" type="velocity-xml">
@@ -1289,5 +1290,14 @@
<result name="success" type="chain">downloadFile</result>
</action>
+ <action name="validateUploadExcelTemplate"
+ class="org.hisp.dhis.reportexcel.filemanager.action.ValidateUploadExcelTemplate">
+ <interceptor-ref name="fileUploadStack" />
+ <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>
+
</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-02-25 04:22:49 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/excelTemplateList.vm 2010-02-25 09:05:59 +0000
@@ -6,7 +6,8 @@
<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 />
+ <!-- <input name="uploadButton" id="uploadButton" type="submit" value="$i18n.getString( 'upload_file' )" disabled /> -->
+ <input name="uploadButton" id="uploadButton" type="button" value="$i18n.getString( 'upload_file' )" onclick="validateUploadExcelTemplate()" />
</td>
</tr>
</table>
@@ -86,4 +87,5 @@
#end
#end
-</script>
\ No newline at end of file
+</script>
+<span id="message" style="top:100px;right:5px;position:fixed;width:200px;z-index:10002" onclick="hideById(this.id);"></span>
=== added file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/ajaxfileupload.js'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/ajaxfileupload.js 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/ajaxfileupload.js 2010-02-25 09:05:59 +0000
@@ -0,0 +1,201 @@
+
+jQuery.extend({
+
+
+ createUploadIframe: function(id, uri)
+ {
+ //create frame
+ var frameId = 'jUploadFrame' + id;
+
+ if(window.ActiveXObject) {
+ var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');
+ if(typeof uri== 'boolean'){
+ io.src = 'javascript:false';
+ }
+ else if(typeof uri== 'string'){
+ io.src = uri;
+ }
+ }
+ else {
+ var io = document.createElement('iframe');
+ io.id = frameId;
+ io.name = frameId;
+ }
+ io.style.position = 'absolute';
+ io.style.top = '-1000px';
+ io.style.left = '-1000px';
+
+ document.body.appendChild(io);
+
+ return io
+ },
+ createUploadForm: function(id, fileElementId)
+ {
+ //create form
+ var formId = 'jUploadForm' + id;
+ var fileId = 'jUploadFile' + id;
+ var form = $('<form action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');
+ var oldElement = $('#' + fileElementId);
+ var newElement = $(oldElement).clone();
+ $(oldElement).attr('id', fileId);
+ $(oldElement).before(newElement);
+ $(oldElement).appendTo(form);
+ //set attributes
+ $(form).css('position', 'absolute');
+ $(form).css('top', '-1200px');
+ $(form).css('left', '-1200px');
+ $(form).appendTo('body');
+ return form;
+ },
+
+ ajaxFileUpload: function(s) {
+ // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
+ s = jQuery.extend({}, jQuery.ajaxSettings, s);
+ var id = new Date().getTime()
+ var form = jQuery.createUploadForm(id, s.fileElementId);
+ var io = jQuery.createUploadIframe(id, s.secureuri);
+ var frameId = 'jUploadFrame' + id;
+ var formId = 'jUploadForm' + id;
+ // Watch for a new set of requests
+ if ( s.global && ! jQuery.active++ )
+ {
+ jQuery.event.trigger( "ajaxStart" );
+ }
+ var requestDone = false;
+ // Create the request object
+ var xml = {}
+ if ( s.global )
+ jQuery.event.trigger("ajaxSend", [xml, s]);
+ // Wait for a response to come back
+ var uploadCallback = function(isTimeout)
+ {
+ var io = document.getElementById(frameId);
+ try
+ {
+ if(io.contentWindow)
+ {
+ xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
+ xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;
+
+ }else if(io.contentDocument)
+ {
+ xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;
+ xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;
+ }
+ }catch(e)
+ {
+ jQuery.handleError(s, xml, null, e);
+ }
+ if ( xml || isTimeout == "timeout")
+ {
+ requestDone = true;
+ var status;
+ try {
+ status = isTimeout != "timeout" ? "success" : "error";
+ // Make sure that the request was successful or notmodified
+ if ( status != "error" )
+ {
+ // process the data (runs the xml through httpData regardless of callback)
+ var data = jQuery.uploadHttpData( xml, s.dataType );
+ // If a local callback was specified, fire it and pass it the data
+ if ( s.success )
+ s.success( data, status );
+
+ // Fire the global callback
+ if( s.global )
+ jQuery.event.trigger( "ajaxSuccess", [xml, s] );
+ } else
+ jQuery.handleError(s, xml, status);
+ } catch(e)
+ {
+ status = "error";
+ jQuery.handleError(s, xml, status, e);
+ }
+
+ // The request was completed
+ if( s.global )
+ jQuery.event.trigger( "ajaxComplete", [xml, s] );
+
+ // Handle the global AJAX counter
+ if ( s.global && ! --jQuery.active )
+ jQuery.event.trigger( "ajaxStop" );
+
+ // Process result
+ if ( s.complete )
+ s.complete(xml, status);
+
+ jQuery(io).unbind()
+
+ setTimeout(function()
+ { try
+ {
+ $(io).remove();
+ $(form).remove();
+
+ } catch(e)
+ {
+ jQuery.handleError(s, xml, null, e);
+ }
+
+ }, 100)
+
+ xml = null
+
+ }
+ }
+ // Timeout checker
+ if ( s.timeout > 0 )
+ {
+ setTimeout(function(){
+ // Check to see if the request is still happening
+ if( !requestDone ) uploadCallback( "timeout" );
+ }, s.timeout);
+ }
+ try
+ {
+ // var io = $('#' + frameId);
+ var form = $('#' + formId);
+ $(form).attr('action', s.url);
+ $(form).attr('method', 'POST');
+ $(form).attr('target', frameId);
+ if(form.encoding)
+ {
+ form.encoding = 'multipart/form-data';
+ }
+ else
+ {
+ form.enctype = 'multipart/form-data';
+ }
+ $(form).submit();
+
+ } catch(e)
+ {
+ jQuery.handleError(s, xml, null, e);
+ }
+ if(window.attachEvent){
+ document.getElementById(frameId).attachEvent('onload', uploadCallback);
+ }
+ else{
+ document.getElementById(frameId).addEventListener('load', uploadCallback, false);
+ }
+ return {abort: function () {}};
+
+ },
+
+ uploadHttpData: function( r, type ) {
+ var data = !type;
+ data = type == "xml" || data ? r.responseXML : r.responseText;
+ // If the type is "script", eval it in global context
+ if ( type == "script" )
+ jQuery.globalEval( data );
+ // Get the JavaScript object, if JSON is used.
+ if ( type == "json" )
+ eval( "data = " + data );
+ // evaluate scripts within html
+ if ( type == "html" )
+ jQuery("<div>").html(data).evalScripts();
+ //alert($('param', data).each(function(){alert($(this).attr('value'));}));
+ return data;
+ }
+})
+
=== 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-02-25 04:22:49 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/exceltemplate.js 2010-02-25 09:05:59 +0000
@@ -216,3 +216,34 @@
window.location.href="listAllExcelTemplates.action?mode=" + mode + "&message=" + message;
}
}
+
+//----------------------------------------------------------
+// Validate Upload Excel Template
+//----------------------------------------------------------
+
+function validateUploadExcelTemplate(){
+
+ $.ajaxFileUpload
+ (
+ {
+ url:'validateUploadExcelTemplate.action',
+ secureuri:false,
+ fileElementId:'upload',
+ dataType: 'xml',
+ success: function (data, status)
+ {
+ data = data.getElementsByTagName('message')[0];
+ var type = data.getAttribute("type");
+ if(type=='error'){
+ setMessage(data.firstChild.nodeValue);
+ }else{
+ document.forms['uploadForm'].submit();
+ }
+ },
+ error: function (data, status, e)
+ {
+
+ }
+ }
+ );
+ }
\ No newline at end of file