← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6705: Improved performance when saving custom forms. Fixed bug with encoding of form html.

 

------------------------------------------------------------
revno: 6705
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-04-23 15:42:38 +0200
message:
  Improved performance when saving custom forms. Fixed bug with encoding of form html.
removed:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/responseMismatch.vm
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonResponseSuccess.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/dataEntryForm.js
  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/viewDataEntryForm.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-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonResponseSuccess.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonResponseSuccess.vm	2012-02-17 12:29:45 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonResponseSuccess.vm	2012-04-23 13:42:38 +0000
@@ -1,5 +1,5 @@
 {
   "response": "success",
   "message": "$!encoder.jsonEncode( ${message} )"
-   #if( $statusCode ),"status": $statusCode#end
+   #if( $statusCode ),"status": ${statusCode}#end
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/struts.xml	2012-02-24 05:14:52 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/struts.xml	2012-04-23 13:42:38 +0000
@@ -186,9 +186,8 @@
     </action>
 
     <action name="validateDataEntryForm" class="org.hisp.dhis.dataset.action.dataentryform.ValidateDataEntryFormAction">
-      <result name="success" type="velocity-xml">/dhis-web-maintenance-dataset/responseSuccess.vm</result>
-      <result name="input" type="velocity-xml">/dhis-web-maintenance-dataset/responseInput.vm</result>
-      <result name="mismatch" type="velocity-xml">/dhis-web-maintenance-dataset/responseMismatch.vm</result>
+      <result name="success" type="velocity-json">../dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+      <result name="input" type="velocity-json">../dhis-web-commons/ajax/jsonResponseInput.vm</result>
       <param name="onExceptionReturn">plainTextError</param>
     </action>
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/dataEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/dataEntryForm.js	2012-04-23 10:45:46 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/dataEntryForm.js	2012-04-23 13:42:38 +0000
@@ -5,12 +5,12 @@
 
 function removeDataEntryForm( dataSetIdField, dataEntryFormId, dataEntryFormName )
 {
-  var result = window.confirm( i18n_confirm_delete + '\n\n' + dataEntryFormName );
+	var result = window.confirm( i18n_confirm_delete + '\n\n' + dataEntryFormName );
 
-  if ( result )
-  {
-	window.location.href = 'delDataEntryForm.action?dataSetId=' + dataSetIdField + "&dataEntryFormId=" + dataEntryFormId;
-  }
+	if ( result )
+	{
+		window.location.href = 'delDataEntryForm.action?dataSetId=' + dataSetIdField + "&dataEntryFormId=" + dataEntryFormId;
+	}
 }
 
 // ----------------------------------------------------------------------
@@ -20,48 +20,34 @@
 function validateDataEntryForm()
 {  
 	$.postUTF8( 'validateDataEntryForm.action',
-		{
-			name: byId( 'nameField' ).value,
-			dataSetId: byId( 'dataSetIdField' ).value,
-			dataEntryFormId: dataEntryFormId
-		}
-		, function( xmlObject ) 
-		{
-			if(autoSave == false)
-			{
-				dataEntryFormValidationCompleted(xmlObject);
-			}
-			else
-			{
-				autoSaveDataEntryFormValidationCompleted(xmlObject);
-			}
-		} );
+	{
+		name: $( '#nameField' ).val(),
+		dataSetId: $( '#dataSetIdField' ).val(),
+		dataEntryFormId: dataEntryFormId
+	}, 
+	function( json ) 
+	{
+		if ( autoSave == false )
+		{
+			dataEntryFormValidationCompleted( json );
+		}
+		else
+		{
+			autoSaveDataEntryFormValidationCompleted( json );
+		}
+	} );
 }
 
-function dataEntryFormValidationCompleted( messageElement )
+function dataEntryFormValidationCompleted( json )
 {
-  messageElement = messageElement.getElementsByTagName( 'message' )[0];
-  var type = messageElement.getAttribute( 'type' );
-  var message = messageElement.firstChild.nodeValue;
-
-  if ( type == 'success' )
-  {  
-      document.forms['saveDataEntryForm'].submit();
-  }
-  else if ( type == 'input' )
-  {
-    document.getElementById( 'message' ).innerHTML = message;
-    document.getElementById( 'message' ).style.display = 'block';
-  }
-  else if ( type == 'mismatch' )
-  {
-    var result = window.confirm( message );
-
-    if ( result )
-    {
-      document.forms['saveDataEntryForm'].submit();
-    }
-  }
+	if ( json.response == 'success' )
+	{  
+		$( '#saveDataEntryForm' ).submit();
+	}
+	else if ( json.response = 'input' )
+	{
+		setHeaderDelayMessage( json.message );
+	}
 }
 
 // -----------------------------------------------------------------------------
@@ -102,48 +88,35 @@
 // Auto-save DataEntryForm
 // -----------------------------------------------------------------------------
 
