← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5933: (patient) Autocomplete fields for dataelements with optionset.

 

------------------------------------------------------------
revno: 5933
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-02-13 14:42:56 +0700
message:
  (patient) Autocomplete fields for dataelements with optionset.
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/multiDataEntrySelect.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programStageDataEntryForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/select.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.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-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2012-02-13 02:41:24 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2012-02-13 07:42:56 +0000
@@ -584,6 +584,7 @@
         // ---------------------------------------------------------------------
 
         final String jsCodeForInputs = " $DISABLED onchange=\"saveVal( $DATAELEMENTID )\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE', provided:'$PROVIDED'}\" onkeypress=\"return keyPress(event, this)\" style=\" text-align:center;\"  ";
+        final String jsCodeForOptions = " $DISABLED options='$OPTIONS' dataElementId=\"$DATAELEMENTID\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE', provided:'$PROVIDED'}\" onkeypress=\"return keyPress(event, this)\" style=\" text-align:center;\"  ";
 
         StringBuffer sb = new StringBuffer();
 
@@ -715,15 +716,29 @@
                 // -------------------------------------------------------------
 
                 String appendCode = dataElementCode;
+
+                if ( appendCode.contains( "value=\"\"" ) )
+                {
+                    appendCode = appendCode.replace( "value=\"\"", "value=\"" + dataElementValue + "\"" );
+                }
+                else
+                {
+                    appendCode += "value=\"" + dataElementValue + "\"";
+                }
                 
                 if ( dataElement.getOptionSet() != null )
                 {
-                    appendCode = appendCode.replaceFirst( "input", "select options='true'" );
+
+                   appendCode += jsCodeForOptions;
+                   
+                   appendCode = appendCode.replace( "$OPTIONS", dataElement.getOptionSet().getOptions().toString() ); 
+ 
+                    /*appendCode = appendCode.replaceFirst( "input", "select options='true'" );
                     appendCode = appendCode.replace( "name=\"entryfield\"", jsCodeForInputs );
 
                     appendCode += ">";
                     appendCode += "<option value=\"\">" + i18n.getString( "select_value" ) + "</option>";
-                    for ( String option : dataElement.getOptionSet().getOptions() )
+                    for ( String option :  )
                     {
                         appendCode += "<option value=\"" + option + "\">" + option + "</option>";
                     }
@@ -734,24 +749,15 @@
                             "<option value=\"" + patientDataValue.getValue() + "\" selected=\"selected\">" );
                     }
 
-                    appendCode += "</select>";
+                    appendCode += "</select>";*/
                 }
                 else
                 {
-                    if ( appendCode.contains( "value=\"\"" ) )
-                    {
-                        appendCode = appendCode.replace( "value=\"\"", "value=\"" + dataElementValue + "\"" );
-                    }
-                    else
-                    {
-                        appendCode += "value=\"" + dataElementValue + "\"";
-                    }
-
                     appendCode += jsCodeForInputs;
-
-                    appendCode += " />";
                 }
 
+                appendCode += " />";
+                
                 // -----------------------------------------------------------
                 // Check if this dataElement is from another programStage then
                 // disable

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2012-02-06 02:56:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2012-02-13 07:42:56 +0000
@@ -469,4 +469,5 @@
 activity_planning = Activity Planning
 back_to_main_menu = Back to main menu
 of = of
-option_set = Option set
\ No newline at end of file
+option_set = Option set
+show_all_items = Show all items
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm	2012-02-09 04:47:14 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm	2012-02-13 07:42:56 +0000
@@ -63,4 +63,5 @@
 	var i18n_comfirm_delete_current_event = '$encoder.jsEscape( $i18n.getString( "comfirm_delete_current_event" ) , "'")';
 	var i18n_history_events = '$encoder.jsEscape( $i18n.getString( "history_events" ) , "'")';
 	var i18n_event_information = '$encoder.jsEscape( $i18n.getString( "event_information" ) , "'")';
+	var i18n_show_all_items = '$encoder.jsEscape( $i18n.getString( "show_all_items" ) , "'")';
 </script>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2012-02-13 02:41:24 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2012-02-13 07:42:56 +0000
@@ -93,12 +93,8 @@
 				<td>   
 					#set( $id = $programStageDataElement.programStage.id + '-' + $programStageDataElement.dataElement.id + '-val' )
 					#if( $!programStageDataElement.dataElement.optionSet )
