← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10487: Add auto-save functionality in designing registration person form.

 

------------------------------------------------------------
revno: 10487
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-04-05 14:46:29 +0700
message:
  Add auto-save functionality in designing registration person form.
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/SetAutoSavePatientRegistrationSettingAction.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewPatientRegistrationFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewPatientRegistationForm.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewDataEntryForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.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-api/src/main/java/org/hisp/dhis/user/UserSettingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java	2013-04-05 07:07:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java	2013-04-05 07:46:29 +0000
@@ -52,6 +52,7 @@
     final String KEY_DB_LOCALE = "keyLocaleUserSetting";
     final String KEY_GENERATE_REPORT_INTERFACE = "keyGenerateReportInterface";
     final String AUTO_SAVE_CASE_ENTRY_FORM = "autoSaveCaseEntryForm";
+    final String AUTO_SAVE_PATIENT_REGISTRATION_ENTRY_FORM = "autoSavePatientRegistration";
     
     final List<Integer> DASHBOARD_CHARTS_TO_DISPLAY = Arrays.asList( 4, 6, 8 );
 

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/SetAutoSavePatientRegistrationSettingAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/SetAutoSavePatientRegistrationSettingAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/SetAutoSavePatientRegistrationSettingAction.java	2013-04-05 07:46:29 +0000
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2004-2009, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.patient.action.dataentryform;
+
+import org.hisp.dhis.user.UserSettingService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version SetAutoSavePatientRegistrationSettingAction.java 02:10:07 PM Apr 05, 2013 $
+ */
+public class SetAutoSavePatientRegistrationSettingAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private UserSettingService userSettingService;
+
+    public void setUserSettingService( UserSettingService userSettingService )
+    {
+        this.userSettingService = userSettingService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input / Output
+    // -------------------------------------------------------------------------
+
+    private boolean autoSave;
+
+    public void setAutoSave( boolean autoSave )
+    {
+        this.autoSave = autoSave;
+    }
+
+    // -------------------------------------------------------------------------
+    // Implementation Action
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        userSettingService.saveUserSetting( UserSettingService.AUTO_SAVE_PATIENT_REGISTRATION_ENTRY_FORM, autoSave );
+
+        return SUCCESS;
+    }
+
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewPatientRegistrationFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewPatientRegistrationFormAction.java	2013-02-26 07:29:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/dataentryform/ViewPatientRegistrationFormAction.java	2013-04-05 07:46:29 +0000
@@ -41,6 +41,7 @@
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.setting.SystemSettingManager;
+import org.hisp.dhis.user.UserSettingService;
 
 import com.opensymphony.xwork2.Action;
 
@@ -91,6 +92,13 @@
         this.systemSettingManager = systemSettingManager;
     }
 
+    private UserSettingService userSettingService;
+
+    public void setUserSettingService( UserSettingService userSettingService )
+    {
+        this.userSettingService = userSettingService;
+    }
+
     // -------------------------------------------------------------------------
     // Getters & Setters
     // -------------------------------------------------------------------------
@@ -149,6 +157,13 @@
         return flags;
     }
 
