← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7255: Made custom form indicator calculation more robust

 

------------------------------------------------------------
revno: 7255
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-06-09 23:27:46 +0200
message:
  Made custom form indicator calculation more robust
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js
  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-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2012-06-06 10:51:29 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2012-06-09 21:27:46 +0000
@@ -1526,6 +1526,11 @@
 	return ( Math.round( number * factor ) / factor );
 }
 
+function isDefined( variable )
+{
+	return ( typeof( variable ) !== "undefined" );
+}
+
 // -----------------------------------------------------------------------------
 // Paging
 // -----------------------------------------------------------------------------

=== 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	2012-03-26 18:11:26 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2012-06-09 21:27:46 +0000
@@ -54,16 +54,23 @@
         var indicatorId = $( this ).attr( 'indicatorid' );
 
         var formula = indicatorFormulas[indicatorId];
-
-        var expression = generateExpression( formula );
-
-        if ( expression )
+        
+        if ( isDefined( formula ) )
+        {        
+	        var expression = generateExpression( formula );
+	
+	        if ( expression )
+	        {
+		        var value = eval( expression );
+		        
+		        value = isNaN( value ) ? '-' : roundTo( value, 1 );
+		
+		        $( this ).attr( 'value', value );
+	        }
+        }
+        else
         {
-	        var value = eval( expression );
-	        
-	        value = isNaN( value ) ? '-' : roundTo( value, 1 );
-	
-	        $( this ).attr( 'value', value );
+        	log( 'Indicator does not exist in form: ' + indicatorId );
         }
     } );
 }