From e962e2499d7aa2b65c97e320ebf183ac24fa712e Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Sun, 14 Jul 2024 07:39:33 +0100 Subject: [PATCH] Bug 37354: Set maxDate based on issuelength + renewals * renewalperiod This patch sets the flatpickr maxDate in the bookings range picker to the startdate selected + issuelength + renewals * renewalperiod circulation rules. --- .../prog/js/modals/place_booking.js | 18 +++++++++++++++--- 1 file changed, 15 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 323009d5905..e7e828b1c59 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js +++ b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js @@ -133,6 +133,7 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { // Lead and Trail days syncing let leadDays = 0; let trailDays = 0; + let lengthDays; function setBufferDays() { let rules_url = "/api/v1/circulation_rules"; $.ajax({ @@ -143,10 +144,12 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { patron_category_id: booking_patron.category_id, item_type_id: booking_itemtype_id, library_id: pickup_library_id, - rules: 'bookings_lead_period,bookings_trail_period' + rules: 'bookings_lead_period,bookings_trail_period,issuelength,renewalsallowed,renewalperiod' }, success: function (response) { - let rules = response[0] + let rules = response[0]; + let renewalLength = rules.renewalsallowed * rules.renewalperiod; + lengthDays = rules.issuelength + renewalLength; leadDays = rules.bookings_lead_period; trailDays = rules.bookings_trail_period; }, @@ -668,8 +671,17 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { dateStr, instance ) { + // Start date selected + if (selectedDates[0] && !selectedDates[1]) { + // Calculate the maximum date based on the selected start date + const maxDate = new Date(selectedDates[0]); + maxDate.setDate(maxDate.getDate() + lengthDays ); + + // Update the maxDate option of the flatpickr instance + instance.set('maxDate', maxDate); + } // Range set, update hidden fields and set available items - if (selectedDates[0] && selectedDates[1]) { + else if (selectedDates[0] && selectedDates[1]) { // set form fields from picker let picker_start = dayjs(selectedDates[0]); let picker_end = dayjs(selectedDates[1]).endOf( -- 2.45.2