diff --git a/omod/src/main/webapp/resources/scripts/jquery-ui/js/openmrsSearch.js b/omod/src/main/webapp/resources/scripts/jquery-ui/js/openmrsSearch.js index 39fcb1cf..e2af9b92 100644 --- a/omod/src/main/webapp/resources/scripts/jquery-ui/js/openmrsSearch.js +++ b/omod/src/main/webapp/resources/scripts/jquery-ui/js/openmrsSearch.js @@ -22,7 +22,7 @@ * displayLength: 5, * minLength: 3, * columnWidths: ["15%","15%","15%","15%","15%", "25%"], - * columnRenderers: [null, null, null, null, null, null], + * columnRenderers: [null, null, null, null, null, null], * columnVisibility: [true, true, true, true, true, true], * searchHandler: doSearchHandler, * selectionHandler: doSelectionHandler, @@ -51,9 +51,9 @@ * {searchLabel: '', * searchPlaceholder:'', * displayLength: 5, - * minLength: 3, + * minLength: 3, * columnWidths: ["15%","15%","15%","15%","15%", "25%"], - * columnRenderers: [null, null, null, null, null, null], + * columnRenderers: [null, null, null, null, null, null], * columnVisibility: [true, true, true, true, true, true]} * ); * }); @@ -104,8 +104,8 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler, * verboseHandler: function to be called to return the text to display as verbose output * attributes: Array of names for attributes types to display in the list of results * showSearchButton: Boolean, indicating whether to use search button for immediate search - * showVerbose: Boolean, indicates whether to check checkbox for verbose - * includeVoided: Boolean, indicates whether to check checkbox for voided + * showVerbose: Boolean, indicates whether to check checkbox for verbose + * includeVoided: Boolean, indicates whether to check checkbox for voided * * The styling on this table works like this: *
@@ -115,7 +115,7 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler,
  *
*/ (function($j) { - var openmrsSearch_div = + var openmrsSearch_div = ''+ ''+ ''+ @@ -195,7 +195,7 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler, notification = div.find("#searchWidgetNotification"); loadingMsgObj = div.find("#loadingMsg"); showSearchButton = o.showSearchButton ? true : false; - + this._div = div; lbl.text(o.searchLabel); @@ -549,7 +549,7 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler, if(typeof(Storage) !== "undefined") { //check to see if there are parameters to get from sessionStorage //after setting the fields clear out session storage so it doesn't get used on other pages - + if(sessionStorage.includeVoided){ self.options.includeVoided = true; sessionStorage.removeItem("includeVoided"); @@ -557,9 +557,9 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler, if(sessionStorage.includeVerbose){ self.options.showVerbose = true; sessionStorage.removeItem("includeVerbose"); - } + } } - + //register an onchange event handler for the length dropdown so that we don't lose //the row highlight when the user makes changes to the length var selectElement = document.getElementById('openmrsSearchTable_length').getElementsByTagName('select')[0]; @@ -580,7 +580,7 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler, } else if(self.options.searchPhrase || self.options.doSearchWhenEmpty) { if (self.options.searchPhrase == null) { self.options.searchPhrase = ""; - } + } //check to see if we need to select the checkbox for includeVerbose and/or includeVoided //since there is a searchPhrase the page will reload using these values if(self.options.showVerbose){ @@ -588,7 +588,7 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler, } if(self.options.includeVoided){ $j('#includeVoided').attr('checked','checked'); - } + } } $j(input).val(self.options.searchPhrase).keyup(); //setting the cursor to the end of the searchPhrase @@ -839,7 +839,7 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler, var cols = this.options.fieldsAndHeaders; rRowData = $j.map(cols, function(c) { var data = rowData[c.fieldName]; - if(data == null) + if(data == null || data === "null") data = " "; //Escape html data = $j('
').text(data).html(); @@ -970,7 +970,7 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler, sessionStorage.includeVerbose = "checked"; } if($j(checkBox).is(':checked')) { - sessionStorage.includeVoided = "checked"; + sessionStorage.includeVoided = "checked"; } } this.options.selectionHandler(position, rowData); @@ -1075,14 +1075,16 @@ function OpenmrsSearch(div, showIncludeVoided, searchHandler, selectionHandler, return Math.ceil(this._table.fnSettings()._iDisplayStart / this._table.fnSettings()._iDisplayLength) + 1; }, _updatePageInfo: function(searchText) { - textToDisplay = omsgs.viewingResultsFor.replace("_SEARCH_TEXT_", "'"+searchText+"'"); - if($j.trim(searchText) == '') - textToDisplay = omsgs.viewingAll; + if ((/^[a-zA-Z0-9_\-]+$/.test(searchText))) { + textToDisplay = omsgs.viewingResultsFor.replace("_SEARCH_TEXT_", "'"+sanitizeHtml(searchText)+"'"); + if($j.trim(searchText) == '') + textToDisplay = omsgs.viewingAll; - $j('#pageInfo').html(sanitizeHtml(textToDisplay)); + $j('#pageInfo').html(sanitizeHtml(textToDisplay)); - if($j('#pageInfo').css("visibility") != 'visible') - $j('#pageInfo').css("visibility", "visible"); + if($j('#pageInfo').css("visibility") != 'visible') + $j('#pageInfo').css("visibility", "visible"); + } }, //This function adds the data returned by the second ajax call that fetches the remaining rows diff --git a/omod/src/main/webapp/resources/scripts/jquery/autocomplete/OpenmrsAutoComplete.js b/omod/src/main/webapp/resources/scripts/jquery/autocomplete/OpenmrsAutoComplete.js index d80b128d..7df86ee9 100644 --- a/omod/src/main/webapp/resources/scripts/jquery/autocomplete/OpenmrsAutoComplete.js +++ b/omod/src/main/webapp/resources/scripts/jquery/autocomplete/OpenmrsAutoComplete.js @@ -231,12 +231,24 @@ function CreateCallback(options) { // between the image and the identifier var textShown = " "; - if (person.identifier) - textShown += person.identifier; - + if (person.identifier) { + textShown += $j('
').text(person.identifier).html(); + } + textShown += " "; - textShown += person.personName; + var personName = ""; + if (person.givenName !== "null") { + personName += person.givenName + " "; + } + if (person.middleName !== "null") { + personName += person.middleName + " "; + } + if (person.familyName !== "null") { + personName += person.familyName; + } + + textShown += $j('
').text(personName).html() // highlight each search term in the results textShown = highlightWords(textShown, origQuery); @@ -244,18 +256,16 @@ function CreateCallback(options) { var ageText = ""; if (person.age) { ageText = " (" + person.age + " " + omsgs.yearsOld + ")"; + ageText = $j('
').text(ageText).html() } // append the gender image and age AFTER word highlighting so regex doesn't match it textShown = imageText + textShown + ageText; // space was inserted into beginning of 'textShown' var - textShown = $j('
').text(textShown).html() - // wrap each result in a span tag (needed?) textShown = "" + textShown + ""; - - personNameEscaped = $j('
').text(person.personName).html(); + personNameEscaped = $j('
').text(personName).html(); personIdEscaped = $j('
').text(person.personId).html(); return { label: textShown, value: personNameEscaped, id: personIdEscaped, object: person }; }; }