← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3112: Add validation for Beneficiary Aggregation Form.

 

------------------------------------------------------------
revno: 3112
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-03-22 09:17:23 +0700
message:
  Add validation for Beneficiary Aggregation Form.
added:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/ValidationCaseAggregationAction.java
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultAction.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/caseAggregationForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseAggregationForm.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.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-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultAction.java	2011-03-08 03:35:28 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultAction.java	2011-03-22 02:17:23 +0000
@@ -215,22 +215,15 @@
 
         List<Period> periodList = new ArrayList<Period>();
 
-        periodGenericManager.setSelectedPeriodIndex( PeriodGenericManager.SESSION_KEY_SELECTED_PERIOD_INDEX_START,
-            sDateLB );
         Period startPeriod = periodGenericManager.getSelectedPeriod(
             PeriodGenericManager.SESSION_KEY_SELECTED_PERIOD_INDEX_START,
             PeriodGenericManager.SESSION_KEY_BASE_PERIOD_START );
-
-        periodGenericManager.setSelectedPeriodIndex( PeriodGenericManager.SESSION_KEY_SELECTED_PERIOD_INDEX_END,
-            eDateLB );
+        
         Period endPeriod = periodGenericManager.getSelectedPeriod(
             PeriodGenericManager.SESSION_KEY_SELECTED_PERIOD_INDEX_END,
             PeriodGenericManager.SESSION_KEY_BASE_PERIOD_END );
      
-        if ( sDateLB != -1 && eDateLB != -1 )
-        {
-            periodList = getPeriodList( (CalendarPeriodType)selectedDataSet.getPeriodType(), startPeriod, endPeriod );
-        }
+        periodList = getPeriodList( (CalendarPeriodType)selectedDataSet.getPeriodType(), startPeriod, endPeriod );
 
         // ---------------------------------------------------------------------
         // Aggregation
@@ -287,7 +280,7 @@
                         {
                                 DataValue dvalue = new DataValue( dElement, period, orgUnit, "", storedBy,
                                     new Date(), null, optionCombo );
-                                dvalue.setValue( dataValue.getValue() + i18n.getString( "old_value" ) ); 
+                                dvalue.setValue( dataValue.getValue() + " " + i18n.getString( "old_value" ) ); 
                                 
                                 dataValueService.deleteDataValue( dataValue );
 

=== added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/ValidationCaseAggregationAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/ValidationCaseAggregationAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/ValidationCaseAggregationAction.java	2011-03-22 02:17:23 +0000
@@ -0,0 +1,145 @@
+/*
+ * 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.caseaggregation;
+
+import org.hisp.dhis.caseentry.state.PeriodGenericManager;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.oust.manager.SelectionTreeManager;
+import org.hisp.dhis.period.Period;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version ValidationCaseAggregationAction.java Mar 21, 2011 8:50:06 PM $
+ */
+public class ValidationCaseAggregationAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private SelectionTreeManager selectionTreeManager;
+
+    private PeriodGenericManager periodGenericManager;
+
+    private I18n i18n;
+
+    // -------------------------------------------------------------------------
+    // Input / Output
+    // -------------------------------------------------------------------------
+    
+    private String message;
+
+    private int sDateLB;
+
+    private int eDateLB;
+    
+    // -------------------------------------------------------------------------
+    // Getters && Setters
+    // -------------------------------------------------------------------------
+
+    public void setPeriodGenericManager( PeriodGenericManager periodGenericManager )
+    {
+        this.periodGenericManager = periodGenericManager;
+    }
+
+    public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager )
+    {
+        this.selectionTreeManager = selectionTreeManager;
+    }
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
+    public void setEDateLB( int dateLB )
+    {
+        eDateLB = dateLB;
+    }
+
+    public void setSDateLB( int dateLB )
+    {
+        sDateLB = dateLB;
+    }
+
+    public String getMessage()
+    {
+        return message;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        message = "";
+
+        // ---------------------------------------------------------------------
+        // Get selected orgunits
+        // ---------------------------------------------------------------------
+
+        OrganisationUnit selectedOrgunit = selectionTreeManager.getReloadedSelectedOrganisationUnit();
+
+        if ( selectedOrgunit == null )
+        {
+            message = i18n.getString("please_specify_an_orgunit");
+            return INPUT;
+        }
+
+        // ---------------------------------------------------------------------
+        // Check start-date and end-date
+        // ---------------------------------------------------------------------
+
+        periodGenericManager.setSelectedPeriodIndex( PeriodGenericManager.SESSION_KEY_SELECTED_PERIOD_INDEX_START,
+            sDateLB );
+        Period startPeriod = periodGenericManager.getSelectedPeriod(
+            PeriodGenericManager.SESSION_KEY_SELECTED_PERIOD_INDEX_START,
+            PeriodGenericManager.SESSION_KEY_BASE_PERIOD_START );
+
+        periodGenericManager.setSelectedPeriodIndex( PeriodGenericManager.SESSION_KEY_SELECTED_PERIOD_INDEX_END,
+            eDateLB );
+        Period endPeriod = periodGenericManager.getSelectedPeriod(
+            PeriodGenericManager.SESSION_KEY_SELECTED_PERIOD_INDEX_END,
+            PeriodGenericManager.SESSION_KEY_BASE_PERIOD_END );
+
+        if ( startPeriod.getEndDate().after( endPeriod.getEndDate()  ) )
+        {
+            message = i18n.getString("please_select_to_date_greater_or_equals_to_from_date");
+            return INPUT;
+        }
+
+        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	2011-01-12 02:22:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2011-03-22 02:17:23 +0000
@@ -335,6 +335,7 @@
 	</bean>
 
 	<!-- Case Aggregation -->
+	
 	<bean
 		id="org.hisp.dhis.caseentry.action.caseaggregation.CaseAggregationFormAction"
 		class="org.hisp.dhis.caseentry.action.caseaggregation.CaseAggregationFormAction"
@@ -349,7 +350,14 @@
 		<property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
 		<property name="periodGenericManager" ref="org.hisp.dhis.caseentry.state.PeriodGenericManager" />
 	</bean>
-
+	
+	<bean
+		id="org.hisp.dhis.caseentry.action.caseaggregation.ValidationCaseAggregationAction"
+		class="org.hisp.dhis.caseentry.action.caseaggregation.ValidationCaseAggregationAction"
+		scope="prototype">
+		<property name="selectionTreeManager" ref="org.hisp.dhis.oust.manager.SelectionTreeManager" />
+		<property name="periodGenericManager" ref="org.hisp.dhis.caseentry.state.PeriodGenericManager" />
+	</bean>
 	<bean
 		id="org.hisp.dhis.caseentry.action.caseaggregation.CaseAggregationResultAction"
 		class="org.hisp.dhis.caseentry.action.caseaggregation.CaseAggregationResultAction"

=== 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	2011-03-08 03:35:28 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2011-03-22 02:17:23 +0000
@@ -283,8 +283,9 @@
 value															= Value
 status															= Status
 no_value_added_or_update										= No values added or updated.
-greater_then_from_date											= This field is greater then from date.
 date_less_incident_date											= This date is less then the incident date.
 deleted															= Deleted
 old_value														= Old Value
-case_aggregation												= Beneficiary Aggregation
\ No newline at end of file
+case_aggregation												= Beneficiary Aggregation
+please_specify_an_orgunit										= Please specify an organisation unit
+please_select_to_date_greater_or_equals_to_from_date			= Please select to-date greater or equals to from-date

=== 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	2011-03-21 10:55:30 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2011-03-22 02:17:23 +0000
@@ -228,9 +228,12 @@
 		<result name="success" type="velocity-json">/dhis-web-caseentry/responsePeriods.vm</result>
 	</action>
 	
-	<!-- <action name="caseAggregationResult" class="org.hisp.dhis.caseentry.action.caseaggregation.LoadPeriodsAction">
-		<result name="success" type="chain">caseAggregationResultChain</result>
-	</action>  -->
+	<action name="validateCaseAggregation"
+		class="org.hisp.dhis.caseentry.action.caseaggregation.ValidationCaseAggregationAction">
+		<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>
+	</action>
 	
     <action name="caseAggregationResult" class="org.hisp.dhis.caseentry.action.caseaggregation.CaseAggregationResultAction">                 
       <result name="success" type="velocity">/main.vm</result>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationForm.vm	2011-03-21 10:55:30 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationForm.vm	2011-03-22 02:17:23 +0000
@@ -62,7 +62,7 @@
 		
 		<tr>
 			<td colspan='2'>
-				#organisationUnitSelectionTree( false, true, false )
+				#organisationUnitSelectionTree( true, false, false )
 			</td>
 		</tr>
 
@@ -73,4 +73,6 @@
 			<td></td>
 		</tr>
 	</table>
+	
+	<span id='message'></span>
 </form>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseAggregationForm.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseAggregationForm.js	2011-03-21 10:55:30 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseAggregationForm.js	2011-03-22 02:17:23 +0000
@@ -12,19 +12,9 @@
 	};
 	
 	validation2( 'caseAggregationForm', function(form) {
-		if(isSubmit) form.submit();
+		validationCaseAggregation();
 	}, {
-		'beforeValidateHandler': function() {
-			var periodFrom = jQuery( '#sDateLB' ).val();
-			var periodTo = jQuery( '#eDateLB' ).val();
-			
-			if(periodFrom > periodTo){
-				byId('warningMessage').innerHTML = i18n_greater_then_from_date;
-				isSubmit = false;
-			} else {
-				isSubmit = true;
-			}
-		},
+		
 		'rules': rules
 	})
 }); 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js	2011-01-05 01:13:23 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js	2011-03-22 02:17:23 +0000
@@ -84,5 +84,30 @@
 	});
 }
 
+	
+function validationCaseAggregation( )
+{
+    var request = new Request();
+    request.setResponseTypeXML( 'dataElementGroup' );
+    request.setCallbackSuccess( validationCaseAggregationCompleted );
+	
+	var url  = "sDateLB=" + byId('sDateLB').value;
+		url += "&eDateLB=" + byId('eDateLB').value;
+		
+	request.sendAsPost(url);
+    request.send( 'validateCaseAggregation.action' );
+}
 
-	
\ No newline at end of file
+function validationCaseAggregationCompleted( message )
+{
+    var type = message.getAttribute("type");
+	
+    if( type == "success" )
+    {
+        document.forms[ 'caseAggregationForm' ].submit();
+    }
+    else
+    {
+        setMessage(message.firstChild.nodeValue);
+    }
+}