View | Details | Raw Unified | Return to bug 37354
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js (-11 / +52 lines)
Lines 132-139 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
132
    // Lead and Trail days syncing
132
    // Lead and Trail days syncing
133
    let leadDays = 0;
133
    let leadDays = 0;
134
    let trailDays = 0;
134
    let trailDays = 0;
135
    let lengthDays;
135
    let boldDates = [];
136
    let issueLength;
137
    let renewalLength;
138
    let renewalsAllowed;
136
    function getCirculationRules() {
139
    function getCirculationRules() {
140
        let rules_url = "/api/v1/circulation_rules";
137
        $.ajax({
141
        $.ajax({
138
            url: rules_url,
142
            url: rules_url,
139
            type: "GET",
143
            type: "GET",
Lines 142-153 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
142
                patron_category_id: booking_patron.category_id,
146
                patron_category_id: booking_patron.category_id,
143
                item_type_id: booking_itemtype_id,
147
                item_type_id: booking_itemtype_id,
144
                library_id: pickup_library_id,
148
                library_id: pickup_library_id,
145
                rules: "bookings_lead_period,bookings_trail_period,issuelength,renewalsallowed,renewalperiod"
149
                rules: "bookings_lead_period,bookings_trail_period,issuelength,renewalsallowed,renewalperiod",
146
            },
150
            },
147
            success: function (response) {
151
            success: function (response) {
148
                let rules = response[0];
152
                let rules = response[0];
149
                let renewalLength = rules.renewalsallowed * rules.renewalperiod;
153
                issueLength = rules.issuelength;
150
                lengthDays = rules.issuelength + renewalLength;
154
                renewalsAllowed = rules.renewalsallowed;
155
                renewalLength = rules.renewalperiod;
151
                leadDays = rules.bookings_lead_period;
156
                leadDays = rules.bookings_lead_period;
152
                trailDays = rules.bookings_trail_period;
157
                trailDays = rules.bookings_trail_period;
153
158
Lines 676-687 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
676
                    ) {
681
                    ) {
677
                        // Start date selected
682
                        // Start date selected
678
                        if (selectedDates[0] && !selectedDates[1]) {
683
                        if (selectedDates[0] && !selectedDates[1]) {
684
                            const startDate = new Date(selectedDates[0]);
685
686
                            // Custom format function to make specific dates bold
687
                            boldDates = [new Date(startDate)];
688
                            // Add issueLength days after the startDate
689
                            const nextDate = new Date(startDate);
690
                            nextDate.setDate(
691
                                nextDate.getDate() + parseInt(issueLength)
692
                            );
693
                            boldDates.push(new Date(nextDate));
694
695
                            // Add subsequent dates based on renewalsAllowed and renewalLength
696
                            for (let i = 0; i < renewalsAllowed; i++) {
697
                                nextDate.setDate(
698
                                    nextDate.getDate() + parseInt(renewalLength)
699
                                );
700
                                boldDates.push(new Date(nextDate));
701
                            }
702
679
                            // Calculate the maximum date based on the selected start date
703
                            // Calculate the maximum date based on the selected start date
680
                            const maxDate = new Date(selectedDates[0]);
704
                            let totalRenewalLength =
681
                            maxDate.setDate(maxDate.getDate() + lengthDays );
705
                                parseInt(renewalsAllowed) *
706
                                parseInt(renewalLength);
707
                            let totalIssueLength =
708
                                parseInt(issueLength) +
709
                                parseInt(totalRenewalLength);
710
711
                            const maxDate = new Date(startDate.getTime());
712
                            maxDate.setDate(
713
                                maxDate.getDate() + totalIssueLength
714
                            );
682
715
683
                            // Update the maxDate option of the flatpickr instance
716
                            // Update the maxDate option of the flatpickr instance
684
                            instance.set('maxDate', maxDate);
717
                            instance.set("maxDate", maxDate);
685
                        }
718
                        }
686
                        // Range set, update hidden fields and set available items
719
                        // Range set, update hidden fields and set available items
687
                        else if (selectedDates[0] && selectedDates[1]) {
720
                        else if (selectedDates[0] && selectedDates[1]) {
Lines 795-809 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
795
                        instance,
828
                        instance,
796
                        dayElem
829
                        dayElem
797
                    ) {
830
                    ) {
798
                        const currentDate = dayElem.dateObj
831
                        const currentDate = dayElem.dateObj;
832
                        const dateString = currentDate
799
                            .toISOString()
833
                            .toISOString()
800
                            .split("T")[0];
834
                            .split("T")[0];
801
835
802
                        if (bookingsByDate[currentDate]) {
836
                        const isBold = boldDates.some(
837
                            boldDate =>
838
                                boldDate.getTime() === currentDate.getTime()
839
                        );
840
                        if (isBold) {
841
                            dayElem.classList.add("title");
842
                        }
843
844
                        if (bookingsByDate[dateString]) {
803
                            const dots = document.createElement("span");
845
                            const dots = document.createElement("span");
804
                            dots.className = "event-dots";
846
                            dots.className = "event-dots";
805
                            dayElem.appendChild(dots);
847
                            dayElem.appendChild(dots);
806
                            bookingsByDate[currentDate].forEach(item => {
848
                            bookingsByDate[dateString].forEach(item => {
807
                                const dot = document.createElement("span");
849
                                const dot = document.createElement("span");
808
                                dot.className = "event item_" + item;
850
                                dot.className = "event item_" + item;
809
                                dots.appendChild(dot);
851
                                dots.appendChild(dot);
810
- 

Return to bug 37354