+    private boolean autoSave;
+
+    public boolean getAutoSave()
+    {
+        return autoSave;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -193,6 +208,8 @@
 
         flags = systemSettingManager.getFlags();
 
+        autoSave = (Boolean) userSettingService.getUserSetting( UserSettingService.AUTO_SAVE_PATIENT_REGISTRATION_ENTRY_FORM, false );
+
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2013-04-05 07:07:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml	2013-04-05 07:46:29 +0000
@@ -562,6 +562,16 @@
 		<property name="systemSettingManager">
 			<ref bean="org.hisp.dhis.setting.SystemSettingManager" />
 		</property>
+		<property name="userSettingService">
+			<ref bean="org.hisp.dhis.user.UserSettingService" />
+		</property>
+	</bean>
+	
+	<bean
+		id="org.hisp.dhis.patient.action.dataentryform.SetAutoSavePatientRegistrationSettingAction"
+		class="org.hisp.dhis.patient.action.dataentryform.SetAutoSavePatientRegistrationSettingAction"
+		scope="prototype">
+		<property name="userSettingService" ref="org.hisp.dhis.user.UserSettingService" />
 	</bean>
 
 	<!-- Patient Attribute Group -->

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2013-04-05 07:07:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2013-04-05 07:46:29 +0000
@@ -369,4 +369,5 @@
 last_12_month = Last 12 months
 auto_save_data_entry_forms = Auto save data entry forms
 save_and_close = Save and close
-delete_this_form = Delete this form 
\ No newline at end of file
+delete_this_form = Delete this form
+auto_save_patient_registration_forms = Auto save person registration forms 
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2013-04-05 07:07:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml	2013-04-05 07:46:29 +0000
@@ -573,6 +573,13 @@
 			<result name="success" type="redirect">patientRegistrationForm.action
 			</result>
 		</action>
+		
+		<action name="autoSavePatientRegistrationForm"
+			class="org.hisp.dhis.patient.action.dataentryform.SavePatientRegistrationFormAction">
+			<result name="success" type="velocity-json">
+				/dhis-web-commons/ajax/jsonResponseSuccess.vm
+			</result>
+		</action>
 
 		<action name="delRegistrationFormAction"
 			class="org.hisp.dhis.patient.action.dataentryform.DelRegistrationFormAction">
@@ -592,6 +599,13 @@
 				/dhis-web-maintenance-patient/dataEntryFormCode.vm
 			</result>
 		</action>
+		
+		<action name="setAutoSavePatientRegistrationSetting"
+			class="org.hisp.dhis.patient.action.dataentryform.SetAutoSavePatientRegistrationSettingAction">
+			<result name="success" type="velocity-json">
+				../dhis-web-commons/ajax/jsonResponseSuccess.vm
+			</result>
+		</action>
 
 		<!-- Patient Attribute Group -->
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js	2013-04-05 07:07:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js	2013-04-05 07:46:29 +0000
@@ -60,6 +60,11 @@
 			resizable: false
 		});
 	});
+	
+	if( autoSave )
+	{
+		timeOut = window.setTimeout( "validateDataEntryFormTimeout( false );", 60000 );
+	}
 });
 
 function openOtherProgramStageDataElements()
@@ -358,4 +363,4 @@
 	{
 		setHeaderDelayMessage( i18n_save_success ); 
 	} );
-}
\ No newline at end of file
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewPatientRegistationForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewPatientRegistationForm.js	2013-04-05 07:07:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewPatientRegistationForm.js	2013-04-05 07:46:29 +0000
@@ -26,6 +26,11 @@
 			position: [$("body").width()- 50, 0],
 		});
 	});
+	
+	if( autoSave )
+	{
+		timeOut = window.setTimeout( "validateDataEntryFormTimeout( false );", 60000 );
+	}
 });
 	
 function openPropertiesSelector()
@@ -300,19 +305,63 @@
 	oEditor.insertHtml( html );
 }
 
