Bug 40245: Show firstname in patron search results when different than preferred_name

This patch shows the patron's firstname in patron search results and autosuggestions
	when the patrons preferred_name is different than their first name. Requires that
	the ShowPatronFirstnameIfDifferentThanPreferredname system preference is enabled.

Test plan:
0. Apply patches and login to the staff interface.
1. Edit a patron to give a different preferred name than firstname.
2. Return to home page and search for the patron in the quick-search bar.
3. Verify patron shows up in autosuggest list, showing preferred name only.
4. Verify patron shows up in regular list (member.pl) with preferred name showing only.
5. Change syspref ShowFirstIfDifferentThanPreferred to "Show" and save.
6. Return to home page and search for the patron in the quick-search bar.
7. Verify patron shows up in autosuggest list, showing preferred name, and firstname in brackets.
8. Verify patron shows up in regular list (member.pl) with preferred name, and firstname in brackets.

Sponsored-by: Westlake Porter Public Library <https://westlakelibrary.org>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
CJ Lynce 2025-10-13 22:20:35 +00:00 committed by Lucas Gass
parent 1d6eb51d20
commit 3bb0936785
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
4 changed files with 17 additions and 3 deletions

View File

@ -75,6 +75,7 @@
var extendedPatronAttributes = "[% Koha.Preference('ExtendedPatronAttributes') | html %]";
var loggedInLibrary = '[% Branches.GetLoggedInBranchcode | html %]';
var singleBranchMode = '[% singleBranchMode | html %]';
var showPatronFirstnameIfDifferentThanPreferredname = [% Koha.Preference('ShowPatronFirstnameIfDifferentThanPreferredname') ? 1 : 0 | html %];
</script>
[% IF ( PatronAutoComplete ) %]
<script>

View File

@ -594,9 +594,10 @@
let patron_id = encodeURIComponent(row.patron_id);
let r = '';
[% IF ! open_on_row_click %]
r += "<a href=\"/cgi-bin/koha/members/moremember.pl?borrowernumber=" + patron_id + "\" class=\"patron_name\" data-borrowernumber=\"" + patron_id + "\" style=\"white-space:nowrap\">" + $patron_to_html(row, { invert_name: 1 }) + "</a>";
r += "<a href=\"/cgi-bin/koha/members/moremember.pl?borrowernumber=" + patron_id + "\" class=\"patron_name\" data-borrowernumber=\"" + patron_id + "\" style=\"white-space:nowrap\">"
+ $patron_to_html(row, { invert_name: 1, showDiffFirstname: [% Koha.Preference('ShowPatronFirstnameIfDifferentThanPreferredname') ? 1 : 0 | html %] }) + "</a>";
[% ELSE %]
r += $patron_to_html(row, { invert_name: 1 });
r += $patron_to_html(row, { invert_name: 1, showDiffFirstname: [% Koha.Preference('ShowPatronFirstnameIfDifferentThanPreferredname') ? 1 : 0 | html %] });
[% END %]
r += '<br/>';
r += '<div class="address"><ul>';

View File

@ -3,7 +3,8 @@
* Format the patron response from a Koha RESTful API request.
* @param {Object} patron The patron json object as returned from the Koha RESTful API
* @param {Object} config A configuration object
* Valid keys are: `invert_name`, `display_cardnumber` and `url`
* Valid keys are: `invert_name`, `display_cardnumber', `url`
* and `showDiffFirstname`
* @return {string} The formatted HTML string
*/
window.$patron_to_html = function (patron, config) {
@ -33,6 +34,15 @@
preferred_name += " (" + escape_str(patron.other_name) + ")";
}
if (
config &&
config.showDiffFirstname &&
patron.preferred_name != patron.firstname
) {
preferred_name +=
" <em>[" + escape_str(patron.firstname) + "]</em>";
}
const nameParts = [];
if (config?.invert_name) {
// Invert: "Surname, Preferred"

View File

@ -803,6 +803,8 @@ function patron_autocomplete(node, options) {
$patron_to_html(item, {
display_cardnumber: true,
invert_name: true,
showDiffFirstname:
showPatronFirstnameIfDifferentThanPreferredname,
}) +
" " +
(item.date_of_birth