------------------------------------------------------------ revno: 6244 committer: Tran Chau <tran.hispviet...@gmail.com> branch nick: dhis2 timestamp: Mon 2012-03-12 14:03:27 +0700 message: (patient) Add jQuery validation for comparing start date and end date in report; and remove this validation class. removed: dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/ValidateReportParametersAction.java added: dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/ValidateTabularReportAction.java modified: dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/report.js dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/tabularReport.js dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportSelect.vm dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/tabularReportSelect.vm dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/messages.vm dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.validate.ext.js dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties
-- 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-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java 2012-03-10 05:06:47 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/GenerateTabularReportAction.java 2012-03-12 07:03:27 +0000 @@ -211,7 +211,7 @@ // --------------------------------------------------------------------- OrganisationUnit selectedOrgunit = selectedStateManager.getSelectedOrganisationUnit(); - + Set<Integer> orgunitIds = new HashSet<Integer>(); if ( facilityLB.equals( "selected" ) ) @@ -231,7 +231,7 @@ orgunitIds.remove( selectedOrgunit.getId() ); } } - + // --------------------------------------------------------------------- // Get program-stage, start-date, end-date // --------------------------------------------------------------------- === removed file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/ValidateReportParametersAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/ValidateReportParametersAction.java 2011-10-04 02:39:49 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/ValidateReportParametersAction.java 1970-01-01 00:00:00 +0000 @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2004-2009, 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. - */ - -package org.hisp.dhis.caseentry.action.report; - -import org.hisp.dhis.i18n.I18n; -import org.hisp.dhis.i18n.I18nFormat; - -import com.opensymphony.xwork2.Action; - -/** - * @author Abyot Asalefew Gizaw - * @version $Id$ - */ -public class ValidateReportParametersAction - implements Action -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private I18nFormat format; - - public void setFormat( I18nFormat format ) - { - this.format = format; - } - - // ------------------------------------------------------------------------- - // Input - // ------------------------------------------------------------------------- - - private String startDate; - - public void setStartDate( String startDate ) - { - this.startDate = startDate; - } - - private String endDate; - - public void setEndDate( String endDate ) - { - this.endDate = endDate; - } - - // ------------------------------------------------------------------------- - // Output - // ------------------------------------------------------------------------- - - private String message; - - public String getMessage() - { - return message; - } - - private I18n i18n; - - public void setI18n( I18n i18n ) - { - this.i18n = i18n; - } - - // ------------------------------------------------------------------------- - // Action implementation - // ------------------------------------------------------------------------- - - public String execute() - throws Exception - { - if ( format.parseDate( endDate ).before( format.parseDate( startDate ) ) ) - { - message = i18n.getString( "please_choose_a_valid_start_end_date" ); - - return INPUT; - } - - // --------------------------------------------------------------------- - // Validation success - // --------------------------------------------------------------------- - - message = i18n.getString( "everything_is_ok" ); - - return SUCCESS; - } -} === added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/ValidateTabularReportAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/ValidateTabularReportAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/ValidateTabularReportAction.java 2012-03-12 07:03:27 +0000 @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2004-2012, 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. + */ + +package org.hisp.dhis.caseentry.action.report; + +import org.hisp.dhis.caseentry.state.SelectedStateManager; +import org.hisp.dhis.i18n.I18n; +import org.hisp.dhis.organisationunit.OrganisationUnit; + +import com.opensymphony.xwork2.Action; + +/** + * @author Chau Thu Tran + * + * @version $ValidationTabularReportAction.java Mar 12, 2012 12:36:48 PM$ + */ +public class ValidateTabularReportAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private SelectedStateManager selectedStateManager; + + public void setSelectedStateManager( SelectedStateManager selectedStateManager ) + { + this.selectedStateManager = selectedStateManager; + } + + private I18n i18n; + + public void setI18n( I18n i18n ) + { + this.i18n = i18n; + } + + // ------------------------------------------------------------------------- + // Input && Output + // ------------------------------------------------------------------------- + + private String facilityLB; + + public void setFacilityLB( String facilityLB ) + { + this.facilityLB = facilityLB; + } + + private String message; + + public String getMessage() + { + return message; + } + + // ------------------------------------------------------------------------- + // Implementation Action + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + OrganisationUnit selectedOrgunit = selectedStateManager.getSelectedOrganisationUnit(); + + if ( selectedOrgunit == null ) + { + message = i18n.getString( "please_specify_an_orgunit" ); + } + + if ( selectedOrgunit != null && facilityLB.equals( "childrenOnly" ) && !selectedOrgunit.hasChild() ) + { + message = i18n.getString( "selected_orgunit_no_have_any_child" ); + } + + return SUCCESS; + } +} === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2012-03-10 05:06:47 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2012-03-12 07:03:27 +0000 @@ -226,12 +226,6 @@ ref="org.hisp.dhis.program.ProgramService" /> </bean> - <bean - id="org.hisp.dhis.caseentry.action.report.ValidateReportParametersAction" - class="org.hisp.dhis.caseentry.action.report.ValidateReportParametersAction" - scope="prototype"> - </bean> - <bean id="org.hisp.dhis.caseentry.action.report.GenerateReportAction" class="org.hisp.dhis.caseentry.action.report.GenerateReportAction" scope="prototype"> @@ -275,6 +269,12 @@ ref="org.hisp.dhis.program.ProgramStageService" /> </bean> + <bean id="org.hisp.dhis.caseentry.action.report.ValidateTabularReportAction" + class="org.hisp.dhis.caseentry.action.report.ValidateTabularReportAction" scope="prototype"> + <property name="selectedStateManager" + ref="org.hisp.dhis.caseentry.state.SelectedStateManager" /> + </bean> + <bean id="org.hisp.dhis.caseentry.action.report.GenerateTabularReportAction" class="org.hisp.dhis.caseentry.action.report.GenerateTabularReportAction" scope="prototype"> <property name="programStageService" === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties 2012-03-12 04:19:40 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties 2012-03-12 07:03:27 +0000 @@ -277,4 +277,5 @@ report_unit = Report unit order_by_orgunit = Order by organisation unit order_by_report_date = Order by report date -clear_filter = Clear filter \ No newline at end of file +clear_filter = Clear filter +selected_orgunit_no_have_any_child = Selected organisation unit no have any child \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2012-03-09 07:59:38 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2012-03-12 07:03:27 +0000 @@ -231,17 +231,6 @@ <param name="stylesheets">../dhis-web-caseentry/style/report.css</param> </action> - <action name="validateReportParameters" - class="org.hisp.dhis.caseentry.action.report.ValidateReportParametersAction"> - <result name="success" type="velocity-xml"> - /dhis-web-caseentry/responseSuccess.vm</result> - <result name="error" type="velocity-xml"> - /dhis-web-caseentry/responseError.vm</result> - <result name="input" type="velocity-xml"> - /dhis-web-caseentry/responseInput.vm</result> - <param name="onExceptionReturn">plainTextError</param> - </action> - <action name="generateReport" class="org.hisp.dhis.caseentry.action.report.GenerateReportAction"> <result name="success" type="velocity">/content.vm</result> @@ -275,6 +264,14 @@ <result name="success" type="velocity-json">/dhis-web-caseentry/responseDataElements.vm</result> </action> + <action name="validateTabularReport" + class="org.hisp.dhis.caseentry.action.report.ValidateTabularReportAction"> + <result name="success" type="velocity-json"> + /dhis-web-commons/ajax/jsonResponseSuccess.vm</result> + <result name="input" type="velocity-json"> + /dhis-web-commons/ajax/jsonResponseInput.vm</result> + </action> + <action name="generateTabularReport" class="org.hisp.dhis.caseentry.action.report.GenerateTabularReportAction"> <result name="success" type="velocity">/content.vm</result> === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/report.js' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/report.js 2012-03-05 07:32:05 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/report.js 2012-03-12 07:03:27 +0000 @@ -37,36 +37,6 @@ selection.setListenerFunction( organisationUnitSelected ); -function validateAndGenerateReport() -{ - $.get( 'validateReportParameters.action', - { - startDate :getFieldValue( 'startDate' ) , - endDate: getFieldValue( 'endDate' ) - },reportValidationCompleted ); -} - -function reportValidationCompleted( messageElement ) -{ - messageElement = messageElement.getElementsByTagName( 'message' )[0]; - var type = messageElement.getAttribute( 'type' ); - var message = messageElement.firstChild.nodeValue; - hideById( 'contentDiv' ); - - if ( type == 'success' ) - { - loadGeneratedReport(); - } - else if ( type == 'error' ) - { - window.alert( i18n_report_generation_failed + ':' + '\n' + message ); - } - else if ( type == 'input' ) - { - setMessage( message ); - } -} - function loadGeneratedReport() { showLoader(); === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/tabularReport.js' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/tabularReport.js 2012-03-12 04:19:40 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/tabularReport.js 2012-03-12 07:03:27 +0000 @@ -161,6 +161,22 @@ }); } +function validateTabularReport() +{ + $.post( 'validateTabularReport.action',{} + , function( json ) + { + if( json.response == 'success' ) + { + loadGeneratedReport(); + } + else + { + setMessage( json.messsage ); + } + } ); +} + function loadGeneratedReport() { hideCriteria(); === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportSelect.vm' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportSelect.vm 2012-03-10 05:06:47 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/reportSelect.vm 2012-03-12 07:03:27 +0000 @@ -1,7 +1,7 @@ <script> jQuery(document).ready( function(){ validation( 'reportForm', function(form){ - validateAndGenerateReport(); + loadGeneratedReport(); }); }); </script> @@ -9,7 +9,7 @@ <h3>$i18n.getString( "program_summary_report" ) #openHelp('program_summary_report')</h3> <form id="reportForm" name="reportForm" method="post"> -<div class="inputCriteria" style="width:530px;height:160px;margin-bottom:20px;"> +<div class="inputCriteria" style="width:540px;height:180px;margin-bottom:20px;"> <table> <tr> @@ -21,7 +21,7 @@ <td><label for="programId">$i18n.getString( "program" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td> <td> <select id="programId" name="programId" #if($!programs) #else disabled #end class="{validate:{required:true}}" > - <option>[$i18n.getString('please_select_a_program')]</option> + <option value=''>[$i18n.getString('please_select_a_program')]</option> #foreach( $program in $programs ) <option value='$program.id'>$program.name</option> #end @@ -42,7 +42,7 @@ <tr> <td><label>$i18n.getString( "end_date" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td> <td> - <input type="text" id="endDate" name="endDate" class="{validate:{required:true}}" /> + <input type="text" id="endDate" name="endDate" class="{validate:{required:true, greaterOrEqualsDate:'#startDate' }}" /> <script type="text/javascript"> datePicker('endDate'); </script> === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/tabularReportSelect.vm' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/tabularReportSelect.vm 2012-03-12 04:19:40 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/tabularReportSelect.vm 2012-03-12 07:03:27 +0000 @@ -49,7 +49,7 @@ <tr> <td><label>$i18n.getString( "end_date" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td> <td colspan='2'> - <input type="text" id="endDate" name="endDate" class="{validate:{required:true}}" /> + <input type="text" id="endDate" name="endDate" class="{validate:{required:true, greaterOrEqualsDate:'#startDate' }}" /> <script type="text/javascript"> datePicker('endDate'); </script> === modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/messages.vm' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/messages.vm 2011-12-30 07:17:59 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/messages.vm 2012-03-12 07:03:27 +0000 @@ -48,6 +48,7 @@ ,letterswithbasicspecialchars: '$encoder.jsEscape($i18n.getString( 'please_letters_numbers_spaces_or_some_special_chars_only' ) , "'")' ,lessthanequal: validatorFormat('$encoder.jsEscape($i18n.getString( 'please_enter_a_value_less_than_or_equal_to' ) , "'")') ,greaterthanequal: validatorFormat( '$encoder.jsEscape($i18n.getString( 'please_enter_a_value_greater_than_or_equal_to' ) , "'")' ) + ,greaterOrEqualsDate: validatorFormat( '$encoder.jsEscape($i18n.getString( 'please_enter_a_value_greater_than_or_equal_to_start_date' ) , "'")' ) ,unique: '$encoder.jsEscape($i18n.getString( 'please_do_not_enter_same_values' ) , "'")' ,letterswithbasicpunc: '$encoder.jsEscape($i18n.getString( 'letters_or_punctuation_only_please' ) , "'")' ,maxWords : validatorFormat('$encoder.jsEscape($i18n.getString( 'please_enter_n_words_or_less' ) , "'")') === modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.validate.ext.js' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.validate.ext.js 2011-12-30 07:17:59 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.validate.ext.js 2012-03-12 07:03:27 +0000 @@ -165,7 +165,18 @@ return true; }, ""); + +jQuery.validator.addMethod("greaterOrEqualsDate",function(value, element, params) { + + if ($(params).val()){ + var closedDate = new Date(value); + var openDate= new Date($(params).val()); + return closedDate >= openDate; + } + return true; + }, ""); + jQuery.validator.addMethod("alphanumeric", function(value, element) { return this.optional(element) || /^[\w\s]+$/i.test(value); }, "Letters, numbers, spaces or underscores only please"); === modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties' --- dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties 2012-03-09 13:21:38 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties 2012-03-12 07:03:27 +0000 @@ -362,6 +362,7 @@ please_enter_a_value_between_a_and_b=Please enter a value between {0} and {1}. please_enter_a_value_less_than_or_equal_to_n=Please enter a value less than or equal to {0}. please_enter_a_value_greater_than_or_equal_to_n=Please enter a value greater than or equal to {0}. +please_enter_a_value_greater_than_or_equal_to_start_date=Please enter a value greater than or equal to start date. please_enter_a_different_value_to_above=Please enter a different value to above. digits_decimal_only_please=Please enter digits only. Three digits before decimal point and two after the decimal point are allowed. please_letters_numbers_spaces_underscores_only=Only letters, numbers, spaces and underscores are allowed.
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp