← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4050: Fixed validation on Constant's value.

 

------------------------------------------------------------
revno: 4050
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-07-01 11:50:26 +0700
message:
  Fixed validation on Constant's value.
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/constant/ValidateConstantAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addConstantForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateConstantForm.vm


--
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-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/constant/ValidateConstantAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/constant/ValidateConstantAction.java	2011-06-30 07:55:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/constant/ValidateConstantAction.java	2011-07-01 04:50:26 +0000
@@ -79,13 +79,6 @@
         this.name = name;
     }
 
-    private String value;
-
-    public void setValue( String value )
-    {
-        this.value = value;
-    }
-
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
@@ -115,27 +108,6 @@
             }
         }
 
-        if ( value != null )
-        {
-            try
-            {
-                double valueTemp = Double.parseDouble( value );
-
-                if ( Double.isNaN( valueTemp ) || Double.isInfinite( valueTemp ) )
-                {
-                    message = i18n.getString( "value_must_be_double" );
-
-                    return ERROR;
-                }
-            }
-            catch ( NumberFormatException nfe )
-            {
-                message = i18n.getString( "value_must_be_double" );
-
-                return ERROR;
-            }
-        }
-
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2011-06-30 07:55:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2011-07-01 04:50:26 +0000
@@ -325,5 +325,5 @@
 constant_management													= Constant Management
 create_new_constant													= Add Constant
 edit_constant														= Edit Constant
-value_must_be_double												= The given value must be a double
+value_must_be_double												= Value must be an number
 confirm_delete_constant												= Do you want to delete this constant object ?
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addConstantForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addConstantForm.vm	2011-06-30 07:55:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addConstantForm.vm	2011-07-01 04:50:26 +0000
@@ -1,14 +1,19 @@
 <script type="text/javascript">
 	jQuery(document).ready(	function(){
+	
 		var rules = getValidationRules("constant");
+		rules['value'].custome_regex = [ /^-?(0|[1-9]\d*)(\.\d+)?$/, i18n_value_must_be_double ];
 		
-		validation2( 'addConstantForm', function( form ) { form.submit() }, {
+		validation2( 'addConstantForm', function( form ){ form.submit(); },
+		{
 			'rules': rules
 		});
 
 		checkValueIsExist( "name", "validateConstant.action" );
-		remoteValidateById( "value", "validateConstant.action" );
 	});
+	
+	var i18n_value_must_be_double = '$encoder.jsEscape( $i18n.getString( "value_must_be_double" ) , "'")';
+	
 </script>
 
 <h3>$i18n.getString( "create_new_constant" )</h3>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateConstantForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateConstantForm.vm	2011-06-30 07:55:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateConstantForm.vm	2011-07-01 04:50:26 +0000
@@ -1,14 +1,19 @@
 <script type="text/javascript">
 	jQuery(document).ready(	function(){
+	
 		var rules = getValidationRules("constant");
+		rules['value'].custome_regex = [ /^-?(0|[1-9]\d*)(\.\d+)?$/, i18n_value_must_be_double ];
 		
-		validation2( 'updateConstantForm', function( form ) { form.submit() }, {
+		validation2( 'updateConstantForm', function( form ){ form.submit(); },
+		{
 			'rules': rules
-		});		
+		});
 
-		checkValueIsExist( "name", "validateConstant.action", {id: $constant.id});				
-		remoteValidateById( "value", "validateConstant.action" );				
+		checkValueIsExist( "name", "validateConstant.action", {id: $constant.id} );
 	});
+	
+	var i18n_value_must_be_double = '$encoder.jsEscape( $i18n.getString( "value_must_be_double" ) , "'")';
+	
 </script>
 
 <h3>$i18n.getString( "edit_constant" )</h3>