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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/place_booking.inc (+6 lines)
Lines 25-30 Link Here
25
                                </select>
25
                                </select>
26
                                <div class="hint">Enter patron card number or partial name</div>
26
                                <div class="hint">Enter patron card number or partial name</div>
27
                            </li>
27
                            </li>
28
                            <li>
29
                                <label class="required" for="booking_pickup">Pickup at:</label>
30
                                <select name="booking_pickup" id="pickup_library_id" required="required" disabled="true"></select>
31
                                <span class="required">Required</span>
32
                            </li>
33
                            <li>
28
                            <label for="booking_item_id">Item: </label>
34
                            <label for="booking_item_id">Item: </label>
29
                                <select name="booking_item_id" id="booking_item_id" disabled="true">
35
                                <select name="booking_item_id" id="booking_item_id" disabled="true">
30
                                    <option value="0">Any item</option>
36
                                    <option value="0">Any item</option>
(-)a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js (-3 / +85 lines)
Lines 112-117 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
112
112
113
    $("#booking_patron_id").on("select2:select", function (e) {
113
    $("#booking_patron_id").on("select2:select", function (e) {
114
        booking_patron = e.params.data;
114
        booking_patron = e.params.data;
115
        $("#pickup_library_id").prop("disabled", false);
116
    });
117
118
    // Pickup location select2
119
    let pickup_url = "/api/v1/biblios/" + biblionumber + "/pickup_locations";
120
    $("#pickup_library_id").kohaSelect({
121
        dropdownParent: $(".modal-content", "#placeBookingModal"),
122
        width: "50%",
123
        dropdownAutoWidth: true,
124
        allowClear: false,
125
        ajax: {
126
            url: pickup_url,
127
            delay: 300, // wait 300 milliseconds before triggering the request
128
            cache: true,
129
            dataType: "json",
130
            data: function (params) {
131
                var search_term = params.term === undefined ? "" : params.term;
132
                var query = {
133
                    q: JSON.stringify({
134
                        name: { "-like": "%" + search_term + "%" },
135
                    }),
136
                    _order_by: "name",
137
                    _page: params.page,
138
                };
139
                query["patron_id"] = booking_patron.patron_id;
140
                return query;
141
            },
142
            processResults: function (data) {
143
                var results = [];
144
                data.results.forEach(function (pickup_location) {
145
                    results.push({
146
                        id: pickup_location.library_id.escapeHtml(),
147
                        text: pickup_location.name.escapeHtml(),
148
                        needs_override: pickup_location.needs_override,
149
                        pickup_items: pickup_location.pickup_items,
150
                    });
151
                });
152
                return {
153
                    results: results,
154
                    pagination: { more: data.pagination.more },
155
                };
156
            },
157
        },
158
        templateResult: function (state) {
159
            var $text;
160
            if (state.needs_override === true) {
161
                $text = $(
162
                    "<span>" +
163
                        state.text +
164
                        '</span> <span style="float:right;" title="' +
165
                        __(
166
                            "This pickup location is not allowed according to circulation rules"
167
                        ) +
168
                        '"><i class="fa fa-exclamation-circle" aria-hidden="true"></i></span>'
169
                );
170
            } else {
171
                $text = $("<span>" + state.text + "</span>");
172
            }
173
            return $text;
174
        },
115
    });
175
    });
116
176
117
    // Adopt periodPicker
177
    // Adopt periodPicker
Lines 389-394 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
389
                    periodPicker.redraw();
449
                    periodPicker.redraw();
390
                });
450
                });
391
451
452
                // Setup listener for pickup location select2
453
                $("#pickup_library_id").on("select2:select", function (e) {
454
                    let valid_items = e.params.data.pickup_items;
455
456
                    // Disable items not available at the pickup location
457
                    $("#booking_item_id > option").each(function () {
458
                        let option = $(this);
459
                        let item_id = option.val();
460
                        if (valid_items.includes(parseInt(item_id))) {
461
                            option.prop("disabled", false);
462
                        } else {
463
                            option.prop("disabled", true);
464
                        }
465
                    });
466
                    $("#booking_item_id").trigger("change.select2");
467
                });
468
392
                // Set onChange for flatpickr
469
                // Set onChange for flatpickr
393
                let changeExists = periodPicker.config.onChange.filter(
470
                let changeExists = periodPicker.config.onChange.filter(
394
                    f => f.name === "periodChange"
471
                    f => f.name === "periodChange"
Lines 567-572 $("#placeBookingForm").on("submit", function (e) { Link Here
567
644
568
    let start_date = $("#booking_start_date").val();
645
    let start_date = $("#booking_start_date").val();
569
    let end_date = $("#booking_end_date").val();
646
    let end_date = $("#booking_end_date").val();
647
    let pickup_library_id = $("#pickup_library_id").val();
648
    let biblio_id = $("#booking_biblio_id").val();
570
    let item_id = $("#booking_item_id").val();
649
    let item_id = $("#booking_item_id").val();
571
650
572
    if (!booking_id) {
651
    if (!booking_id) {
Lines 575-581 $("#placeBookingForm").on("submit", function (e) { Link Here
575
            JSON.stringify({
654
            JSON.stringify({
576
                start_date: start_date,
655
                start_date: start_date,
577
                end_date: end_date,
656
                end_date: end_date,
578
                biblio_id: $("#booking_biblio_id").val(),
657
                pickup_library_id: pickup_library_id,
658
                biblio_id: biblio_id,
579
                item_id: item_id != 0 ? item_id : null,
659
                item_id: item_id != 0 ? item_id : null,
580
                patron_id: $("#booking_patron_id").find(":selected").val(),
660
                patron_id: $("#booking_patron_id").find(":selected").val(),
581
            })
661
            })
Lines 635-641 $("#placeBookingForm").on("submit", function (e) { Link Here
635
                booking_id: booking_id,
715
                booking_id: booking_id,
636
                start_date: start_date,
716
                start_date: start_date,
637
                end_date: end_date,
717
                end_date: end_date,
638
                biblio_id: $("#booking_biblio_id").val(),
718
                pickup_library_id: pickup_library_id,
719
                biblio_id: biblio_id,
639
                item_id: item_id != 0 ? item_id : null,
720
                item_id: item_id != 0 ? item_id : null,
640
                patron_id: $("#booking_patron_id").find(":selected").val(),
721
                patron_id: $("#booking_patron_id").find(":selected").val(),
641
            }),
722
            }),
Lines 693-698 $("#placeBookingModal").on("hidden.bs.modal", function (e) { Link Here
693
    $("#booking_patron_id").val(null).trigger("change");
774
    $("#booking_patron_id").val(null).trigger("change");
694
    $("#booking_patron_id").empty();
775
    $("#booking_patron_id").empty();
695
    $("#booking_item_id").val(0).trigger("change");
776
    $("#booking_item_id").val(0).trigger("change");
777
    $("#pickup_library_id").val(null).trigger("change");
778
    $("#pickup_library_id").empty();
696
    $("#period").get(0)._flatpickr.clear();
779
    $("#period").get(0)._flatpickr.clear();
697
    $("#booking_start_date").val("");
780
    $("#booking_start_date").val("");
698
    $("#booking_end_date").val("");
781
    $("#booking_end_date").val("");
699
- 

Return to bug 36120