← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3956: Improved logic in data entry save value function

 

------------------------------------------------------------
revno: 3956
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2011-06-19 23:36:17 +0200
message:
  Improved logic in data entry save value function
modified:
  dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.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-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties	2011-06-16 09:24:02 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/org/hisp/dhis/de/i18n_module.properties	2011-06-19 21:36:17 +0000
@@ -109,10 +109,11 @@
 data_element_order 					= Data Element Order
 generate_min_max_success 			= Generated min/max values
 enter_digits                        = Enter digit only.
-value_must_number					= Value must be an number and maximum length not exceeds 255 characters
-value_must_positive_integer			= Value must be an positive integer and maximum length not exceeds 255 characters
-value_must_negative_integer			= Value must be an negative integer and maximum length not exceeds 255 characters
-field_unallowed_save_zero			= This element unallowed to save Zero. The original value won\'t be effect. 
+value_must_number					= Value must be an number
+value_must_positive_integer			= Value must be an positive integer
+value_must_negative_integer			= Value must be an negative integer
+value_is_too_long 					= Value is too long
+field_unallowed_save_zero			= This element does not permit 0 values. The original value will not be affected.
 datavalue_history                   = Data value history
 max_must_be_greater_than_min		= Max must be greater than min
 next 								= Next

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-06-17 09:29:13 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-06-19 21:36:17 +0000
@@ -106,70 +106,68 @@
     {
         if ( type == 'int' || type == 'number' || type == 'positiveNumber' || type == 'negativeNumber' )
         {
+        	if ( field.value && field.value.length > 255 )
+        	{
+        		window.alert( i18n_value_too_long + '\n\n' + dataElementName );
+        		return alertField( field );
+        	}
+			if ( type == 'int' && !isInt( field.value ) )
+            {
+            	window.alert( i18n_value_must_integer + '\n\n' + dataElementName );
+                return alertField( field );
+            }
+            if ( type == 'number' && !isRealNumber( field.value ) )
+            {
+                window.alert( i18n_value_must_number + '\n\n' + dataElementName );
+                return alertField( field );
+            } 
+			if ( type == 'positiveNumber' && !isPositiveInt( field.value ) )
+            {
+                window.alert( i18n_value_must_positive_integer + '\n\n' + dataElementName );
+                return alertField( field );
+            } 
+			if ( type == 'negativeNumber' && !isNegativeInt( field.value ) )
+            {
+                window.alert( i18n_value_must_negative_integer + '\n\n' + dataElementName );
+                return alertField( field );
+            }
 			if ( isValidZeroNumber( field.value ) )
             {
                 // If value is 0 and zero is not significant for data element, then skip value				
 				if ( significantZeros.indexOf( dataElementId ) == -1 )
 				{
 					field.style.backgroundColor = COLOR_GREEN;
-					field.value = '';
-					field.select();
-					field.focus();
 					return false;
 				}
-				
-				field.value = (field.value.indexOf(".") == -1) ? "0" : "0.0";
-            }
-			else if ( type == 'int' && ( !isInt( field.value ) || ( field.value.length > 255 ) ) )
-            {
-            	window.alert( i18n_value_must_integer + '\n\n' + dataElementName );
-                return alertField( field );
-            }  
-            else if ( type == 'number' && ( !isRealNumber( field.value ) || ( field.value.length > 255 ) ) )
-            {
-                window.alert( i18n_value_must_number + '\n\n' + dataElementName );
-                return alertField( field );
-            } 
-			else if ( type == 'positiveNumber' && ( !isPositiveInt( field.value ) || ( field.value.length > 255 ) ) )
-            {
-                window.alert( i18n_value_must_positive_integer + '\n\n' + dataElementName );
-                return alertField( field );
-            } 
-			else if ( type == 'negativeNumber' && ( !isNegativeInt( field.value ) || ( field.value.length > 255 ) ) )
-            {
-                window.alert( i18n_value_must_negative_integer + '\n\n' + dataElementName );
-                return alertField( field );
-            }
-            else
-            {
-                var minString = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].min' ).innerHTML;
-                var maxString = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].max' ).innerHTML;
-
-                if ( minString.length != 0 && maxString.length != 0 )
-                {
-                    var value = new Number( field.value );
-                    var min = new Number( minString );
-                    var max = new Number( maxString );
-
-                    if ( value < min )
-                    {
-                        var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, field.value, COLOR_RED );
-                        valueSaver.save();
-                        
-                        window.alert( i18n_value_of_data_element_less + '\n\n' + dataElementName );
-                        
-                        return;
-                    }
-
-                    if ( value > max )
-                    {
-                        var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, field.value, COLOR_RED );
-                        valueSaver.save();
-                        
-                        window.alert( i18n_value_of_data_element_greater + '\n\n' + dataElementName);
-                        
-                        return;
-                    }
+            }
+        
+            var minString = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].min' ).innerHTML;
+            var maxString = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].max' ).innerHTML;
+
+            if ( minString.length != 0 && maxString.length != 0 )
+            {
+                var value = new Number( field.value );
+                var min = new Number( minString );
+                var max = new Number( maxString );
+
+                if ( value < min )
+                {
+                    var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, field.value, COLOR_RED );
+                    valueSaver.save();
+                    
+                    window.alert( i18n_value_of_data_element_less + '\n\n' + dataElementName );
+                    
+                    return;
+                }
+
+                if ( value > max )
+                {
+                    var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, field.value, COLOR_RED );
+                    valueSaver.save();
+                    
+                    window.alert( i18n_value_of_data_element_greater + '\n\n' + dataElementName);
+                    
+                    return;
                 }
             }      
         }

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm	2011-06-16 09:24:02 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm	2011-06-19 21:36:17 +0000
@@ -6,6 +6,7 @@
 	var i18n_undo_register_complete_dataset_success = '$encoder.jsEscape( $i18n.getString( "undo_register_complete_dataset_success" ) , "'")';
     var i18n_value_of_data_element_less = '$encoder.jsEscape( $i18n.getString( "value_of_data_element_less" ) , "'")';
     var i18n_value_of_data_element_greater = '$encoder.jsEscape( $i18n.getString( "value_of_data_element_greater" ) , "'")';
+    var i18n_value_too_long = '$encoder.jsEscape( $i18n.getString( "value_is_too_long" ) , "'")';
 	var i18n_value_must_integer = '$encoder.jsEscape( $i18n.getString( "value_must_integer" ) , "'")';
 	var i18n_value_must_number = '$encoder.jsEscape( $i18n.getString( "value_must_number" ) , "'")';
 	var i18n_value_must_positive_integer = '$encoder.jsEscape( $i18n.getString( "value_must_positive_integer" ) , "'")';