From 39a73245f3593d12bb2d1597725154a166bc8e3e Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 3 Jun 2025 21:46:36 +0100 Subject: [PATCH] Bug 39916: Fix booking modal redraw issue Fixes an issue where the booking modal's date picker and form fields were not properly updating when switching between different booking scenarios or after form submissions. The fix ensures proper redraw and state management of the flatpickr component and associated form elements. --- .../prog/js/modals/place_booking.js | 87 ++++++++++--------- 1 file changed, 44 insertions(+), 43 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 634cce0c36e..8b9f2d91b0c 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js +++ b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js @@ -93,29 +93,29 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { let $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") + - "" - : "") + - (patron.library - ? ' ' + - escape_str(patron.library.name) + - "" - : "") + - "" + (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") + + "" + : "") + + (patron.library + ? ' ' + + escape_str(patron.library.name) + + "" + : "") + + "" ) .addClass(loggedInClass); return $patron; @@ -170,6 +170,7 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { if (changed) { periodPicker.clear(); } + periodPicker.set("disable", periodPicker.config.disable); periodPicker.redraw(); // Enable flatpickr now we have data we need @@ -211,10 +212,10 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { ) { let option = $( '" + pickup_location.library_id + + '">' + + pickup_location.name + + "" ); option.attr( @@ -413,8 +414,8 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { if ( !$("#booking_itemtype").find( "option[value='" + - item.item_type.item_type_id + - "']" + item.item_type.item_type_id + + "']" ).length ) { // Create a DOM Option and de-select by default @@ -458,7 +459,7 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { } // iterate existing bookings - for (booking of bookings) { + for (let booking of bookings) { // Skip if we're editing this booking if ( booking_id && @@ -752,7 +753,7 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { for (let i = 0; i < renewalsAllowed; i++) { nextDate.setDate( nextDate.getDate() + - parseInt(renewalLength) + parseInt(renewalLength) ); boldDates.push(new Date(nextDate)); } @@ -932,8 +933,8 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { ); const startDate = periodPicker.selectedDates[0] ? dayjs(periodPicker.selectedDates[0]).startOf( - "day" - ) + "day" + ) : null; const leadStart = startDate @@ -959,7 +960,7 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { dayElem.classList.toggle( "leadRange", elemDate.isSameOrAfter(leadStart) && - elemDate.isBefore(leadEnd) + elemDate.isBefore(leadEnd) ); dayElem.classList.toggle( "leadRangeEnd", @@ -972,7 +973,7 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { dayElem.classList.toggle( "trailRange", elemDate.isAfter(trailStart) && - elemDate.isSameOrBefore(trailEnd) + elemDate.isSameOrBefore(trailEnd) ); dayElem.classList.toggle( "trailRangeEnd", @@ -1195,8 +1196,8 @@ $("#placeBookingForm").on("submit", function (e) { // Set feedback $("#transient_result").replaceWith( '
' + - __("Booking successfully placed") + - "
" + __("Booking successfully placed") + + "" ); // Close modal @@ -1206,8 +1207,8 @@ $("#placeBookingForm").on("submit", function (e) { posting.fail(function (data) { $("#booking_result").replaceWith( '
' + - __("Failure") + - "
" + __("Failure") + + "" ); }); } else { @@ -1264,8 +1265,8 @@ $("#placeBookingForm").on("submit", function (e) { // Set feedback $("#transient_result").replaceWith( '
' + - __("Booking successfully updated") + - "
" + __("Booking successfully updated") + + "" ); // Close modal @@ -1275,8 +1276,8 @@ $("#placeBookingForm").on("submit", function (e) { putting.fail(function (data) { $("#booking_result").replaceWith( '
' + - __("Failure") + - "
" + __("Failure") + + "" ); }); } -- 2.49.0