Skip to content

Commit e60d95e

Browse files
bhashithawluyima
authored andcommittedMar 21, 2013
Add search button to Concept search -TRUNK-3836
TRUNK-3836: Improvements on first fix TRUNK-3836: Further improvement on fix TRUNK-3836: Avoid double search
1 parent a9586d5 commit e60d95e

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed
 

‎webapp/src/main/webapp/WEB-INF/view/dictionary/index.jsp

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
columnVisibility: [true, false],
2525
searchPhrase:'<request:parameter name="phrase"/>',
2626
showIncludeVerbose: true,
27-
verboseHandler: doGetVerbose
27+
verboseHandler: doGetVerbose,
28+
showSearchButton: true
2829
});
2930
});
3031

‎webapp/src/main/webapp/WEB-INF/view/scripts/jquery-ui/js/openmrsSearch.js

+33-3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler,
103103
* doSearchWhenEmpty: If it is set to true, it lists all items initially and filters them with the given search phrase. (default:false)
104104
* verboseHandler: function to be called to return the text to display as verbose output
105105
* attributes: Array of names for attributes types to display in the list of results
106+
* showSearchButton: Boolean, indicating whether to use search button for immediate search
106107
*
107108
* The styling on this table works like this:
108109
* <pre>
@@ -192,6 +193,7 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler,
192193
minCharErrorObj.html(omsgs.minCharRequired.replace("_REQUIRED_NUMBER_", o.minLength));
193194
notification = div.find("#searchWidgetNotification");
194195
loadingMsgObj = div.find("#loadingMsg");
196+
showSearchButton = o.showSearchButton ? true : false;
195197

196198
this._div = div;
197199

@@ -201,6 +203,21 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler,
201203
if(o.displayLength < 3)
202204
o.displayLength = 3;
203205

206+
// If need search button
207+
if (showSearchButton) {
208+
input.after("<input type='button' id='searchButton' name='searchButton' value='" + omsgs.searchLabel + "' />");
209+
$j('#searchButton').click(function() {
210+
if ($j.trim(input.val()) != '' || self.options.doSearchWhenEmpty) {
211+
//if there is any delay in progress, cancel it
212+
if(self._searchDelayTimer != null) {
213+
window.clearTimeout(self._searchDelayTimer);
214+
}
215+
self._doSearch($j.trim(input.val()));
216+
input.focus();
217+
}
218+
});
219+
}
220+
204221
if(o.showIncludeVoided) {
205222
var tmp = div.find("#includeVoided");
206223
tmp.after("<label for='includeVoided'>" + o.includeVoidedLabel + "</label>");
@@ -250,11 +267,17 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler,
250267
//LEFT(37), UP(38), RIGHT(39), DOWN(40), ENTER(13), HOME(36), END(35), PAGE UP(33), PAGE DOWN(34)
251268
var kc = event.keyCode;
252269
if(((kc >= 33) && (kc <= 40)) || (kc == 13)) {
253-
if(!(self._div.find(".openmrsSearchDiv").css("display") != 'none')) {
270+
if(!(self._div.find(".openmrsSearchDiv").css("display") != 'none') && ($j.trim(input.val()) == '')) {
254271
return true;
255272
}
256-
if(kc == 13)
273+
if(kc == 13) {
274+
//if there is any delay in progress, cancel it
275+
if(self._searchDelayTimer != null) {
276+
window.clearTimeout(self._searchDelayTimer);
277+
}
257278
self._doKeyEnter();
279+
}
280+
258281
//kill the event
259282
event.stopPropagation();
260283

@@ -885,15 +908,22 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler,
885908
},
886909

887910
_doKeyEnter: function() {
911+
888912
var selectedRowIndex = null;
889913
if(this.hoverRowSelection != null) {
890914
selectedRowIndex = this.hoverRowSelection;
891915
}else if(this.curRowSelection != null){
892916
selectedRowIndex = this.curRowSelection;
893917
}
894918

895-
if(selectedRowIndex != null)
919+
if(selectedRowIndex != null) {
896920
this._doSelected(selectedRowIndex, this._results[selectedRowIndex]);
921+
} else if (showSearchButton) {
922+
if (($j.trim($j('#inputNode').val()) != '') || self.options.doSearchWhenEmpty) {
923+
this._doSearch($j.trim($j('#inputNode').val()));
924+
}
925+
}
926+
897927
},
898928

899929
_doSelected: function(position, rowData) {

‎webapp/src/main/webapp/WEB-INF/view/scripts/openmrsmessages.js.withjstl

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ omsgs.gender="<openmrs:message code="Person.gender" javaScriptEscape="true"/>";
2121
omsgs.genderRequired="<openmrs:message code='Person.gender.required'/>";
2222
omsgs.givenName="<openmrs:message code="PersonName.givenName" javaScriptEscape="true"/>";
2323
omsgs.identifier="<openmrs:message code="Patient.identifier" javaScriptEscape="true"/>";
24+
omsgs.searchLabel="<openmrs:message code="general.search" javaScriptEscape="true"/>";
2425
omsgs.includeDisabled="<openmrs:message code="SearchResults.includeDisabled" javaScriptEscape="true"/>";
2526
omsgs.includeRetired="<openmrs:message code="SearchResults.includeRetired" javaScriptEscape="true"/>";
2627
omsgs.includeVoided="<openmrs:message code="SearchResults.includeVoided" javaScriptEscape="true"/>";

0 commit comments

Comments
 (0)
Please sign in to comment.