← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10501: Use header-message insteads of validate-form when to click Save button.

 

------------------------------------------------------------
revno: 10501
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-04-09 09:22:46 +0700
message:
  Use header-message insteads of validate-form when to click Save button.
modified:
  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/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 08:47:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2013-04-09 02:22:46 +0000
@@ -371,4 +371,7 @@
 save_and_close = Save and close
 delete_this_form = Delete this form
 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
+enter_a_name = Please enter a name between 4 and 150 characters long.
+save_unsuccess = Save unsuccessfully
+validate_form = Validate form
+validate_success = The registration form passed validation successfully
\ 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-08 04:21:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewPatientRegistationForm.js	2013-04-09 02:22:46 +0000
@@ -1,4 +1,5 @@
 var isSave;
+var interval = 60000;
 
 $( document ).ready( function() 
 {
@@ -30,7 +31,7 @@
 	
 	if( autoSave )
 	{
-		timeOut = window.setTimeout( "validateRegistrationFormTimeout( false );", 60000 );
+		timeOut = window.setTimeout( "validateRegistrationFormTimeout( false );", interval );
 	}
 });
 	
@@ -140,15 +141,7 @@
 		}
 	});
 	
-	return requiredFields;
-}
-
-function validateForm()
-{
-	var result = false;
 	var html = jQuery("#designTextarea").ckeditorGet().getData();
-	requiredFields = getRequiredFields();
-	
 	var input = jQuery( html ).find("input");
 	if( input.length > 0 )
 	{
@@ -171,7 +164,7 @@
 				inputKey = jQuery(item).attr('programid');
 				key = 'programid=' + inputKey
 			}
-			
+				
 			for (var idx in requiredFields){
 				if( key == idx)
 				{
@@ -179,29 +172,77 @@
 				}
 			}
 		});
+	}
 	
-	}
-	if( Object.keys(requiredFields).length > 0 ) {
-		setFieldValue('requiredField','');
-		var violate = '<h3>' + i18n_please_insert_all_required_fields + '<h3>';
+	return requiredFields;
+}
+
+function validateFormOnclick()
+{
+	setFieldValue('requiredField','');
+	var requiredFields = getRequiredFields();
+	var violate = "";
+	if( Object.keys(requiredFields).length > 0 )
+	{
+		violate = '<h3>' + i18n_please_insert_all_required_fields + '<h3>';
 		for (var idx in requiredFields){
 			violate += " - " + requiredFields[idx] + '<br>';
 		}
-		
-		setInnerHTML('validateDiv', violate);
-		jQuery('#validateDiv').dialog({
-			title:i18n_required_fields_valivation,
-			maximize:true, 
-			closable:true,
-			modal:false,
-			overlay:{background:'#000000', opacity:0.1},
-			width:500,
-			height:300
-		});
+	}
+	else
+	{
+		violate = '<h3>' + i18n_validate_success + '<h3>';
+	}
+	
+	setInnerHTML('validateDiv', violate);
+	jQuery('#validateDiv').dialog({
+		title:i18n_required_fields_valivation,
+		maximize:true, 
+		closable:true,
+		modal:false,
+		overlay:{background:'#000000', opacity:0.1},
+		width:500,
+		height:300
+	});
+}
+
+function validateForm( checkViolate )
+{
+	var result = false;
+	requiredFields = getRequiredFields();
+	
+	if( Object.keys(requiredFields).length > 0 )
+	{
+		if ( byId('autoSave').checked )
+		{
+			setHeaderMessage( i18n_save_unsuccess_please_insert_all_required_fields );
+			return;
+		}
+		else
+		{
+			setFieldValue('requiredField','');
+			var violate = '<h3>' + i18n_please_insert_all_required_fields + '<h3>';
+			for (var idx in requiredFields){
+				violate += " - " + requiredFields[idx] + '<br>';
+			}
+			
+			setInnerHTML('validateDiv', violate);
+			jQuery('#validateDiv').dialog({
+				title:i18n_required_fields_valivation,
+				maximize:true, 
+				closable:true,
+				modal:false,
+				overlay:{background:'#000000', opacity:0.1},
+				width:500,
+				height:300
+			});
+			
+		}
 		
 		return false;
 	}
-	else{
+	else
+	{
 		setFieldValue('requiredField','everything_is_ok');
 		setInnerHTML( 'designTextarea' , jQuery("#designTextarea").ckeditorGet().getData() );
 		if(isSave='true'){
@@ -330,7 +371,7 @@
 function validateRegistrationFormTimeout()
 {
 	validateDataEntryForm();
-	timeOut = window.setTimeout( "validateRegistrationFormTimeout();", 60000 );
+	timeOut = window.setTimeout( "validateRegistrationFormTimeout();", interval );
 }
 
 function validateDataEntryForm()

=== 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-08 04:21:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.vm	2013-04-09 02:22:46 +0000
@@ -101,6 +101,7 @@
         <td>
 		    <button type="button" id="saveButton" onclick="isSave='true';validateDataEntryForm();">$i18n.getString( 'save' )</button>
             <button type="submit" id="saveAndCloseButton" onclick="isSave='false';"/>$i18n.getString( 'save_and_close' )</button>
+            <button type="button" id="validateButton" onclick="validateFormOnclick();">$i18n.getString( 'validate_form' )</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>
@@ -238,11 +239,14 @@
 	var i18n_please_insert_all_required_fields = '$encoder.jsEscape( $i18n.getString( "please_insert_all_required_fields" ) , "'" )';
 	var i18n_required_fields_valivation = '$encoder.jsEscape( $i18n.getString( "required_fields_valivation" ) , "'" )';
 	var i18n_registration_date = '$encoder.jsEscape( $i18n.getString( "registration_date" ) , "'" )';
-	var i18n_full_name = '$encoder.jsEscape( $i18n.getString( "full_name" ) , "'" )';;
-	var i18n_gender = '$encoder.jsEscape( $i18n.getString( "gender" ) , "'" )';;
+	var i18n_full_name = '$encoder.jsEscape( $i18n.getString( "full_name" ) , "'" )';
+	var i18n_gender = '$encoder.jsEscape( $i18n.getString( "gender" ) , "'" )';
 	var i18n_date_of_birth = '$encoder.jsEscape( $i18n.getString( "date_of_birth" ) , "'" )';
 	var i18n_properties = '$encoder.jsEscape( $i18n.getString( "properties" ) , "'" )';
 	var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_patient_registration_form" ) , "'" )';
+	var i18n_save_unsuccess_please_insert_all_required_fields = '$encoder.jsEscape( $i18n.getString( "save_unsuccess" ) , "'" )' + '. ' + '$encoder.jsEscape( $i18n.getString( "please_insert_all_required_fields" ) , "'" )';
+	var i18n_validate_success = '$encoder.jsEscape( $i18n.getString( "validate_success" ) , "'" )';
+	
 	jQuery(document).ready(	function(){
 		openPropertiesSelector();
 	});