← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6715: Fixed auto save custom form function

 

------------------------------------------------------------
revno: 6715
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-04-23 22:19:49 +0200
message:
  Fixed auto save custom form function
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java
  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/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-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java	2012-01-20 10:38:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java	2012-04-23 20:19:49 +0000
@@ -142,7 +142,6 @@
             .getHtmlCode(), i18n ) : "";
 
         autoSave = (Boolean) userSettingService.getUserSetting( UserSettingService.AUTO_SAVE_DATA_ENTRY_FORM, false );
-
         
         dataElementList = new ArrayList<DataElement>( dataSet.getDataElements() );
 

=== 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 14:26:57 +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 20:19:49 +0000
@@ -17,56 +17,35 @@
 // Validation
 // ----------------------------------------------------------------------
 
-function validateDataEntryForm()
-{  
-	$.postUTF8( 'validateDataEntryForm.action',
+function validateDataEntryForm( exit )
+{
+	$.post( 'validateDataEntryForm.action',
 	{
 		name: $( '#nameField' ).val(),
 		dataSetId: $( '#dataSetIdField' ).val(),
 		dataEntryFormId: dataEntryFormId
 	}, 
-	function( json ) 
+	function( json )
 	{
-		if ( autoSave == false )
+		if ( json.response == 'success' )
 		{
-			dataEntryFormValidationCompleted( json );
+			if ( exit )
+			{
+				$( '#saveDataEntryForm' ).submit();
+			}			
+			else
+			{
+				saveDataEntryForm();
+			}
 		}
-		else
+		else if ( json.response = 'input' )
 		{
-			autoSaveDataEntryFormValidationCompleted( json );
+			setHeaderDelayMessage( json.message );
 		}
 	} );
 }
 
-function dataEntryFormValidationCompleted( json )
-{
-	if ( json.response == 'success' )
-	{  
-		$( '#saveDataEntryForm' ).submit();
-	}
-	else if ( json.response = 'input' )
-	{
-		setHeaderDelayMessage( json.message );
-	}
-}
-
-// -----------------------------------------------------------------------------
-// Auto-save DataEntryForm
-// -----------------------------------------------------------------------------
-
-function autoSaveDataEntryFormValidationCompleted( json )
-{
-	if ( json.response == 'success' )
-	{
-		autoSaveDataEntryForm();
-	}
-	else if ( json.response = 'input' )
-	{
-		setHeaderDelayMessage( json.message );
-	}
-}
-
-function autoSaveDataEntryForm() 
+function saveDataEntryForm() 
 {
 	var field = $("#designTextarea").ckeditorGet();
 	var designTextarea = field.getData();
@@ -85,4 +64,10 @@
 		dataEntryFormId = json.message;
 		enable('delete');
 	} );
-}
\ No newline at end of file
+}
+
+function validateDataEntryFormTimeout()
+{
+	validateDataEntryForm( false );
+	window.setTimeout( "validateDataEntryFormTimeout();", 60000 );
+}

=== 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-23 13:42:38 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm	2012-04-23 20:19:49 +0000
@@ -1,14 +1,7 @@
 <script type="text/javascript" src="javascript/viewDataEntryForm.js"></script>
 <script type="text/javascript">
-	jQuery(document).ready(function() {
-		if('$autoSave' == 'true'){
-			if (!timer_is_on)
-			  {
-				  timer_is_on=1;
-				  timedCount();
-			  }
-		}
-
+	jQuery(document).ready(function() 
+	{
 		jQuery('#designTextarea').ckeditor();
 		jQuery("#designTextarea").ckeditorGet().setData('$encoder.jsEscape( $dataEntryValue, "'" )');
 
@@ -60,21 +53,24 @@
 				return option;
 			},
 			params: {
-				dataSetId: $dataSet.id
+				dataSetId: ${dataSet.id}
 			}
 		});
+				
+		if( '${autoSave}' == 'true' )
+		{
+			window.setTimeout( "validateDataEntryFormTimeout( false );", 60000 );
+		}		
 	});
 
     var stat = "ADD";
     var dataEntryFormId = -1;
 	var selected = null;
-	var autoSave = $autoSave;
-	var t;
-	var timer_is_on = 0;
+	var autoSave = ${autoSave};
 
 	#if( $dataEntryForm )
     stat = "EDIT";
-    dataEntryFormId = $dataEntryForm.id;
+    dataEntryFormId = ${dataEntryForm.id};
     #end
 
     var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "dataentryform_confirm_delete" ) , "'" )';
@@ -142,8 +138,8 @@
     </tr>
     <tr>
       <td>
-	    <button type="button" id="saveButton" name="save" onclick="autoSave = true; validateDataEntryForm(); autoSave = '$!autoSave';">$i18n.getString( 'save' )</button>
-        <button type="button" id="saveCloseButton" name="saveClose" onclick="autoSave = false; validateDataEntryForm();">$i18n.getString( 'save_close' )</button>
+	    <button type="button" id="saveButton" name="save" onclick="validateDataEntryForm( false )">$i18n.getString( 'save' )</button>
+        <button type="button" id="saveCloseButton" name="saveClose" onclick="validateDataEntryForm( true )">$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>
@@ -160,7 +156,7 @@
 	  </script>
     </tr>
   </table>
-  <input type="hidden" name="dataSetIdField" id="dataSetIdField" value="$dataSet.id" />
+  <input type="hidden" name="dataSetIdField" id="dataSetIdField" value="${dataSet.id}" />
 </form>
 
 <div id="selectionDialog" title="Selection Box">