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

(-)a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js (-7 / +42 lines)
Lines 5-11 let bookable_items, Link Here
5
    checkouts,
5
    checkouts,
6
    booking_id,
6
    booking_id,
7
    booking_item_id,
7
    booking_item_id,
8
    booking_patron;
8
    booking_patron,
9
    booking_itemtype_id;
9
10
10
function containsAny(integers1, integers2) {
11
function containsAny(integers1, integers2) {
11
    // Create a hash set to store integers from the second array
12
    // Create a hash set to store integers from the second array
Lines 25-30 function containsAny(integers1, integers2) { Link Here
25
}
26
}
26
27
27
$("#placeBookingModal").on("show.bs.modal", function (e) {
28
$("#placeBookingModal").on("show.bs.modal", function (e) {
29
28
    // Get context
30
    // Get context
29
    let button = $(e.relatedTarget);
31
    let button = $(e.relatedTarget);
30
    let biblionumber = button.data("biblionumber");
32
    let biblionumber = button.data("biblionumber");
Lines 128-133 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
128
        placeholder: __("Search for a patron"),
130
        placeholder: __("Search for a patron"),
129
    });
131
    });
130
132
133
    // Lead and Trail days syncing
134
    let leadDays = 0;
135
    let trailDays = 0;
136
    function setBufferDays() {
137
        let rules_url = "/api/v1/circulation_rules";
138
        $.ajax({
139
            url: rules_url,
140
            type: "GET",
141
            dataType: "json",
142
            data: {
143
                category: booking_patron.category_id,
144
                itemtype: booking_itemtype_id,
145
                branchcode: pickup_library_id,
146
                rules: [ 'bookings_lead_period', 'bookings_trail_period' ]
147
            },
148
            success: function (response) {
149
                leadDays = response.bookings_lead_period;
150
                trailDays = response.bookings_trail_period;
151
            },
152
            error: function (xhr, status, error) {
153
                console.log("Circulation rules fetch failed: ", error);
154
            },
155
        });
156
    }
157
131
    // Pickup location select2
158
    // Pickup location select2
132
    let pickup_url = "/api/v1/biblios/" + biblionumber + "/pickup_locations";
159
    let pickup_url = "/api/v1/biblios/" + biblionumber + "/pickup_locations";
133
    $("#pickup_library_id").select2({
160
    $("#pickup_library_id").select2({
Lines 172-178 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
172
199
173
        $pickupSelect.prop("disabled", false);
200
        $pickupSelect.prop("disabled", false);
174
201
175
        // If pickup_library alread exists, pre-select
202
        // If pickup_library already exists, pre-select
176
        if (pickup_library_id) {
203
        if (pickup_library_id) {
177
            $pickupSelect.val(pickup_library_id).trigger("change");
204
            $pickupSelect.val(pickup_library_id).trigger("change");
178
        } else {
205
        } else {
Lines 244-249 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
244
        if ($bookingItemtypeSelect.data("loaded")) {
271
        if ($bookingItemtypeSelect.data("loaded")) {
245
            $bookingItemtypeSelect.prop("disabled", false);
272
            $bookingItemtypeSelect.prop("disabled", false);
246
        }
273
        }
274
275
        // Populate circulation rules
276
        setBufferDays();
247
    });
277
    });
248
278
249
    // Adopt periodPicker
279
    // Adopt periodPicker
Lines 524-530 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
524
554
525
                // Setup listener for itemtype select2
555
                // Setup listener for itemtype select2
526
                $("#booking_itemtype").on("select2:select", function (e) {
556
                $("#booking_itemtype").on("select2:select", function (e) {
527
                    effective_itemtype = e.params.data.id
557
                    booking_itemtype_id = e.params.data.id
528
                        ? e.params.data.id
558
                        ? e.params.data.id
529
                        : null;
559
                        : null;
530
560
Lines 533-539 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
533
                        let option = $(this);
563
                        let option = $(this);
534
                        if (option.val() != 0) {
564
                        if (option.val() != 0) {
535
                            let item_itemtype = option.data("itemtype");
565
                            let item_itemtype = option.data("itemtype");
536
                            if (item_itemtype == effective_itemtype) {
566
                            if (item_itemtype == booking_itemtype_id) {
537
                                if (
567
                                if (
538
                                    option.data("available") &&
568
                                    option.data("available") &&
539
                                    option.data("pickup")
569
                                    option.data("pickup")
Lines 546-551 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
546
                        }
576
                        }
547
                    });
577
                    });
548
                    $("#booking_item_id").trigger("change.select2");
578
                    $("#booking_item_id").trigger("change.select2");
579
580
                    // update buffer days
581
                    setBufferDays();
549
                });
582
                });
550
583
551
                // Setup listener for item select2
584
                // Setup listener for item select2
Lines 582-587 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
582
                    // handle itemtype picker
615
                    // handle itemtype picker
583
                    if (booking_item_id != 0) {
616
                    if (booking_item_id != 0) {
584
                        let itemtype = e.params.data.element.dataset.itemtype;
617
                        let itemtype = e.params.data.element.dataset.itemtype;
618
                        booking_itemtype_id = itemtype;
585
619
586
                        $("#booking_itemtype").val(itemtype);
620
                        $("#booking_itemtype").val(itemtype);
587
                        $("#booking_itemtype").trigger("change.select2");
621
                        $("#booking_itemtype").trigger("change.select2");
Lines 590-595 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
590
                        $("#booking_itemtype").prop("disabled", false);
624
                        $("#booking_itemtype").prop("disabled", false);
591
                    }
625
                    }
592
626
627
                    // update buffer days
628
                    setBufferDays();
629
593
                    // redraw pariodPicker taking selected item into account
630
                    // redraw pariodPicker taking selected item into account
594
                    periodPicker.redraw();
631
                    periodPicker.redraw();
595
                });
632
                });
Lines 760-767 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
760
                }
797
                }
761
798
762
                // Add hints for days before the start range and after the end range
799
                // Add hints for days before the start range and after the end range
763
                const leadDays = 2;
764
                const trailDays = 3;
765
                periodPicker.calendarContainer.addEventListener(
800
                periodPicker.calendarContainer.addEventListener(
766
                    "mouseover",
801
                    "mouseover",
767
                    function (event) {
802
                    function (event) {
Lines 1089-1094 $("#placeBookingModal").on("hidden.bs.modal", function (e) { Link Here
1089
    // Reset itemtype select
1124
    // Reset itemtype select
1090
    $("#booking_itemtype").val(0).trigger("change");
1125
    $("#booking_itemtype").val(0).trigger("change");
1091
    $("#booking_itemtype").prop("disabled", true);
1126
    $("#booking_itemtype").prop("disabled", true);
1127
    booking_itemtype_id = undefined;
1092
1128
1093
    // Reset pickup library select
1129
    // Reset pickup library select
1094
    $("#pickup_library_id").val(null).trigger("change");
1130
    $("#pickup_library_id").val(null).trigger("change");
1095
- 

Return to bug 34440