← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11536: Don't add new person when selecting a program with validation criteria.

 

------------------------------------------------------------
revno: 11536
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-07-29 16:14:04 +0700
message:
  Don't add new person when selecting a program with validation criteria.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.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/program/Program.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2013-07-25 03:58:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java	2013-07-29 09:14:04 +0000
@@ -210,15 +210,18 @@
             {
                 Object propertyValue = getValueFromPatient( StringUtils.capitalize( criteria.getProperty() ), patient );
 
-                // Compare property value with compare value
-
-                int i = ((Comparable<Object>) propertyValue).compareTo( criteria.getValue() );
-
-                // Return validation criteria if criteria is not met
-
-                if ( i != criteria.getOperator() )
+                if ( propertyValue != null )
                 {
-                    return criteria;
+                    // Compare property value with compare value
+
+                    int i = ((Comparable<Object>) propertyValue).compareTo( criteria.getValue() );
+
+                    // Return validation criteria if criteria is not met
+
+                    if ( i != criteria.getOperator() )
+                    {
+                        return criteria;
+                    }
                 }
             }
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2013-07-25 02:32:32 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2013-07-29 09:14:04 +0000
@@ -2152,6 +2152,10 @@
 
 function addCustomPhoneNumberField( phoneNumber )
 {
+	if(phoneNumber=='')
+	{
+		phoneNumber = phoneNumberAreaCode;
+	}
 	var idx = $('.phoneNumberTR').length + 1;
 	$('.phoneNumberTR').last().after(
 		'<br/><input type="text" id="phoneNumber" name="phoneNumber" class="idxPhoneNumber' + idx + ' {validate:{phone:true}}" value=\"' + phoneNumber + '\" />'

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm	2013-07-25 02:32:32 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm	2013-07-29 09:14:04 +0000
@@ -1,3 +1,7 @@
+<script>
+	var phoneNumberAreaCode =  '$!encoder.jsEscape( $phoneNumberAreaCode , "'" )';
+</script>
+
 #if($!customRegistrationForm)
 	$customRegistrationForm
 #elseif($!patientRegistrationForm)
@@ -63,7 +67,7 @@
 		<td class='text-column'><label for="phoneNumber">$i18n.getString( "phone_number" )</label></td>
 		<td class="input-column">
 			<input type="text" id="phoneNumber" name="phoneNumber" class="{validate:{phone:true}}"/>
-			<input type="button" value='+' style='width:20px;' onclick='addPhoneNumberField($!phoneNumberAreaCode);' />
+			<input type="button" value='+' style='width:20px;' onclick='addPhoneNumberField(phoneNumberAreaCode);' />
 		</td>
 	</tr>
 
@@ -264,7 +268,6 @@
 #end
 
 <script>
-	var phoneNumberAreaCode = "$!phoneNumberAreaCode";
 	#if($!patient.dobType && $!patient.dobType=='A') 
 		showById('age');
 		hideById('birthDate');
@@ -273,19 +276,21 @@
 		showById('birthDate');
 	#end
 	
-	var phoneNumbers = "$!patient.phoneNumber".split(';');
-	setFieldValue('phoneNumber',phoneNumbers[0]);
-	#if($!customRegistrationForm)
-		for( var i = 1;i<phoneNumbers.length;i++ )
-		{
-			addCustomPhoneNumberField(phoneNumbers[i]);
-		}
-	#elseif( $!patient.phoneNumber && $patient.phoneNumber!="")
-		for( var i = 1;i<phoneNumbers.length;i++ )
-		{
-			addPhoneNumberField(phoneNumbers[i]);
-		}
-	#else 
+	#if( $!patient.phoneNumber )
+		var phoneNumbers = '$!encoder.jsEscape( $patient.phoneNumber , "'" )';
+		setFieldValue('phoneNumber',phoneNumbers[0]);
+		#if($!customRegistrationForm)
+			for( var i = 1;i<phoneNumbers.length;i++ )
+			{
+				addCustomPhoneNumberField(phoneNumbers[i]);
+			}
+		#elseif( $!patient.phoneNumber && $patient.phoneNumber!="")
+			for( var i = 1;i<phoneNumbers.length;i++ )
+			{
+				addPhoneNumberField(phoneNumbers[i]);
+			}
+		#end
+	#else
 		setFieldValue('phoneNumber',phoneNumberAreaCode)
 	#end
 </script>
\ No newline at end of file