← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16680: Data entry, replacing variables in global ns

 

------------------------------------------------------------
revno: 16680
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-09-09 23:45:33 -0400
message:
   Data entry, replacing variables in global ns
modified:
  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/form.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.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	2014-09-08 02:02:09 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2014-09-10 03:45:33 +0000
@@ -15,10 +15,6 @@
 // Save
 // -----------------------------------------------------------------------------
 
-var FORMULA_PATTERN = /#\{.+?\}/g;
-var SEPARATOR = '.';
-var EVENT_VALUE_SAVED = 'dhis-web-dataentry-value-saved'; // Deprecated
-
 /**
  * Updates totals for data element total fields.
  * 
@@ -120,7 +116,7 @@
  */
 dhis2.de.generateExpression = function( expression )
 {
-    var matcher = expression.match( FORMULA_PATTERN );
+    var matcher = expression.match( dhis2.de.cst.formulaPattern );
 
     for ( k in matcher )
     {
@@ -130,7 +126,7 @@
 
         var operand = match.replace( /[#\{\}]/g, '' );
 
-        var isTotal = !!( operand.indexOf( SEPARATOR ) == -1 );
+        var isTotal = !!( operand.indexOf( dhis2.de.cst.separator ) == -1 );
         
         var value = '0';
         
@@ -140,8 +136,8 @@
         }
         else
         {
-	        var de = operand.substring( 0, operand.indexOf( SEPARATOR ) );
-	        var coc = operand.substring( operand.indexOf( SEPARATOR ) + 1, operand.length );	
+	        var de = operand.substring( 0, operand.indexOf( dhis2.de.cst.separator ) );
+	        var coc = operand.substring( operand.indexOf( dhis2.de.cst.separator ) + 1, operand.length );	
 	        value = dhis2.de.getFieldValue( de, coc );
         }
 
@@ -168,7 +164,7 @@
     var value = $( fieldId ).val();
     var type = getDataElementType( dataElementId );
 
-    $( fieldId ).css( 'background-color', COLOR_YELLOW );
+    $( fieldId ).css( 'background-color', dhis2.de.cst.colorYellow );
 
     var periodId = $( '#selectedPeriodId' ).val();
 
@@ -224,7 +220,7 @@
 
                 if ( dhis2.de.significantZeros.indexOf( dataElementId ) == -1 )
                 {
-                    $( fieldId ).css( 'background-color', COLOR_GREEN );
+                    $( fieldId ).css( 'background-color', dhis2.de.cst.colorGreen );
                     return false;
                 }
             }
@@ -251,7 +247,7 @@
         }
     }
     
-    var color = warning ? COLOR_ORANGE : COLOR_GREEN;
+    var color = warning ? dhis2.de.cst.colorOrange : dhis2.de.cst.colorGreen;
     
     var valueSaver = new ValueSaver( dataElementId,	periodId, optionComboId, value, fieldId, color );
     valueSaver.save();
@@ -271,11 +267,11 @@
     
     var value = $( fieldId + ' option:selected' ).val();
 
-    $( fieldId ).css( 'background-color', COLOR_YELLOW );
+    $( fieldId ).css( 'background-color', dhis2.de.cst.colorYellow );
 
     var periodId = $( '#selectedPeriodId' ).val();
 
-    var valueSaver = new ValueSaver( dataElementId, periodId, optionComboId, value, fieldId, COLOR_GREEN );
+    var valueSaver = new ValueSaver( dataElementId, periodId, optionComboId, value, fieldId, dhis2.de.cst.colorGreen );
     valueSaver.save();
 }
 
@@ -287,11 +283,11 @@
     
     value = ( value == true) ? value : undefined; // Send nothing if un-ticked
 
-    $( fieldId ).css( 'background-color', COLOR_YELLOW );
+    $( fieldId ).css( 'background-color', dhis2.de.cst.colorYellow );
 
     var periodId = $( '#selectedPeriodId' ).val();
 
-    var valueSaver = new ValueSaver( dataElementId, periodId, optionComboId, value, fieldId, COLOR_GREEN );
+    var valueSaver = new ValueSaver( dataElementId, periodId, optionComboId, value, fieldId, dhis2.de.cst.colorGreen );
     valueSaver.save();
 }
 
