← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4118: wip jqueryfication of data entry

 

------------------------------------------------------------
revno: 4118
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-07-12 15:41:21 +0200
message:
  wip jqueryfication of data entry
modified:
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.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-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-07-11 10:22:45 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-07-12 13:41:21 +0000
@@ -79,10 +79,9 @@
         var dataElementId = operand.substring( 0, operand.indexOf( SEPARATOR ) );
         var categoryOptionComboId = operand.substring( operand.indexOf( SEPARATOR ) + 1, operand.length );
 
-        var entryFieldId = dataElementId + '-' + categoryOptionComboId + '-val';
-        var entryField = document.getElementById( entryFieldId );
+        var fieldId = '#' + dataElementId + '-' + categoryOptionComboId + '-val';
 
-        var value = entryField && entryField.value ? entryField.value : '0';
+        var value = $( fieldId ) && $( fieldId ).val() ? $( fieldId ).val() : '0';
 
         expression = expression.replace( match, value ); // TODO signed numbers
     }
@@ -95,87 +94,80 @@
  */
 function saveVal( dataElementId, optionComboId )
 {
-    var dataElementName = document.getElementById( dataElementId + '-dataelement' ).innerHTML;
-
-    var field = document.getElementById( dataElementId + '-' + optionComboId + '-val' );
-    var type = document.getElementById( dataElementId + '-type' ).innerHTML;
-    var organisationUnitId = getFieldValue( 'organisationUnitId' );
-
-    field.style.backgroundColor = COLOR_YELLOW;
-
-    if ( field.value && field.value != '' )
+    var dataElementName = $( '#' + dataElementId + '-dataelement' ).html();
+
+    var fieldId = '#' + dataElementId + '-' + optionComboId + '-val';
+    var value =$( fieldId ).val();
+    var type = $( '#' + dataElementId + '-type' ).html();
+    var organisationUnitId = $( '#organisationUnitId' ).val();
+
+    $( fieldId ).css( 'background-color', COLOR_YELLOW );
+
+    if ( value )
     {
         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 ( value.length > 255 )
+            {
+                return alertField( fieldId, i18n_value_too_long + '\n\n' + dataElementName );
+            }
+            if ( type == 'int' && !isInt( value ) )
+            {
+                return alertField( fieldId,  i18n_value_must_integer + '\n\n' + dataElementName );
+            }
+            if ( type == 'number' && !isRealNumber( value ) )
+            {
+                return alertField( fieldId, i18n_value_must_number + '\n\n' + dataElementName );
+            }
+            if ( type == 'positiveNumber' && !isPositiveInt( value ) )
+            {
+                return alertField( fieldId,  i18n_value_must_positive_integer + '\n\n' + dataElementName );
+            }
+            if ( type == 'negativeNumber' && !isNegativeInt( value ) )
+            {
+                return alertField( fieldId, i18n_value_must_negative_integer + '\n\n' + dataElementName );
+            }
+            if ( isValidZeroNumber( value ) )
+            {
+                // If value is 0 and zero is not significant for data element, skip value
                 if ( significantZeros.indexOf( dataElementId ) == -1 )
                 {
-                    field.style.backgroundColor = COLOR_GREEN;
+                    $( fieldId ).css( 'background-color', COLOR_GREEN );
                     return false;
                 }
             }
 
-            var minString = document.getElementById( dataElementId + '-' + optionComboId + '-min' ).innerHTML;
-            var maxString = document.getElementById( dataElementId + '-' + optionComboId + '-max' ).innerHTML;
+            var minString = $( '#' + dataElementId + '-' + optionComboId + '-min' ).html();
+            var maxString = $( '#' + dataElementId + '-' + optionComboId + '-max' ).html();
 
-            if ( minString.length != 0 && maxString.length != 0 )
+            if ( minString && maxString )
             {
-                var value = new Number( field.value );
+                var valueNo = new Number( value );
                 var min = new Number( minString );
                 var max = new Number( maxString );
 
-                if ( value < min )
+                if ( valueNo < min )
                 {
-                    var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, field.value, COLOR_ORANGE );
+                    var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, value, COLOR_ORANGE );
                     valueSaver.save();
 
                     window.alert( i18n_value_of_data_element_less + ': ' + min + '\n\n' + dataElementName );
-
                     return;
                 }
 
-                if ( value > max )
+                if ( valueNo > max )
                 {
-                    var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, field.value, COLOR_ORANGE );
+                    var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, value, COLOR_ORANGE );
                     valueSaver.save();
 
                     window.alert( i18n_value_of_data_element_greater + ': ' + max + '\n\n' + dataElementName );
-
                     return;
                 }
             }
         }
     }
 
-    var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, field.value, COLOR_GREEN, '' );
+    var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, value, COLOR_GREEN, '' );
     valueSaver.save();
     
     updateIndicators(); // Update indicators in case of custom form
@@ -188,8 +180,7 @@
 
     selectedOption.style.backgroundColor = COLOR_YELLOW;
 
-    var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, select, COLOR_GREEN,
-            selectedOption );
+    var valueSaver = new ValueSaver( dataElementId, optionComboId, organisationUnitId, select, COLOR_GREEN, selectedOption );
     valueSaver.save();
 }
 
@@ -208,11 +199,13 @@
 /**
  * Supportive method.
  */
-function alertField( field )
+function alertField( fieldId, alertMessage )
 {
-    field.style.backgroundColor = COLOR_YELLOW;
-    field.select();
-    field.focus();
+    $( fieldId ).css( fieldId, COLOR_YELLOW );
+    $( fieldId ).select();
+    $( fieldId ).focus();
+    alert( alertMessage );
+
     return false;
 }
 
@@ -268,4 +261,4 @@
         var element = document.getElementById( dataElementId + '-' + optionComboId + '-val' );
         element.style.backgroundColor = color;
     }
-}
+}
\ No newline at end of file