From 3d403e48e25f5d8be5edec199a278585f490a5b0 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 21 Mar 2024 15:34:59 +0000 Subject: [PATCH] Bug 36120: Account for both pickup_location and date selection in items This patch ensures we account for both pickup location and date selections having taken place before an item selection is pondered. We now correctly disable item options given both conditions rather than it being a race between the two. Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer --- .../prog/js/modals/place_booking.js | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) 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 dc6e0b85c1..385604350b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js +++ b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js @@ -254,6 +254,11 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { false, false ); + newOption.setAttribute( + "data-available", + true + ); + // Append it to the select $("#booking_item_id").append(newOption); } @@ -459,9 +464,13 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { let option = $(this); let item_id = option.val(); if (valid_items.includes(parseInt(item_id))) { - option.prop("disabled", false); + option.attr("data-pickup", true); + if (option.data("available")) { + option.prop("disabled", false); + } } else { option.prop("disabled", true); + option.attr("data-pickup", false); } }); $("#booking_item_id").trigger("change.select2"); @@ -526,9 +535,13 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { ); }) ) { + option.attr("data-available", false); option.prop("disabled", true); } else { - option.prop("disabled", false); + option.attr("data-available", true); + if (option.data("pickup")) { + option.prop("disabled", false); + } } }); $("#booking_item_id").trigger("change.select2"); @@ -536,7 +549,10 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { // Range not set, reset field options else { $("#booking_item_id > option").each(function () { - $(this).prop("disabled", false); + let option = $(this); + if (option.data("pickup")) { + option.prop("disabled", false); + } }); $("#booking_item_id").trigger("change.select2"); } @@ -774,9 +790,11 @@ $("#placeBookingForm").on("submit", function (e) { $("#placeBookingModal").on("hidden.bs.modal", function (e) { $("#booking_patron_id").val(null).trigger("change"); $("#booking_patron_id").empty(); + booking_patron = undefined; $("#booking_item_id").val(0).trigger("change"); $("#pickup_library_id").val(null).trigger("change"); $("#pickup_library_id").empty(); + $("#pickup_library_id").prop("disabled", true); $("#period").get(0)._flatpickr.clear(); $("#booking_start_date").val(""); $("#booking_end_date").val(""); -- 2.39.5