-						<select name="entryselect" options='true' data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" #if($programStageInstance.completed) disabled="disabled" #end id="$id" onchange="saveVal( $programStageDataElement.dataElement.id )" tabindex="$tabIndex">              
-							<option value="">[$i18n.getString( "select_value" )]</option>
-							#foreach( $option in $programStageDataElement.dataElement.optionSet.options )
-								<option value="$option" #if( $patientDataValue.value == $option ) selected="selected" #end>$encoder.htmlEncode( $option )</option>
-							#end
-						</select>
+						#set( $optionId = $id + '-options')
+						<input name="entryselect" options='$programStageDataElement.dataElement.optionSet.options' id='$id' value='$!patientDataValue.value' data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" #if($programStageInstance.completed) disabled="disabled" #end id="$id-options" dataElementId="$programStageDataElement.dataElement.id" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" />
 					#elseif( $programStageDataElement.dataElement.type == "bool" )
 						<select name="entryselect" #if($programStageInstance.completed) disabled="disabled" #end data="{compulsory: $programStageDataElement.compulsory }" id="$id" onchange="saveOpt( $programStageDataElement.dataElement.id )" tabindex="$tabIndex"> 
 							<option value="">[$i18n.getString( "select_value" )]</option>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2012-02-11 13:58:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2012-02-13 07:42:56 +0000
@@ -778,13 +778,13 @@
         TOGGLE.init();
 		
 		
-		/*jQuery("#entryForm :input").each(function()
+		jQuery("#entryForm :input").each(function()
 		{ 
 			if( jQuery(this).attr( 'options' )!= null )
 			{
 				autocompletedField(jQuery(this).attr('id'));
 			}
-		});*/
+		});
     }
 }
 
