← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10488: Add validation for auto-save a registration form; minor fix for adding a new program.

 

------------------------------------------------------------
revno: 10488
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-04-05 15:47:47 +0700
message:
  Add validation for auto-save a registration form; minor fix for adding a new program.
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java
  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/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/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-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java	2013-03-06 14:00:44 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/AddProgramAction.java	2013-04-05 08:47:47 +0000
@@ -267,10 +267,6 @@
         program.setPatientAttributes( patientAttributes );
 
         programService.saveProgram( program );
-
-        program.setPublicAccess( "rw------" );
-        program.setUser( currentUserService.getCurrentUser() );
-        programService.updateProgram( program );
         
         if ( program.getType().equals( Program.SINGLE_EVENT_WITH_REGISTRATION )
             || program.getType().equals( Program.SINGLE_EVENT_WITHOUT_REGISTRATION ) )

=== 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:46:29 +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 08:47:47 +0000
@@ -370,4 +370,5 @@
 auto_save_data_entry_forms = Auto save data entry forms
 save_and_close = Save and close
 delete_this_form = Delete this form
-auto_save_patient_registration_forms = Auto save person registration forms 
\ No newline at end of file
+auto_save_patient_registration_forms = Auto save person registration forms
+enter_a_name = Please enter a name between 4 and 150 characters long.
\ 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:46:29 +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 08:47:47 +0000
@@ -29,7 +29,7 @@
 	
 	if( autoSave )
 	{
-		timeOut = window.setTimeout( "validateDataEntryFormTimeout( false );", 60000 );
+		timeOut = window.setTimeout( "validateRegistrationFormTimeout( false );", 60000 );
 	}
 });
 	
@@ -172,10 +172,8 @@
 			}
 			
 			for (var idx in requiredFields){
-				//var field = requiredFields[idx];
 				if( key == idx)
 				{
-					//requiredFields.splice(idx,1);
 					delete requiredFields[idx];
 				}
 			}
@@ -205,7 +203,13 @@
 	else{
 		setFieldValue('requiredField','everything_is_ok');
 		setInnerHTML( 'designTextarea' , jQuery("#designTextarea").ckeditorGet().getData() );
-		byId('saveDataEntryForm').submit();
+		if(getFieldValue('autoSave')=='true'){
+			autoSavePatientRegistrationForm();
+		}
+		else
+		{
+			byId('saveDataEntryForm').submit();
+		}
 	}
 }
 
@@ -305,8 +309,6 @@
 	oEditor.insertHtml( html );
 }
 
-
-
 // -------------------------------------------------------
 // Auto-save data entry form
 // -------------------------------------------------------
@@ -316,7 +318,7 @@
 	jQuery.postJSON("setAutoSavePatientRegistrationSetting.action", {autoSave:_autoSave}, function(json) {
 		autoSave = _autoSave;
 		if (_autoSave) {
-			window.setTimeout( "validateDataEntryFormTimeout( false );", 6000 );
+			window.setTimeout( "validateRegistrationFormTimeout( false );", 6000 );
 		}
 		else{
 			window.clearTimeout(timeOut);
@@ -324,41 +326,52 @@
 	});
 }
 
-function validateDataEntryFormTimeout()
+function validateRegistrationFormTimeout()
 {
 	validateDataEntryForm();
-	timeOut = window.setTimeout( "validateDataEntryFormTimeout();", 60000 );
+	timeOut = window.setTimeout( "validateRegistrationFormTimeout();", 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 );
-		}
-	} );
+	var name = getFieldValue('name');
+	if( name =='' || name.length<4 || name.length > 150 )
+	{
+		setHeaderDelayMessage( i18n_enter_a_name );
+	}
+	else if ( !validateForm() )
+	{
+		return;
+	}
+	else
+	{
+		$.post( 'validateDataEntryForm.action',
+		{
+			name: getFieldValue('name'),
+			dataEntryFormId: getFieldValue('dataEntryFormId')
+		}, 
+		function( json )
+		{
+			if ( json.response == 'success' )
+			{
+				autoSavePatientRegistrationForm();
+			}
+			else if ( json.response = 'error' )
+			{
+				setHeaderDelayMessage( json.message );
+			}
+		} );
+	}
 }
 
-function autoSaveDataEntryForm()
+function autoSavePatientRegistrationForm()
 {
-	$.postUTF8( 'autoSaveDataEntryForm.action',
+	$.postUTF8( 'autoSavePatientRegistrationForm.action',
 	{
 		name: getFieldValue('name'),
 		designTextarea: jQuery("#designTextarea").ckeditorGet().getData(),
 		programId: getFieldValue('programId'),
-		programStageId: getFieldValue('programStageId'),
-		dataEntryFormId: getFieldValue('dataEntryFormId')
+		id: getFieldValue('id')
 	},
 	function( json ) 
 	{

=== 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 07:46:29 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.vm	2013-04-05 08:47:47 +0000
@@ -26,9 +26,10 @@
     var i18n_dataelement_is_inserted = '$encoder.jsEscape( $i18n.getString( "dataelement_is_inserted" ) , "'" )';
 	var i18n_specify_dataelememt = '$encoder.jsEscape( $i18n.getString( "specify_dataelememt" ) , "'" )';
     var i18n_choose_existing_dataentry ='$encoder.jsEscape( $i18n.getString( "choose_existing_dataentry" ) , "'" )';
-	var i18n_dataelement = "$i18n.getString( 'dataelement' )";
+	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 i18n_enter_a_name = '$encoder.jsEscape( $i18n.getString( "enter_a_name" ) , "'" )';
 	var autoSave=${autoSave};
 	var previousName = '';
 </script>
@@ -108,7 +109,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' )
+			<input type="checkbox" id="autoSave" name="autoSave" value='$!autoSave' #if($autoSave && $autoSave=="true") checked #end onchange="setAutoSaveRegistrationSetting(this.checked)" />$i18n.getString( 'auto_save_patient_registration_forms' )
         </td>		
     </tr>
 </table>