← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6081: Reimplemented outlier analysis js using jquery

 

------------------------------------------------------------
revno: 6081
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-02-22 18:36:22 +0100
message:
  Reimplemented outlier analysis js using jquery
removed:
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/responseStatus.vm
modified:
  dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/dataanalysis/EditDataValueAction.java
  dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/dataAnalysis.js
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/editDataValue.js
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/searchResult.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-validationrule/src/main/java/org/hisp/dhis/validationrule/action/dataanalysis/EditDataValueAction.java'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/dataanalysis/EditDataValueAction.java	2009-12-24 14:47:25 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/dataanalysis/EditDataValueAction.java	2012-02-22 17:36:22 +0000
@@ -137,18 +137,11 @@
         this.categoryOptionComboId = categoryOptionComboId;
     }
 
-    private String message = "";
-
-    public String getMessage()
-    {
-        return message;
-    }
-
-    private int statusCode = 0;
-
-    public int getStatusCode()
-    {
-        return statusCode;
+    private int code = 0;
+
+    public int getCode()
+    {
+        return code;
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/struts.xml	2012-02-22 15:24:59 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/struts.xml	2012-02-22 17:36:22 +0000
@@ -185,12 +185,11 @@
     </action>
 
     <action name="editDataValue" class="org.hisp.dhis.validationrule.action.dataanalysis.EditDataValueAction">
-      <result name="success" type="velocity">responseStatus.vm</result>
-      <result name="error" type="velocity">responseStatus.vm</result>
+      <result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
     </action>
 
     <action name="markForFollowup" class="org.hisp.dhis.validationrule.action.dataanalysis.MarkForFollowupAction">
-      <result name="success" type="velocity-xml">/dhis-web-validationrule/responseSuccess.vm</result>
+      <result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
     </action>
 
     <action name="validateRunAnalysis" class="org.hisp.dhis.validationrule.action.dataanalysis.ValidationRunAnalysisAction">

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/dataAnalysis.js'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/dataAnalysis.js	2011-06-23 14:44:17 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/dataAnalysis.js	2012-02-22 17:36:22 +0000
@@ -12,7 +12,8 @@
         $.post( "validateRunAnalysis.action", {
             fromDate : getFieldValue( 'fromDate' ),
             toDate : getFieldValue( 'toDate' )
-        }, function( data )
+        }, 
+        function( data )
         {
             runValidationCompleted( data );
         }, 'xml' );
@@ -52,10 +53,12 @@
     if ( type == 'success' )
     {
         analyseData();
-    } else if ( type == 'error' )
+    }
+    else if ( type == 'error' )
     {
         window.alert( i18n_validation_failed + ':' + '\n' + message );
-    } else if ( type == 'input' )
+    }
+    else if ( type == 'input' )
     {
         setMessage( message );
     }

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/editDataValue.js'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/editDataValue.js	2011-06-23 14:44:17 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/editDataValue.js	2012-02-22 17:36:22 +0000
@@ -1,14 +1,12 @@
 
-var currentFollowupId = null;
-
 function editValue( valueId )
 {
-	var field = document.getElementById( 'value[' + valueId + '].value' );
+	var field = document.getElementById( 'value-' + valueId + '-val' );
 	
-	var dataElementId = document.getElementById( 'value[' + valueId + '].dataElement' ).value;
-    var categoryOptionComboId = document.getElementById( 'value[' + valueId + '].categoryOptionCombo' ).value;
-	var periodId = document.getElementById( 'value[' + valueId + '].period' ).value;
-	var sourceId = document.getElementById( 'value[' + valueId + '].source' ).value;
+	var dataElementId = $( '#value-' + valueId + '-de' ).val();
+    var categoryOptionComboId = $( '#value-' + valueId + '-coc' ).val();
+	var periodId = $( '#value-' + valueId + '-pe' ).val();
+	var sourceId = $( '#value-' + valueId + '-ou' ).val();
 	
 	if ( field.value != '' )
 	{
@@ -23,8 +21,8 @@
 		}
 		else
 		{
-			var minString = document.getElementById('value[' + valueId + '].min').value;
-			var maxString = document.getElementById('value[' + valueId + '].max').value;
+			var minString = $( '#value-' + valueId + '-min' ).val();
+			var maxString = $( '#value-' + valueId + '-max' ).val();
 			
 			var min = new Number( minString );
 			var max = new Number( maxString );
@@ -53,9 +51,8 @@
 		}
 	}
 	