-function autoSaveDataEntryFormValidationCompleted( messageElement )
+function autoSaveDataEntryFormValidationCompleted( json )
 {
-  messageElement = messageElement.getElementsByTagName( 'message' )[0];
-  var type = messageElement.getAttribute( 'type' );
-  var message = messageElement.firstChild.nodeValue;
-
-  if ( type == 'success' )
-  {
-     autoSaveDataEntryForm();
-  }
-  else if ( type == 'input' )
-  {
-	 setMessage( message );
-  }
-  else if ( type == 'mismatch' )
-  {
-    var result = window.confirm( message );
-
-    if ( result )
-    {
-      autoSaveDataEntryForm();
-    }
-  }
+	if ( json.response == 'success' )
+	{
+		autoSaveDataEntryForm();
+	}
+	else if ( json.response = 'input' )
+	{
+		setHeaderDelayMessage( json.message );
+	}
 }
 
 function autoSaveDataEntryForm() 
 {
 	var field = $("#designTextarea").ckeditorGet();
-	var designTextarea = htmlEncode(field.getData());
+	var designTextarea = field.getData();
 	
 	$.postUTF8( 'autoSaveDataEntryForm.action',
-		{
-			nameField: getFieldValue('nameField'),
-			designTextarea: designTextarea,
-			dataSetIdField: getFieldValue('dataSetIdField'),
-			dataEntryFormId: dataEntryFormId
-		}
-		, function( xmlObject ) 
-		{
-			setMessage(i18n_save_success); 
-			stat = "EDIT";
-			dataEntryFormId = xmlObject.getElementsByTagName( 'message' )[0].firstChild.nodeValue;
-			enable('delete');
-		} );
+	{
+		nameField: getFieldValue('nameField'),
+		designTextarea: designTextarea,
+		dataSetIdField: getFieldValue('dataSetIdField'),
+		dataEntryFormId: dataEntryFormId
+	},
+	function( xmlObject ) 
+	{
+		setHeaderDelayMessage( i18n_save_success ); 
+		stat = "EDIT";
+		dataEntryFormId = xmlObject.getElementsByTagName( 'message' )[0].firstChild.nodeValue;
+		enable('delete');
+	} );
 }
\ 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	2012-01-19 11:52:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js	2012-04-23 13:42:38 +0000
@@ -1,11 +1,5 @@
-$(document).ready(function() {
-	validation2('saveDataEntryForm', function() {
-		autoSave = false;
-		validateDataEntryForm();
-	}, {
-		'rules' : getValidationRules("dataEntry")
-	});
-
+$( document ).ready( function() {
+	
 	leftBar.hideAnimated();
 
 	$("#selectionDialog").dialog({
@@ -197,7 +191,7 @@
 function showThenFadeOutMessage( message )
 {
 	$("#message_").html(message);
-	$("#message_").fadeOut(1000, function() {
+	$("#message_").fadeOut(3000, function() {
 		$("#message_").html("");
 		$("#message_").show();
 	});

=== removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/responseMismatch.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/responseMismatch.vm	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/responseMismatch.vm	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<message type="mismatch">$encoder.xmlEncode( $message )</message>
\ 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/viewDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm	2012-04-16 13:41:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm	2012-04-23 13:42:38 +0000
@@ -28,7 +28,7 @@
 				return option;
 			},
 			params: {
-				dataSetId: $dataSet.id
+				dataSetId: ${dataSet.id}
 			}
 		});
 
@@ -44,7 +44,7 @@
 				return option;
 			},
 			params: {
-				dataSetId: $dataSet.id
+				dataSetId: ${dataSet.id}
 			}
 		});
 
@@ -143,7 +143,7 @@
     <tr>
       <td>
 	    <button type="button" id="saveButton" name="save" onclick="autoSave = true; validateDataEntryForm(); autoSave = '$!autoSave';">$i18n.getString( 'save' )</button>
-        <button type="submit" id="saveCloseButton" name="saveClose">$i18n.getString( 'save_close' )</button>
+        <button type="button" id="saveCloseButton" name="saveClose" onclick="autoSave = false; validateDataEntryForm();">$i18n.getString( 'save_close' )</button>
         <button type="button" id="cancelButton" name="cancel" onclick="window.location.href='dataSet.action'">$i18n.getString( 'cancel' )</button>&nbsp;&nbsp;<span style="color:#606060">|</span>&nbsp;
         <button type="button" id="showSelectionBoxButton" name="showselectionbox">$i18n.getString( 'show_selection_box' )</button>&nbsp;&nbsp;<span style="color:#606060">|</span>&nbsp;
         <button type="button" id="delete" name="delete" onclick="removeDataEntryForm( '$dataSet.id', '$dataEntryForm.id', '$dataEntryForm.name' )">$i18n.getString( 'delete' )</button>
@@ -159,7 +159,6 @@
 		}
 	  </script>
     </tr>
-	<tr><td><span id="message"></span></td></tr>
   </table>
   <input type="hidden" name="dataSetIdField" id="dataSetIdField" value="$dataSet.id" />
 </form>