@@ -301,7 +297,7 @@
 dhis2.de.alertField = function( fieldId, alertMessage )
 {
     var $field = $( fieldId );
-    $field.css( 'background-color', COLOR_YELLOW );
+    $field.css( 'background-color', dhis2.de.cst.colorYellow );
 
     window.alert( alertMessage );
     
@@ -381,7 +377,7 @@
     {
     	if ( 409 == xhr.status || 500 == xhr.status ) // Invalid value or locked
     	{
-    		markValue( fieldId, COLOR_RED );
+    		markValue( fieldId, dhis2.de.cst.colorRed );
     		setHeaderMessage( xhr.responseText );
     	}
     	else // Offline, keep local value

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2014-09-10 03:27:53 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2014-09-10 03:45:33 +0000
@@ -76,19 +76,24 @@
 
 // "organisationUnits" object inherited from ouwt.js
 
-// Colors
-
-var COLOR_GREEN = '#b9ffb9';
-var COLOR_YELLOW = '#fffe8c';
-var COLOR_RED = '#ff8a8a';
-var COLOR_ORANGE = '#ff6600';
-var COLOR_WHITE = '#fff';
-var COLOR_GREY = '#ccc';
-var COLOR_BORDER_ACTIVE = '#73ad72';
-var COLOR_BORDER = '#aaa';
+// Constants
 
 dhis2.de.cst.defaultType = 'int';
 dhis2.de.cst.defaultName = '[unknown]';
+dhis2.de.cst.dropDownMaxItems = 30;
+dhis2.de.cst.formulaPattern = /#\{.+?\}/g;
+dhis2.de.cst.separator = '.';
+
+// Colors
+
+dhis2.de.cst.colorGreen = '#b9ffb9';
+dhis2.de.cst.colorYellow = '#fffe8c';
+dhis2.de.cst.colorRed = '#ff8a8a';
+dhis2.de.cst.colorOrange = '#ff6600';
+dhis2.de.cst.colorWhite = '#fff';
+dhis2.de.cst.colorGrey = '#ccc';
+dhis2.de.cst.colorBorderActive = '#73ad72';
+dhis2.de.cst.colorBorder = '#aaa';
 
 // Form types
 
@@ -119,8 +124,7 @@
 }
 
 var EVENT_FORM_LOADED = "dhis-web-dataentry-form-loaded"; // Deprecated
-
-var MAX_DROPDOWN_DISPLAYED = 30;
+var EVENT_VALUE_SAVED = 'dhis-web-dataentry-value-saved'; // Deprecated
 
 var DAO = DAO || {};
 
@@ -1307,16 +1311,16 @@
     $( '.entrytrueonly' ).removeAttr( 'checked' );
     $( '.entryoptionset' ).val( '' );
 
-    $( '.entryfield' ).css( 'background-color', COLOR_WHITE ).css( 'border', '1px solid ' + COLOR_BORDER );
-    $( '.entryselect' ).css( 'background-color', COLOR_WHITE ).css( 'border', '1px solid ' + COLOR_BORDER );
-    $( '.indicator' ).css( 'background-color', COLOR_WHITE ).css( 'border', '1px solid ' + COLOR_BORDER );
-    $( '.entrytrueonly' ).css( 'background-color', COLOR_WHITE );
-    $( '.entryoptionset' ).css( 'background-color', COLOR_WHITE );
+    $( '.entryfield' ).css( 'background-color', dhis2.de.cst.colorWhite ).css( 'border', '1px solid ' + dhis2.de.cst.colorBorder );
+    $( '.entryselect' ).css( 'background-color', dhis2.de.cst.colorWhite ).css( 'border', '1px solid ' + dhis2.de.cst.colorBorder );
+    $( '.indicator' ).css( 'background-color', dhis2.de.cst.colorWhite ).css( 'border', '1px solid ' + dhis2.de.cst.colorBorder );
+    $( '.entrytrueonly' ).css( 'background-color', dhis2.de.cst.colorWhite );
+    $( '.entryoptionset' ).css( 'background-color', dhis2.de.cst.colorWhite );
 
     $( '[name="min"]' ).html( '' );
     $( '[name="max"]' ).html( '' );
 
-    $( '.entryfield' ).filter( ':disabled' ).css( 'background-color', COLOR_GREY );
+    $( '.entryfield' ).filter( ':disabled' ).css( 'background-color', dhis2.de.cst.colorGrey );
 
     var params = {
 		periodId : periodId,
@@ -1436,7 +1440,7 @@
             }
             else if ( $( fieldId ).length > 0 )
             {
-                $( fieldId ).css( 'border-color', COLOR_BORDER_ACTIVE )
+                $( fieldId ).css( 'border-color', dhis2.de.cst.colorBorderActive )
             }	            		
         }
         
