← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3542: JQuerification in data entry

 

Merge authors:
  Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 3542 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2011-05-08 21:23:07 +0200
message:
  JQuerification in data entry
modified:
  dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml
  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/history.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/status.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.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/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml	2011-04-24 10:11:07 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml	2011-05-08 19:22:16 +0000
@@ -59,13 +59,13 @@
 		</action>
 
 		<action name="saveValue" class="org.hisp.dhis.de.action.SaveValueAction">
-			<result name="success" type="velocity">status.vm</result>
+			<result name="success" type="velocity-json">/dhis-web-dataentry/status.vm</result>
 			<param name="onExceptionReturn">plainTextError</param>
 			<param name="requiredAuthorities">F_DATAVALUE_ADD,F_DATAVALUE_UPDATE,F_DATAVALUE_DELETE</param>
 		</action>
 
 		<action name="saveComment" class="org.hisp.dhis.de.action.SaveCommentAction">
-			<result name="success" type="velocity">status.vm</result>
+			<result name="success" type="velocity-json">/dhis-web-dataentry/status.vm</result>
 			<param name="onExceptionReturn">plainTextError</param>
 			<param name="requiredAuthorities">F_DATAVALUE_ADD,F_DATAVALUE_UPDATE,F_DATAVALUE_DELETE</param>
 		</action>

=== 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-05-07 14:07:03 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js	2011-05-08 19:22:16 +0000
@@ -7,6 +7,9 @@
 var COLOR_YELLOW = '#fffe8c';
 var COLOR_RED = '#ff8a8a';
 
+/**
+/* Used by default and section forms.
+*/
 function saveVal( dataElementId, optionComboId )
 {
 	var dataElementName = document.getElementById( 'value[' + dataElementId + '].name' ).innerHTML;
@@ -14,6 +17,9 @@
 	saveValue( dataElementId, optionComboId, dataElementName, null );
 }
 
+/**
+/* Used by custom forms.
+*/
 function saveValue( dataElementId, optionComboId, dataElementName )
 {
     var field = document.getElementById( 'value[' + dataElementId + '].value' + ':' +  'value[' + optionComboId + '].value');
@@ -154,18 +160,15 @@
     
     this.save = function()
     {
-        var request = new Request();
-        request.setCallbackSuccess( handleResponse );
-        request.setCallbackError( handleHttpError );
-        request.setResponseTypeXML( 'status' );        
-        request.send( 'saveValue.action?organisationUnitId=' + organisationUnitId + '&dataElementId=' +
-                dataElementId + '&optionComboId=' + optionComboId + '&value=' + value );
+        var url = 'saveValue.action?organisationUnitId=' + organisationUnitId + '&dataElementId=' +
+                dataElementId + '&optionComboId=' + optionComboId + '&value=' + value;
+                
+        $.ajax( { url: url, dataType: 'json', success: handleResponse, error: handleError } );
     };
     
-    function handleResponse( rootElement )
+    function handleResponse( json )
     {
-        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
-        var code = parseInt( codeElement.firstChild.nodeValue );
+        var code = json.code;
         
         if ( code == 0 )
         {
@@ -178,10 +181,10 @@
         }
     }
     
-    function handleHttpError( errorCode )
+    function handleError( jqXHR, textStatus, errorThrown )
     {
         markValue( COLOR_RED );
-        window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
+        window.alert( i18n_saving_value_failed_error_code + '\n\n' + textStatus );
     }   
     
     function markValue( color )

=== 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	2011-04-12 19:30:34 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js	2011-05-08 19:22:16 +0000
@@ -68,19 +68,16 @@
     
     this.save = function()
     {
-        var request = new Request();
-        request.setCallbackSuccess( handleResponse );
-        request.setCallbackError( handleHttpError );
-        request.setResponseTypeXML( 'status' );
-        request.send( 'saveComment.action?organisationUnitId=' + organisationUnitId + '&dataElementId=' +
-                dataElementId + '&optionComboId=' + optionComboId + '&comment=' + value );
+        var url = 'saveComment.action?organisationUnitId=' + organisationUnitId + '&dataElementId=' +
+                dataElementId + '&optionComboId=' + optionComboId + '&comment=' + value;
+        
+        $.ajax( { url: url, dataType: 'json', success: handleResponse, error: handleError } );
     };
     
-    function handleResponse( rootElement )
+    function handleResponse( json )
     {
-        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
-        var code = parseInt( codeElement.firstChild.nodeValue );
-        
+    	var code = json.code;
+    	
         if ( code == 0 )
         {
             markComment( SUCCESS );           
@@ -92,10 +89,10 @@
         }
     }
     
-    function handleHttpError( errorCode )
+    function handleError( jqXHR, textStatus, errorThrown )
     {
         markComment( ERROR );
-        window.alert( i18n_saving_comment_failed_error_code + '\n\n' + errorCode );
+        window.alert( i18n_saving_comment_failed_error_code + '\n\n' + textStatus );
     }
     
     function markComment( color )

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/status.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/status.vm	2011-01-25 16:14:19 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/status.vm	2011-05-08 19:22:16 +0000
@@ -1,3 +1,1 @@
-<status>
-	<code>$statusCode</code>
-</status>
+{ "code": "${statusCode}" }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js	2011-05-07 22:34:06 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js	2011-05-08 18:59:01 +0000
@@ -67,7 +67,8 @@
 		html = "<input title=\"" + titleValue
 				+ "\" value=\"" + displayName + "\" id=\"" + boolDataEntryId
 				+ "\" style=\"width:4em;text-align:center\"/>";
-	} else {
+	} 
+	else {
 		id = dataEntryId;
 		html = "<input title=\"" + titleValue
 				+ "\" value=\"" + displayName + "\" id=\"" + dataEntryId
@@ -77,7 +78,8 @@
 	if (checkExisted(id)) {
 		jQuery("#message_").html("<b>" + i18n_dataelement_is_inserted + "</b>");
 		return;
-	} else {
+	}
+	else {
 		jQuery("#message_").html("");
 	}