From 4cfbd7dbb0524ab7836b6248cb74e0906d45b27b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Sun, 14 Jul 2024 08:57:22 +0100 Subject: [PATCH] Bug 37354: Add visual hint at usual loan periods This patch adds a visual hint to the datepicker to highlight dates that line up with normal loan and renewal lengths. We use bold to highlight such dates. --- .../prog/js/modals/place_booking.js | 45 +++++++++++++++---- 1 file changed, 37 insertions(+), 8 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 e7e828b1c59..5b7d3ed8086 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js +++ b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js @@ -133,7 +133,10 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { // Lead and Trail days syncing let leadDays = 0; let trailDays = 0; - let lengthDays; + let boldDates = []; + let issueLength; + let renewalLength; + let renewalsAllowed; function setBufferDays() { let rules_url = "/api/v1/circulation_rules"; $.ajax({ @@ -148,8 +151,9 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { }, success: function (response) { let rules = response[0]; - let renewalLength = rules.renewalsallowed * rules.renewalperiod; - lengthDays = rules.issuelength + renewalLength; + issueLength = rules.issuelength; + renewalsAllowed = rules.renewalsallowed; + renewalLength = rules.renewalperiod; leadDays = rules.bookings_lead_period; trailDays = rules.bookings_trail_period; }, @@ -673,9 +677,28 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { ) { // Start date selected if (selectedDates[0] && !selectedDates[1]) { + + const startDate = new Date(selectedDates[0]); + + // Custom format function to make specific dates bold + boldDates = [new Date(startDate)]; + // Add issueLength days after the startDate + const nextDate = new Date(startDate); + nextDate.setDate(nextDate.getDate() + parseInt(issueLength)); + boldDates.push(new Date(nextDate)); + + // Add subsequent dates based on renewalsAllowed and renewalLength + for (let i = 0; i < renewalsAllowed; i++) { + nextDate.setDate(nextDate.getDate() + parseInt(renewalLength)); + boldDates.push(new Date(nextDate)); + } + // Calculate the maximum date based on the selected start date - const maxDate = new Date(selectedDates[0]); - maxDate.setDate(maxDate.getDate() + lengthDays ); + let totalRenewalLength = parseInt(renewalsAllowed) * parseInt(renewalLength); + let totalIssueLength = parseInt(issueLength) + parseInt(totalRenewalLength); + + const maxDate = new Date(startDate.getTime()); + maxDate.setDate(maxDate.getDate() + totalIssueLength ); // Update the maxDate option of the flatpickr instance instance.set('maxDate', maxDate); @@ -792,15 +815,21 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { instance, dayElem ) { - const currentDate = dayElem.dateObj + const currentDate = dayElem.dateObj; + const dateString = currentDate .toISOString() .split("T")[0]; - if (bookingsByDate[currentDate]) { + const isBold = boldDates.some(boldDate => boldDate.getTime() === currentDate.getTime()); + if (isBold) { + dayElem.classList.add('title'); + } + + if (bookingsByDate[dateString]) { const dots = document.createElement("span"); dots.className = "event-dots"; dayElem.appendChild(dots); - bookingsByDate[currentDate].forEach(item => { + bookingsByDate[dateString].forEach(item => { const dot = document.createElement("span"); dot.className = "event item_" + item; dots.appendChild(dot); -- 2.45.2