← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2094: rename javascript function

 

------------------------------------------------------------
revno: 2094
committer: Tran Thanh Tri <Tran Thanh Tri@compaq>
branch nick: trunk
timestamp: Fri 2010-09-10 20:34:00 +0700
message:
  rename javascript function
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.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-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm	2010-09-10 12:55:23 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm	2010-09-10 13:34:00 +0000
@@ -66,30 +66,21 @@
 			<input type="submit" value="$i18n.getString( 'save' )" style="width:125px"/>
 			<input type="button" value="$i18n.getString( 'cancel' )" style="width:125px" onclick="closeExpressionBuilder()">
 		</td>
-	</tr>
-	
-	
+	</tr>	
 </table>
 </form>
 </div>
 
 <script>
-	
+
+	var numerator = false;	
+	var validator = null;
 
 	function indicatorNumeratorForm()
 	{
-		loadDataElementGroups( "#indicator-expression-container select[id=dataElementGroupId]" );
-		var validator = validation( 'indicator-expression-form', function(){
-			var expression = getFieldValue( 'indicator-expression-container textarea[id=expression]' );
-			var description = getFieldValue( 'indicator-expression-container input[id=description]' );
-			var aggregationOperator = getRadioValue( 'aggregationOperator' );
-			setFieldValue( 'numerator', expression );
-			setFieldValue( 'numeratorDescription', description );
-			setFieldValue( 'numeratorAggregationOperator', aggregationOperator );
-			closeExpressionBuilder();
-		} );
+		numerator = true;
 		
-		remoteValidateById('expression', '../dhis-web-commons-ajax-json/getExpressionText.action');
+		loadDataElementGroups( "#indicator-expression-container select[id=dataElementGroupId]" );	
 		
 		validator.resetForm();
 		
@@ -108,18 +99,9 @@
 	
 	function indicatorDenominatorForm()
 	{
-		loadDataElementGroups( "#indicator-expression-container select[id=dataElementGroupId]" );
-		var validator = validation( 'indicator-expression-form', function(){
-			var expression = getFieldValue( 'indicator-expression-container textarea[id=expression]' );
-			var description = getFieldValue( 'indicator-expression-container input[id=description]' );
-			var aggregationOperator = getRadioValue( 'aggregationOperator' );
-			setFieldValue( 'denominator', expression );
-			setFieldValue( 'denominatorDescription', description );
-			setFieldValue( 'denominatorAggregationOperator', aggregationOperator );
-			closeExpressionBuilder();
-		} );
+		numerator = false;
 		
-		remoteValidateById('expression', '../dhis-web-commons-ajax-json/getExpressionText.action');
+		loadDataElementGroups( "#indicator-expression-container select[id=dataElementGroupId]" );	
 		
 		validator.resetForm();
 		
@@ -192,6 +174,39 @@
 		hideById( 'indicator-expression-container' );
 		unLockScreen();
 	}
+	
+	function inserExpression()
+	{
+		var expression = getFieldValue( 'indicator-expression-container textarea[id=expression]' );
+		var description = getFieldValue( 'indicator-expression-container input[id=description]' );
+		var aggregationOperator = getRadioValue( 'aggregationOperator' );
+		
+		jQuery.postJSON( '../dhis-web-commons-ajax-json/getExpressionText.action', 
+			{expression: expression},
+			function( json ){
+				if( json.response == 'error') markInvalid( 'indicator-expression-container textarea[id=expression]' , json.message );
+				else {								
+					if( numerator ){								
+						setFieldValue( 'numerator', expression );
+						setFieldValue( 'numeratorDescription', description );
+						setFieldValue( 'numeratorAggregationOperator', aggregationOperator );			
+					}else{
+						setFieldValue( 'denominator', expression );
+						setFieldValue( 'denominatorDescription', description );
+						setFieldValue( 'denominatorAggregationOperator', aggregationOperator );									
+					}
+					
+					closeExpressionBuilder();
+				}
+				
+				
+			});		
+		
+	}
+	
+	jQuery( document ).ready( function(){
+		validator = validation( 'indicator-expression-form', inserExpression );
+	});
 
 	
 </script>