-    var valueSaver = new ValueSaver( dataElementId, periodId, sourceId, categoryOptionComboId, field.value, valueId, '#ccffcc', '');
+    var valueSaver = new ValueSaver( dataElementId, periodId, sourceId, categoryOptionComboId, field.value, valueId, '#ccffcc' );
     valueSaver.save();
-
 }
 
 function isInt( value )
@@ -70,98 +67,76 @@
     return true;
 }
 
-function markValueForFollowup( valueId )
+function markFollowUp( valueId )
 {	
-	currentFollowupId = valueId;
-	
-    var dataElementId = document.getElementById( 'value[' + valueId + '].dataElement' ).value;
-    var categoryOptionComboId = document.getElementById( 'value[' + valueId + '].categoryOptionCombo' ).value;
-    var periodId = document.getElementById( 'value[' + valueId + '].period' ).value;
-    var sourceId = document.getElementById( 'value[' + valueId + '].source' ).value;
-    
-    var url = 'markForFollowup.action?dataElementId=' + dataElementId + '&periodId=' + periodId +
-        '&sourceId=' + sourceId + '&categoryOptionComboId=' + categoryOptionComboId;
-    
-    var request = new Request();
-    request.setResponseTypeXML( 'message' );
-    request.setCallbackSuccess( markValueForFollowupReceived );    
-    request.send( url );
-}
-
-function markValueForFollowupReceived( messageElement )
-{   
-    var message = messageElement.firstChild.nodeValue;
-    var image = document.getElementById( 'value[' + currentFollowupId + '].followup' );
-    
-    if ( message == "marked" )
-    {
-        image.src = "../images/marked.png";
-        image.alt = i18n_unmark_value_for_followup;
-    }
-    else if ( message = "unmarked" )
-    {
-        image.src = "../images/unmarked.png";
-        image.alt = i18n_mark_value_for_followup;   
-    }
+    var dataElementId = $( '#value-' + valueId + '-de' ).val();
+    var categoryOptionComboId = $( '#value-' + valueId + '-coc' ).val();
+    var periodId = $( '#value-' + valueId + '-pe' ).val();
+    var sourceId = $( '#value-' + valueId + '-ou' ).val();
+    
+    $.ajax( {
+    	url: 'markForFollowup.action',
+    	data: { dataElementId:dataElementId, periodId:periodId, sourceId:sourceId, categoryOptionComboId:categoryOptionComboId },
+    	type: 'POST',
+    	dataType: 'json',
+    	success: function( json )
+		{
+            var $image = $( '#value-' + valueId + '-followUp' );
+			
+            if ( json.message == "marked" )
+		    {
+		        $image.attr( "src", "../images/marked.png" );
+		        $image.attr( "title", i18n_unmark_value_for_followup );
+		    }
+		    else if ( json.message == "unmarked" )
+		    {
+		        $image.attr( "src", "../images/unmarked.png" );
+		        $image.attr( "title", i18n_mark_value_for_followup );   
+		    }
+		} } );
 }
 
 // -----------------------------------------------------------------------------
 // Saver object (modified version of dataentry/javascript/general.js)
 // -----------------------------------------------------------------------------
 
