From 5c3ee79814c8bd55f7baf94bcccda76e5e0dba7d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 6 Oct 2025 15:22:12 +0200 Subject: [PATCH] Bug 32176: Remove duplicated code to select patron from autocomplete On bug 31782 we centralized the code to autocomplete when searching for patron There were several occurrences in the code where some code were duplicated (when selecting patrons and allowing to remove them from a list). This patch centralizes this code by adding another parameter to patron_autocomplete: on-select-add-to Test plan: When duplicating an order, searching for orders, editing a course (and adding instructors) and adding patrons to a patron list, you should now see the correct patron details displayed: with preferred name, without "null" in case of missing surname, correct spacing, etc. Like (almost) everywhere else in Koha. Signed-off-by: Andrew Fuerste Henry Signed-off-by: Nick Clemens Signed-off-by: Lucas Gass --- .../prog/css/src/staff-global.scss | 4 ++ .../prog/en/modules/acqui/duplicate_orders.tt | 29 ++--------- .../prog/en/modules/acqui/histsearch.tt | 23 +-------- .../prog/en/modules/course_reserves/course.tt | 49 +++---------------- .../prog/en/modules/patron_lists/list.tt | 21 ++------ .../intranet-tmpl/prog/js/staff-global.js | 30 +++++++++++- patron_lists/list.pl | 2 +- 7 files changed, 51 insertions(+), 107 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss index f8c9cefcd7..44c3229cf1 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss +++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss @@ -2863,6 +2863,10 @@ td.bundle { background: #FFF url( "../img/spinner-small.gif" ) right center no-repeat; } +.patron-detail-autocomplete-selection { + padding: 0.3em; +} + .toptabs { margin: 1rem 0; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/duplicate_orders.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/duplicate_orders.tt index c2aa545245..c660a925bb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/duplicate_orders.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/duplicate_orders.tt @@ -323,7 +323,6 @@ $("input[name='ordernumbers']").val(ordernumbers.join(',')); } - var MSG_REMOVE_PATRON = _("Remove"); var MSG_NO_ITEM_SELECTED = _("Nothing is selected."); var MSG_NO_FUND_SELECTED = _("No fund selected."); $(document).ready(function() { @@ -333,34 +332,16 @@ }); [% IF op == 'search' OR op == 'select' %] - function AddPatron( patron_name, value, container, input_name ) { - div = "
" + patron_name + " ( " + MSG_REMOVE_PATRON + " )
"; - $(container).append( div ); - - $(container).parent().show( 800 ); - } - function RemovePatron( cardnumber, container ) { - $( '#borrower_' + cardnumber ).remove(); - - if ( ! $(container).html() ) { - $(container).parent("fieldset").hide( 800 ); - } - } patron_autocomplete($("#find_patron"), { - 'on-select-callback': function( event, ui ) { - var field = ui.item.patron_id; - AddPatron( ui.item.firstname + " " + ( ui.item.middle_name || "" ) + " " + ui.item.surname, field, $("#basket_creators"), 'created_by' ); + "on-select-add-to": { + container: $("#basket_creators"), + input_name: 'created_by' + }, + "on-select-callback": function( event, ui ) { $("#find_patron").val('').focus(); return false; } }); - $("body").on("click",".removePatron",function(e){ - e.preventDefault(); - var divid = $(this).parent().attr("id"); - var cardnumber = divid.replace("borrower_",""); - RemovePatron(cardnumber, $("#basket_creators")); - }); - [% END %] $("#show_orders_filters, #hide_orders_filters").on('click', function(e) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt index 59a838856b..5f6656c9cd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt @@ -168,7 +168,6 @@ [% INCLUDE 'calendar.inc' %] [% INCLUDE 'datatables.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course.tt index 939d292f1e..ac3202e5cf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course.tt @@ -19,9 +19,6 @@ #course_instructors { float: left; } - .instructor_line { - padding: 0.3em; - } fieldset.rows label[for="find_instructor"] { text-align: left; margin: 0; @@ -131,13 +128,13 @@
[% FOREACH i IN instructors %] -
- [% INCLUDE 'patron-title.inc' patron=i no_cardnumber=1 %] ( Remove ) +
+ [% INCLUDE 'patron-title.inc' patron=i no_cardnumber=1 %] ( Remove )
[% END %]
-