@@ -1459,7 +1463,7 @@
             if ( dataValue && ( ( value.min && new Number( dataValue ) < new Number(
                 value.min ) ) || ( value.max && new Number( dataValue ) > new Number( value.max ) ) ) )
             {
-                $( valFieldId ).css( 'background-color', COLOR_ORANGE );
+                $( valFieldId ).css( 'background-color', dhis2.de.cst.colorOrange );
             }
 
             dhis2.de.currentMinMaxValueMap[minId] = value.min;
@@ -1885,7 +1889,7 @@
                     if ( $.trim( $( this ).val() ).length == 0 )
                     {
                         violations = true;						
-                        $selector.css( 'background-color', COLOR_RED );						
+                        $selector.css( 'background-color', dhis2.de.cst.colorRed );						
                         return false;
                     }
                 } );
@@ -2580,7 +2584,7 @@
                 var options = [];
 
                 if ( query == null || query == '' ) {
-                    options = obj.optionSet.options.slice( 0, MAX_DROPDOWN_DISPLAYED - 1 );
+                    options = obj.optionSet.options.slice( 0, dhis2.de.cst.dropDownMaxItems - 1 );
                 } 
                 else {
                     query = query.toLowerCase();
@@ -2588,7 +2592,7 @@
                     for ( var idx=0, len = obj.optionSet.options.length; idx < len; idx++ ) {
                         var item = obj.optionSet.options[idx];
 
-                        if ( options.length >= MAX_DROPDOWN_DISPLAYED ) {
+                        if ( options.length >= dhis2.de.cst.dropDownMaxItems ) {
                             break;
                         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js	2014-07-10 15:06:47 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js	2014-09-10 03:45:33 +0000
@@ -7,7 +7,7 @@
 
     if ( commentValue.length > 360 )
     {
-        markComment( COLOR_YELLOW );
+        markComment( dhis2.de.cst.colorYellow );
         window.alert(i18n_value_too_long + " for comment field");
 
         return;
@@ -42,7 +42,7 @@
     
     this.save = function()
     {
-        markComment( COLOR_YELLOW );
+        markComment( dhis2.de.cst.colorYellow );
 
         $.ajax( {
             url: '../api/dataValues',
@@ -55,12 +55,12 @@
 
     function handleSuccess( json )
     {
-    	markComment( COLOR_GREEN );
+    	markComment( dhis2.de.cst.colorGreen );
     }
 
     function handleError( xhr, textStatus, errorThrown )
     {
-        markComment( COLOR_RED );
+        markComment( dhis2.de.cst.colorRed );
         window.alert( i18n_saving_comment_failed_error_code + '\n\n' + xhr.responseText );
     }
 }
@@ -84,8 +84,8 @@
     		organisationUnitId: dhis2.de.currentOrganisationUnitId
     	},
     	success: function() {    		
-    		$( '#minLimit' ).css( 'background-color', COLOR_WHITE );
-    		$( '#maxLimit' ).css( 'background-color', COLOR_WHITE );
+    		$( '#minLimit' ).css( 'background-color', dhis2.de.cst.colorWhite );
+    		$( '#maxLimit' ).css( 'background-color', dhis2.de.cst.colorWhite );
     		
     		refreshChart()
     	}
@@ -153,14 +153,14 @@
     	},
     	dataType: 'json',
     	success: function() {
-    		$( '#minLimit' ).css( 'background-color', COLOR_GREEN );
-    		$( '#maxLimit' ).css( 'background-color', COLOR_GREEN );
+    		$( '#minLimit' ).css( 'background-color', dhis2.de.cst.colorGreen );
+    		$( '#maxLimit' ).css( 'background-color', dhis2.de.cst.colorGreen );
     		refreshChart();
     	},
     	error: function() {
     		
-    		$( '#minLimit' ).css( 'background-color', COLOR_RED );
-    		$( '#maxLimit' ).css( 'background-color', COLOR_RED );
+    		$( '#minLimit' ).css( 'background-color', dhis2.de.cst.colorRed );
+    		$( '#maxLimit' ).css( 'background-color', dhis2.de.cst.colorRed );
     	}
     } );
 }