@@ -820,59 +820,67 @@
 
 function autocompletedField( idField )
 {
-	hideById( idField );
-	var select = jQuery( "#" + idField );
-	var input = $("<input onkeypress='return keyPress(event, this);' name='entryfield' class='inputText'>")
-		.insertAfter(select)
-		.autocomplete({
-			source: function(request, response) {
-				var matcher = new RegExp(request.term, "i");
-				response(select.children("option").map(function() {
-					var text = $(this).text();
-					if (this.value && (!request.term || matcher.test(text)))
-						return {
-							id: this.value,
-							label: text,
-							value: text
-						};
-				}));
-			},
+	var input = jQuery( "#" +  idField )
+	var dataElementId = input.attr( 'dataElementId' );
+	var options = new Array();
+	options = input.attr('options').replace('[', '').replace(']', '').split(', ');
+	options.push(" ");
+
+	input.autocomplete({
 			delay: 0,
-			change: function(event, ui) {
-				if (!ui.item) {
-					// remove invalid value, as it didn't match anything
-					$(this).val("");
-					return false;
+			minLength: 0,
+			source: options,
+			select: function( event, ui ) {
+				input.val(ui.item.value);
+				saveVal( dataElementId );
+				input.autocomplete( "close" );
+			},
+			change: function( event, ui ) {
+				if ( !ui.item ) {
+					var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
+						valid = false;
+					for (var i = 0; i < options.length; i++)
+					{
+						if (options[i].match( matcher ) ) {
+							this.selected = valid = true;
+							break;
+						}
+					}
+					if ( !valid ) {
+						// remove invalid value, as it didn't match anything
+						$( this ).val( "" );
+						input.data( "autocomplete" ).term = "";
+						return false;
+					}
 				}
-				select.val(ui.item.id);
-				select.change();
+				saveVal( dataElementId );
+			}
+		})
+		.addClass( "ui-widget" );
+
+	this.button = $( "<button type='button'>&nbsp;</button>" )
+		.attr( "tabIndex", -1 )
+		.attr( "title", i18n_show_all_items )
+		.insertAfter( input )
+		.button({
+			icons: {
+				primary: "ui-icon-triangle-1-s"
 			},
-			minLength: 0
+			text: false
+		})
+		.addClass( "small-button" )
+		.click(function() {
+			// close if already visible
+			if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
+				input.autocomplete( "close" );
+				return;
+			}
+
+			// work around a bug (likely same cause as #5265)
+			$( this ).blur();
+
+			// pass empty string as value to search for, displaying all results
+			input.autocomplete( "search", "" );
+			input.focus();
 		});
-
-	// Set default value of the combobox
-	input.val( $("#" + idField + " option:selected").text());
-	$("<button>&nbsp;</button>")
-	.attr("tabIndex", -1)
-	.attr("title", "Show All Items")
-	.insertAfter(input)
-	.button({
-		icons: {
-			primary: "ui-icon-triangle-1-s"
-		},
-		text: false
-	}).removeClass("ui-corner-all")
-	.addClass("small-button ui-corner-right ui-button-icon")
-	.click(function() {
-		// close if already visible
-		if (input.autocomplete("widget").is(":visible")) {
-			input.autocomplete("close");
-			return;
-		}
-		// pass empty string as value to search for, displaying all results
-		input.autocomplete("search", "");
-		input.focus();
-	}).change(function(){
-		select.change();
-	});
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/multiDataEntrySelect.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/multiDataEntrySelect.vm	2012-01-15 15:59:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/multiDataEntrySelect.vm	2012-02-13 07:42:56 +0000
@@ -62,4 +62,5 @@
 	var i18n_date_of_birth = '$encoder.jsEscape( $i18n.getString( "date_of_birth" ), "'")';
 	var i18n_blood_group = '$encoder.jsEscape( $i18n.getString( "blood_group" ), "'")';
 	var i18n_none = '$encoder.jsEscape( $i18n.getString( "none" ), "'")';
+	var i18n_show_all_items = '$encoder.jsEscape( $i18n.getString( "show_all_items" ) , "'")';
 </script>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programStageDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programStageDataEntryForm.vm	2012-01-11 07:36:21 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programStageDataEntryForm.vm	2012-02-13 07:42:56 +0000
@@ -1,8 +1,3 @@
-<script>
-jQuery("#entryFormContainer").ready(function(){
-    entryFormContainerOnReady();
-});
-</script>
 
 <table> 
     <tr>            
@@ -98,5 +93,6 @@
     var i18n_complete_confirm_message = '$encoder.jsEscape( $i18n.getString( "complete_confirm_message" ) , "'")';
     var i18n_error_required_field = '$encoder.jsEscape( $i18n.getString( "error_required_field" ) , "'")';
 	var i18n_violate_validation = '$encoder.jsEscape( $i18n.getString( "violate_validation" ) , "'")';
-	var i18n_date_is_greater_then_or_equals_due_date = '$encoder.jsEscape( $i18n.getString( "date_is_greater_then_or_equals_due_date" ) , "'")';</script>
+	var i18n_date_is_greater_then_or_equals_due_date = '$encoder.jsEscape( $i18n.getString( "date_is_greater_then_or_equals_due_date" ) , "'")';
+	var i18n_show_all_items = '$encoder.jsEscape( $i18n.getString( "show_all_items" ) , "'")';
 </script>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/select.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/select.vm	2012-01-15 15:59:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/select.vm	2012-02-13 07:42:56 +0000
@@ -72,4 +72,6 @@
 	var i18n_date_is_greater_then_or_equals_due_date = '$encoder.jsEscape( $i18n.getString( "date_is_greater_then_or_equals_due_date" ) , "'")';
 	
 	var i18n_program_stage = '$encoder.jsEscape( $i18n.getString( "program_stage" ) , "'")';
-    var i18n_scheduled_for = '$encoder.jsEscape( $i18n.getString( "scheduled_for" ) , "'")';</script>
\ No newline at end of file
+    var i18n_scheduled_for = '$encoder.jsEscape( $i18n.getString( "scheduled_for" ) , "'")';
+	var i18n_show_all_items = '$encoder.jsEscape( $i18n.getString( "show_all_items" ) , "'")';
+</script>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm	2012-01-15 15:59:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm	2012-02-13 07:42:56 +0000
@@ -126,7 +126,7 @@
 	var i18n_date_is_greater_then_or_equals_due_date = '$encoder.jsEscape( $i18n.getString( "date_is_greater_then_or_equals_due_date" ) , "'")';
 	
 	var i18n_violate_validation = '$encoder.jsEscape( $i18n.getString( "violate_validation" ) , "'")';
-	
+	var i18n_show_all_items = '$encoder.jsEscape( $i18n.getString( "show_all_items" ) , "'")';
 	
 	var checkedDuplicate = false;
 	// -1: no search anything