-// --------------------------------------------------------------------------
-// Auto-save
-// --------------------------------------------------------------------------
-
-function setAutoSaveSetting(_autoSave)
+
+
+// -------------------------------------------------------
+// Auto-save data entry form
+// -------------------------------------------------------
+
+function setAutoSaveRegistrationSetting(_autoSave)
 {
-	jQuery.postJSON("setAutoSaveSetting.action", {autoSave:_autoSave}, function(json) {
+	jQuery.postJSON("setAutoSavePatientRegistrationSetting.action", {autoSave:_autoSave}, function(json) {
 		autoSave = _autoSave;
 		if (_autoSave) {
-			window.setTimeout( "validateDataEntryFormTimeout( false );", 60000 );
+			window.setTimeout( "validateDataEntryFormTimeout( false );", 6000 );
 		}
 		else{
 			window.clearTimeout(timeOut);
 		}
 	});
 }
+
+function validateDataEntryFormTimeout()
+{
+	validateDataEntryForm();
+	timeOut = window.setTimeout( "validateDataEntryFormTimeout();", 60000 );
+}
+
+function validateDataEntryForm()
+{
+	$.post( 'validateDataEntryForm.action',
+	{
+		name: getFieldValue('name'),
+		dataEntryFormId: getFieldValue('dataEntryFormId')
+	}, 
+	function( json )
+	{
+		if ( json.response == 'success' )
+		{
+			autoSaveDataEntryForm();
+		}
+		else if ( json.response = 'error' )
+		{
+			setHeaderDelayMessage( json.message );
+		}
+	} );
+}
+
+function autoSaveDataEntryForm()
+{
+	$.postUTF8( 'autoSaveDataEntryForm.action',
+	{
+		name: getFieldValue('name'),
+		designTextarea: jQuery("#designTextarea").ckeditorGet().getData(),
+		programId: getFieldValue('programId'),
+		programStageId: getFieldValue('programStageId'),
+		dataEntryFormId: getFieldValue('dataEntryFormId')
+	},
+	function( json ) 
+	{
+		setHeaderDelayMessage( i18n_save_success ); 
+	} );
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewDataEntryForm.vm	2013-04-05 07:07:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewDataEntryForm.vm	2013-04-05 07:46:29 +0000
@@ -21,6 +21,7 @@
 	var i18n_dataelement = '$encoder.jsEscape( $i18n.getString( "dataelement" ) , "'" )';
 	var i18n_dataelement_of_orther_program_stage = "$i18n.getString( 'dataelement_of_orther_program_stage' )";
 	var i18n_save_success = '$encoder.jsEscape( $i18n.getString( "save_success" ) , "'" )';
+	var autoSave=${autoSave};
 	var previousName = '';
 </script>
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.vm	2013-04-05 02:48:22 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.vm	2013-04-05 07:46:29 +0000
@@ -28,7 +28,8 @@
     var i18n_choose_existing_dataentry ='$encoder.jsEscape( $i18n.getString( "choose_existing_dataentry" ) , "'" )';
 	var i18n_dataelement = "$i18n.getString( 'dataelement' )";
 	var i18n_dataelement_of_orther_program_stage = "$i18n.getString( 'dataelement_of_orther_program_stage' )";
-	
+	var i18n_save_success = '$encoder.jsEscape( $i18n.getString( "save_success" ) , "'" )';
+	var autoSave=${autoSave};
 	var previousName = '';
 </script>
 
@@ -97,7 +98,8 @@
 <table width="100%">	
     <tr>
         <td>
-		    <button type="submit" id="saveButton"/>$i18n.getString( 'save' )</button>
+		    <button type="button" id="saveButton" onclick="validateDataEntryForm();">$i18n.getString( 'save' )</button>
+            <button type="submit" id="saveAndCloseButton"/>$i18n.getString( 'save_and_close' )</button>
             <button type="button" id="cancelButton" onclick="window.location='patientRegistrationForm.action'">$i18n.getString( 'cancel' )</button>
 			&nbsp;&nbsp;<span style="color:#606060">|</span>&nbsp;
 		    <button type="button" id="propertiesButton" onclick="openPropertiesSelector()"/>$i18n.getString( 'insert_properties' )</button>
@@ -106,6 +108,7 @@
 			&nbsp;&nbsp;<span style="color:#606060">|</span>&nbsp;
 		    <button type="button" id="deleteButton" onclick="deleteRegistrationForm( $registrationForm.id, '$registrationForm.dataEntryForm.name' )" />$i18n.getString( 'delete' )</button>
 			#end
+			<input type="checkbox" id="autoSave" name="autoSave" #if($autoSave && $autoSave=="true") checked #end onchange="setAutoSaveRegistrationSetting(this.checked)" />$i18n.getString( 'auto_save_patient_registration_forms' )
         </td>		
     </tr>
 </table>