dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21089
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9892: (Patient registration form) Add validation for fields into the custom form.
------------------------------------------------------------
revno: 9892
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-02-25 14:12:31 +0700
message:
(Patient registration form) Add validation for fields into the custom form.
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/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/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-02-21 03:26:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties 2013-02-25 07:12:31 +0000
@@ -351,4 +351,5 @@
avg_dataelement_value = Average of data element values
min_dataelement_value = Minimum of data element values
max_dataelement_value = Maximum of data element values
-assign_program_to_userroles = Assign program to userroles
\ No newline at end of file
+assign_program_to_userroles = Assign program to userroles
+property_is_inserted = The property is inserted
\ 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/viewDataEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js 2013-01-29 14:45:08 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewDataEntryForm.js 2013-02-25 07:12:31 +0000
@@ -132,7 +132,6 @@
function insertDataElement( source, programStageId )
{
- var oEditor = jQuery("#designTextarea").ckeditorGet();
var dataElement = JSON.parse( jQuery( source + ' #dataElementIds').val() );
if( dataElement == null )
@@ -177,10 +176,11 @@
jQuery( source + " #message_").html( "<span class='bold'>" + i18n_dataelement_is_inserted + "</span>" );
return;
}else{
+ var oEditor = jQuery("#designTextarea").ckeditorGet();
+ oEditor.insertHtml( htmlCode );
jQuery( source + " #message_").html("");
}
- oEditor.insertHtml( htmlCode );
}
=== 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-02-02 10:34:22 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/viewPatientRegistationForm.js 2013-02-25 07:12:31 +0000
@@ -9,9 +9,8 @@
modal:false,
overlay:{background:'#000000', opacity:0.1},
width:500,
- height:400
+ height:460
});
- showById('fixedAttrTab');
}
function fixAttrOnClick()
@@ -46,9 +45,110 @@
showById('programAttrTab');
}
+function validateForm()
+{
+ var result = false;
+ var html = jQuery("#designTextarea").ckeditorGet().getData();
+
+ var requiredFields = new Array();
+ requiredFields.push('fixedattributeid=registrationDate');
+ requiredFields.push('fixedattributeid=fullName');
+ requiredFields.push('fixedattributeid=gender');
+ requiredFields.push('fixedattributeid=birthDate');
+
+ jQuery('#identifiersSelector option').each(function() {
+ var item = jQuery(this);
+ if( item.attr('mandatory')=='true'){
+ requiredFields.push('identifierid=' + item.val());
+ }
+ });
+
+ jQuery('#attributesSelector option').each(function() {
+ var item = jQuery(this);
+ if( item.attr('mandatory')=='true'){
+ requiredFields.push('attributeid=' + item.val());
+ }
+ });
+
+ var input = jQuery( html ).find("input");
+ if( input.length > 0 )
+ {
+ input.each( function(i, item){
+ var key = "";
+ var inputKey = jQuery(item).attr('fixedattributeid');
+ if( inputKey!=undefined)
+ {
+ key = 'fixedattributeid=' + inputKey
+ }
+ else if( jQuery(item).attr('identifierid')!=undefined ){
+ inputKey = jQuery(item).attr('identifierid');
+ key = 'identifierid=' + inputKey
+ }
+ else if( jQuery(item).attr('attributeid')!=undefined ){
+ inputKey = jQuery(item).attr('attributeid');
+ key = 'attributeid=' + inputKey
+ }
+ else if( jQuery(item).attr('programid')!=undefined ){
+ inputKey = jQuery(item).attr('programid');
+ key = 'programid=' + inputKey
+ }
+
+ for (var idx=0; idx<requiredFields.length; idx++){
+ var field = requiredFields[idx];
+ if( key == field)
+ {
+ requiredFields.splice(idx,1);
+ }
+ }
+ });
+
+ }
+ if( requiredFields.length > 0 ) {
+ setFieldValue('requiredField','');
+ return false;
+ }
+ else{
+ setFieldValue('requiredField','everything_is_ok');
+ setInnerHTML( 'designTextarea' , jQuery("#designTextarea").ckeditorGet().getData() );
+ byId('saveDataEntryForm').submit();
+ }
+}
+
+function checkExisted( id )
+{
+ var result = false;
+ var html = jQuery("#designTextarea").ckeditorGet().getData();
+ var input = jQuery( html ).find("input");
+
+ input.each( function(i, item){
+ var key = "";
+ var inputKey = jQuery(item).attr('fixedattributeid');
+ if( inputKey!=undefined)
+ {
+ key = 'fixedattributeid="' + inputKey + '"';
+ }
+ else if( jQuery(item).attr('identifierid')!=undefined ){
+ inputKey = jQuery(item).attr('identifierid');
+ key = 'identifierid="' + inputKey + '"';
+ }
+ else if( jQuery(item).attr('attributeid')!=undefined ){
+ inputKey = jQuery(item).attr('attributeid');
+ key = 'attributeid="' + inputKey + '"';
+ }
+ else if( jQuery(item).attr('programid')!=undefined ){
+ inputKey = jQuery(item).attr('programid');
+ key = 'programid="' + inputKey + '"';
+ }
+
+ if( id == key ) result = true;
+
+ });
+
+ return result;
+}
+
function insertElement( type )
{
- var oEditor = jQuery("#designTextarea").ckeditorGet();
var id = '';
var value = '';
if( type == 'fixedAttr' ){
@@ -74,5 +174,13 @@
var htmlCode = "<input " + id + " value=\"[" + value + "]\" title=\"" + value + "\">";
- oEditor.insertHtml( htmlCode );
+ if( checkExisted( id ) ){
+ setMessage( "<span class='bold'>" + i18n_property_is_inserted + "</span>" );
+ return;
+ }else{
+ var oEditor = jQuery("#designTextarea").ckeditorGet();
+ oEditor.insertHtml( htmlCode );
+ setMessage("");
+ }
+
}
=== 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-02-20 15:10:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/viewPatientRegistationForm.vm 2013-02-25 07:12:31 +0000
@@ -7,7 +7,7 @@
setInnerHTML( 'designTextarea' , jQuery("#designTextarea").ckeditorGet().getData() );
form.submit();
} );
-
+
jQuery('#designTextarea').ckeditor();
#if($!registrationForm)
jQuery("#designTextarea").ckeditorGet().setData('$encoder.jsEscape( $!registrationForm.dataEntryForm.htmlCode, "'" )');
@@ -42,7 +42,7 @@
}
</style>
-<form id="saveDataEntryForm" name="saveDataEntryForm" action="savePatientRegistrationForm.action" method="post">
+<form id="saveDataEntryForm" name="saveDataEntryForm" action="savePatientRegistrationForm.action" method="post" onsubmit="validateForm();">
<input type="hidden" name="id" id="id" value="$!registrationForm.id"/>
<input type="hidden" name="programId" id="programId" value="$!programId"/>
@@ -82,6 +82,9 @@
</div>
</td>
</tr>
+ <tr>
+ <td><input type='hidden' id='requiredField' name='requiredField' class="{validate:{required:true}}"></td>
+ </tr>
</table>
</div>
@@ -100,7 +103,7 @@
</form>
<div id='selectionDialog' class='hidden'>
- <table id="fixedAttrTab" class='hidden'>
+ <table id="fixedAttrTab">
<tr>
<td>
<input type='text' placeholder="$i18n.getString('filter')" style="width:278px;">
@@ -111,12 +114,12 @@
<tr>
<td>
<select id="fixedAttrSelector" multiple="multiple" style="width:450px;height:270px" ondblclick="insertElement( 'fixedAttr' )">
- <option value="fullName">$i18n.getString('full_name')</option>
- <option value="gender">$i18n.getString('gender')</option>
- <option value="birthDate">$i18n.getString('birth_date')</option>
+ <option value="registrationDate" class="bold">$i18n.getString('registration_date')</option>
+ <option value="fullName" class="bold">$i18n.getString('full_name')</option>
+ <option value="gender" class="bold">$i18n.getString('gender')</option>
+ <option value="birthDate" class="bold">$i18n.getString('birth_date')</option>
<option value="phoneNumber">$i18n.getString('phone_number')</option>
<option value="deathDate">$i18n.getString('death_date')</option>
- <option value="registrationDate">$i18n.getString('registration_date')</option>
<option value="isDead">$i18n.getString('is_dead')</option>
<option value="dobType">$i18n.getString('dob_type')</option>
<option value="healthWorker">$i18n.getString('health_worker')</option>
@@ -137,7 +140,7 @@
<td>
<select id="identifiersSelector" multiple="multiple" style="width:450px;height:270px" ondblclick="insertElement( 'iden' )">
#foreach( $identifierType in $identifierTypes )
- <option value="$identifierType.id">$encoder.htmlEncode($identifierType.displayName)</option>
+ <option value="$identifierType.id" mandatory='$identifierType.mandatory' #if($identifierType.mandatory=='true') class="bold" #end >$encoder.htmlEncode($identifierType.displayName)</option>
#end
</select>
</td>
@@ -156,13 +159,14 @@
<td>
<select id="attributesSelector" multiple="multiple" style="width:450px;height:270px" ondblclick="insertElement( 'attr' )">
#foreach( $attribute in $attributes )
- <option value="$attribute.id">$encoder.htmlEncode($attribute.displayName)</option>
+ <option value="$attribute.id" mandatory='$attribute.mandatory' #if($attribute.mandatory=='true') class="bold" #end >$encoder.htmlEncode($attribute.displayName)</option>
#end
</select>
</td>
</tr>
</table>
+ #if($!program)
<table id="programAttrTab" class='hidden'>
<tr>
<td>
@@ -182,19 +186,26 @@
</td>
</tr>
</table>
-
+ #end
+
<table>
<tr>
<td>
<button type="button" id="fixAttrButton" onclick="fixAttrOnClick()">$i18n.getString( "fixed_attributes" )</button>
<button type="button" id="identifierTypeButton" onclick="identifierTypeOnClick()">$i18n.getString( "identifier_types" )</button>
<button type="button" id="attributesButton" onclick="attributesOnClick()">$i18n.getString( "attributes" )</button>
- <button type="button" id="programAttrButton" onclick="programAttrOnClick()">$i18n.getString( "program" )</button>
+ #if($!program)
+ <button type="button" id="programAttrButton" onclick="programAttrOnClick()">$i18n.getString( "program" )</button>
+ #end
</td>
</tr>
</table>
+
+ <span id='message'></span>
+
</div>
<script>
var i18n_delete_program_data_entry_confirm = '$encoder.jsEscape( $i18n.getString( "delete_program_data_entry_confirm" ) , "'" )';
+ var i18n_property_is_inserted = '$encoder.jsEscape( $i18n.getString( "property_is_inserted" ) , "'" )';
</script>