From 288bdb81bffb34d8555c72f117449bedde622bae Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 19 Apr 2024 16:39:46 +0100 Subject: [PATCH] Bug 36120: Restore edit Signed-off-by: Nick Clemens --- .../prog/en/modules/bookings/list.tt | 5 +-- .../prog/js/modals/place_booking.js | 33 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt index b0d69114232..47740506f89 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt @@ -106,6 +106,7 @@ id: booking.booking_id, booking: booking.booking_id, patron: booking.patron_id, + pickup_library: booking.pickup_library_id, start: dayjs(booking.start_date).toDate(), end: dayjs(booking.end_date).toDate(), content: $patron_to_html(booking.patron, { @@ -167,7 +168,7 @@ // set end datetime hours and minutes to the end of the day let endDate = dayjs(data.end).endOf('day'); - $('#placeBookingModal').modal('show', $(''; + result += ''; result += ''; [% END %] return result; diff --git a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js index a649408f176..bd09384fb9b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js +++ b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js @@ -31,6 +31,7 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { $("#booking_biblio_id").val(biblionumber); let patron_id = button.data("patron") || 0; + let pickup_library_id = button.data("pickup_library"); booking_item_id = button.data("itemnumber"); let start_date = button.data("start_date"); let end_date = button.data("end_date"); @@ -139,17 +140,21 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { }); function setLocationsPicker(response) { let $pickupSelect = $("#pickup_library_id"); - let bookableItemnumbers = bookable_items.map(function(object) { return object.item_id; }); + let bookableItemnumbers = bookable_items.map(function (object) { + return object.item_id; + }); $pickupSelect.empty(); - $.each(response, function(index, pickup_location) { - if (containsAny(pickup_location.pickup_items, bookableItemnumbers)) { + $.each(response, function (index, pickup_location) { + if ( + containsAny(pickup_location.pickup_items, bookableItemnumbers) + ) { let option = $( '" + pickup_location.library_id + + '">' + + pickup_location.name + + "" ); option.attr( @@ -166,7 +171,13 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { }); $pickupSelect.prop("disabled", false); - $pickupSelect.val(null).trigger("change"); + + // If pickup_library alread exists, pre-select + if (pickup_library_id) { + $pickupSelect.val(pickup_library_id).trigger("change"); + } else { + $pickupSelect.val(null).trigger("change"); + } } // Item select2 @@ -195,16 +206,15 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { success: function (response) { if (dataFetched === true) { setLocationsPicker(response); - } else { - var interval = setInterval(function() { + var interval = setInterval(function () { if (dataFetched === true) { // Data is fetched, execute the callback and stop the interval setLocationsPicker(response); clearInterval(interval); } }, 100); - }; + } }, error: function (xhr, status, error) { console.log("Pickup location fetch failed: ", error); @@ -854,7 +864,6 @@ $("#placeBookingForm").on("submit", function (e) { }); $("#placeBookingModal").on("hidden.bs.modal", function (e) { - // Reset patron select $("#booking_patron_id").val(null).trigger("change"); $("#booking_patron_id").empty(); -- 2.44.0