-function ValueSaver( dataElementId_, periodId_, sourceId_, categoryOptionComboId_, value_, valueId_, resultColor_, selectedOption_ )
+function ValueSaver( dataElementId, periodId, organisationUnitId, categoryOptionComboId, value, valueId_, resultColor_ )
 {
     var SUCCESS = '#ccffcc';
     var ERROR = '#ccccff';
 
-    var dataElementId = dataElementId_;
-    var periodId = periodId_;
-    var sourceId = sourceId_;
-    var categoryOptionComboId = categoryOptionComboId_;
-    var value = value_;
     var valueId = valueId_;
     var resultColor = resultColor_;
-    var selecteOption = selectedOption_;
     
     this.save = function()
-    {
-        var request = new Request();
-        request.setCallbackSuccess( handleResponse );
-        request.setCallbackError( handleHttpError );
-        request.setResponseTypeXML( 'status' );
-        request.send( 'editDataValue.action?'
-        		+ 'dataElementId=' + dataElementId
-        		+ '&periodId=' + periodId
-        		+ '&organisationUnitId=' + sourceId
-        		+ '&categoryOptionComboId=' + categoryOptionComboId
-        		+ '&value=' + value );
+    {        
+        $.ajax( {
+        	url: 'editDataValue.action',
+        	data: { dataElementId:dataElementId, periodId:periodId, organisationUnitId:organisationUnitId, categoryOptionComboId:categoryOptionComboId, value:value },
+        	type: 'POST',
+    		dataType: 'json',
+        	success: function( json )
+        	{
+        		if ( json.response == "success" )
+        		{
+        			markValue( resultColor );
+        		}
+        		else
+		        {
+		            markValue( ERROR );
+		            window.alert( "Failed saving value" );
+		        }
+        	},
+        	error: function( json )
+        	{
+        		markValue( ERROR );
+        		window.alert( "Failed saving value" );
+        	}
+        } );        
     };
     
-    function handleResponse( rootElement )
-    {
-        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
-        var code = parseInt( codeElement.firstChild.nodeValue );
-        
-        if ( code == 0 )
-        {
-            markValue( resultColor );
-        }
-        else
-        {
-            markValue( ERROR );
-            window.alert( "Failed saving value." );
-        }
-    }
-    
-    function handleHttpError( errorCode )
-    {
-        markValue( ERROR );
-        window.alert( "Failed saving value." );
-    }
-    
     function markValue( color )
     {
-        var element = document.getElementById( 'value[' + valueId + '].value' );
-        element.style.backgroundColor = color;
+    	$( '#value-' + valueId + '-val' ).css( "background-color", color );
     }
 }

=== removed file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/responseStatus.vm'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/responseStatus.vm	2009-10-10 14:26:24 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/responseStatus.vm	1970-01-01 00:00:00 +0000
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<status>
-	<code>$statusCode</code>
-	<message>$message</message>
-</status>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/searchResult.vm'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/searchResult.vm	2011-03-18 14:58:26 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/searchResult.vm	2012-02-22 17:36:22 +0000
@@ -16,7 +16,7 @@
 <span id="info">$i18n.getString( "no_values_found" )</span>
 
 <input type="button" onclick="window.location.href='viewAnalysisForm.action?key=$!{key}'" value="Back" style="width:120px">
-	
+
 #else
 
 <span id="info">#if( $maxExceeded )$i18n.getString( "max_values_exceeded" ) #else$!dataValues.size() $i18n.getString( "values_found" ) #end</span>
@@ -40,7 +40,7 @@
 	#foreach( $value in $dataValues )	
 	#set( $count = $count + 1 )	
 	<tr>	
-		<td><span id="value[$count].name">$value.dataElementName $value.categoryOptionComboNameParsed</span></td>
+		<td><span id="value-${count}-name">$value.dataElementName $value.categoryOptionComboNameParsed</span></td>
 		
 		<td>$value.sourceName</td>
 		
@@ -49,23 +49,22 @@
 		<td style="text-align:center">$value.min</td>
 		
 		<td style="width:100px">
-			<input id="value[$count].value" value="$value.value"
-				style="width: 95%; text-align: center;" tabindex="$count" type="text" onchange="editValue( $count )">			
-            <input type="hidden" id="value[$count].dataElement" value="$value.dataElementId">
-            <input type="hidden" id="value[$count].period" value="$value.periodId">
-            <input type="hidden" id="value[$count].source" value="$value.sourceId">
-            <input type="hidden" id="value[$count].categoryOptionCombo" value="$value.categoryOptionComboId">
-            <input type="hidden" id="value[$count].min" value="$value.min">
-            <input type="hidden" id="value[$count].max" value="$value.max">
+			<input id="value-${count}-val" value="$value.value" style="width: 95%; text-align: center;" tabindex="$count" type="text" onchange="editValue( $count )">			
+            <input type="hidden" id="value-${count}-de" value="$value.dataElementId">
+            <input type="hidden" id="value-${count}-pe" value="$value.periodId">
+            <input type="hidden" id="value-${count}-ou" value="$value.sourceId">
+            <input type="hidden" id="value-${count}-coc" value="$value.categoryOptionComboId">
+            <input type="hidden" id="value-${count}-min" value="$value.min">
+            <input type="hidden" id="value-${count}-max" value="$value.max">
 		</td>
 		
 		<td style="text-align:center">$value.max</td>
 		
 		<td style="text-align:center">
 		#if ( $value.followup )
-			<img id="value[$count].followup" src="../images/marked.png" onclick="markValueForFollowup($count)" style="cursor:pointer">
+			<img id="value-${count}-followUp" src="../images/marked.png" onclick="markFollowUp($count)" style="cursor:pointer">
 		#else
-		    <img id="value[$count].followup" src="../images/unmarked.png" onclick="markValueForFollowup($count)" style="cursor:pointer">
+		    <img id="value-${count}-followUp" src="../images/unmarked.png" onclick="markFollowUp($count)" style="cursor:pointer">
 		#end
 		</td>		
 	</tr>