From e2e0d66ac889953908ed3c2f9a7d6dfc08eca621 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 17 Aug 2023 18:14:18 +0100 Subject: [PATCH] Bug 29002: Match select2 patron format to patron_autocomplete This still needs a little work to fully match, but is getting close now. I'd love to convert the existing autocompletes to select2 styling instead actually.. maybe convert the select here to patron_autocomplete and then work on a patch to convert patron_autocomplete to a select2 implimentation. Signed-off-by: Martin Renvoize Signed-off-by: Janet McGowan Signed-off-by: Caroline Cyr La Rose Signed-off-by: Laurence Rault Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- .../prog/js/place_booking_modal.js | 54 ++++++++++++++++--- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/place_booking_modal.js b/koha-tmpl/intranet-tmpl/prog/js/place_booking_modal.js index 13f6f382c8..58e39264b5 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/place_booking_modal.js +++ b/koha-tmpl/intranet-tmpl/prog/js/place_booking_modal.js @@ -7,7 +7,7 @@ $('#placeBookingModal').on('show.bs.modal', function(e) { // Patron select2 $("#booking_patron_id").kohaSelect({ dropdownParent: $(".modal-content", "#placeBookingModal"), - width: '30%', + width: '50%', dropdownAutoWidth: true, allowClear: true, minimumInputLength: 3, @@ -15,6 +15,9 @@ $('#placeBookingModal').on('show.bs.modal', function(e) { url: '/api/v1/patrons', delay: 250, dataType: 'json', + headers: { + "x-koha-embed": "library" + }, data: function(params) { var search_term = (params.term === undefined) ? '' : params.term; var query = { @@ -36,7 +39,7 @@ $('#placeBookingModal').on('show.bs.modal', function(e) { } ] }), - '_order_by': 'firstname', + '_order_by': '+me.surname,+me.firstname', '_page': params.page, }; return query; @@ -44,17 +47,52 @@ $('#placeBookingModal').on('show.bs.modal', function(e) { processResults: function(data, params) { var results = []; data.results.forEach(function(patron) { - results.push({ - "id": patron.patron_id, - "text": escape_str(patron.firstname) + " " + escape_str(patron.surname) + " (" + escape_str(patron.cardnumber) + ")" - }); + patron.id = patron.patron_id; + results.push(patron); }); return { "results": results, "pagination": { "more": data.pagination.more } }; }, }, - placeholder: "Search for a patron" + templateResult: function (patron) { + if (patron.library_id == loggedInLibrary) { + loggedInClass = "ac-currentlibrary"; + } else { + loggedInClass = ""; + } + + var $patron = $("") + .append( + "" + + (patron.surname + ? escape_str(patron.surname) + ", " + : "") + + (patron.firstname + ? escape_str(patron.firstname) + " " + : "") + + (patron.cardnumber + ? " (" + escape_str(patron.cardnumber) + ") " + : "") + + (patron.date_of_birth + ? '' + + $get_age(patron.date_of_birth) + + " " + + __("years") + + "" + : "") + ) + .addClass(loggedInClass); + return $patron; + }, + templateSelection: function (patron) { + if (!patron.id) { + return patron.text; + } + return ( + escape_str(patron.surname) + ", " + escape_str(patron.firstname) + ); + }, placeholder: "Search for a patron" }); // If passed patron, pre-select @@ -77,7 +115,7 @@ $('#placeBookingModal').on('show.bs.modal', function(e) { // Item select2 $("#booking_item_id").select2({ dropdownParent: $(".modal-content", "#placeBookingModal"), - width: '30%', + width: '50%', dropdownAutoWidth: true, minimumResultsForSearch: 20, placeholder: "Select item" -- 2.39.5