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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/place_booking.inc (+9 lines)
Lines 1-3 Link Here
1
[% USE ItemTypes %]
1
<!-- Place booking modal -->
2
<!-- Place booking modal -->
2
<div class="modal" id="placeBookingModal" tabindex="-1" role="dialog" aria-labelledby="placeBookingLabel">
3
<div class="modal" id="placeBookingModal" tabindex="-1" role="dialog" aria-labelledby="placeBookingLabel">
3
    <form method="get" id="placeBookingForm">
4
    <form method="get" id="placeBookingForm">
Lines 30-35 Link Here
30
                                <select name="booking_pickup" id="pickup_library_id" required="required" disabled="disabled"></select>
31
                                <select name="booking_pickup" id="pickup_library_id" required="required" disabled="disabled"></select>
31
                                <span class="required">Required</span>
32
                                <span class="required">Required</span>
32
                            </li>
33
                            </li>
34
                            <li>
35
                                <label for="booking_itemtype">Itemtype: </label>
36
                                [% SET itemtypes = ItemTypes.Get() %]
37
                                <select id="booking_itemtype" name="booking_itemtype" disabled="true">
38
                                    [% FOREACH itemtype IN itemtypes %]
39
                                        <option value="[% itemtype.itemtype | html %]">[% itemtype.description | html%]</option>
40
                                    [% END %]
41
                                </select>
33
                            <li>
42
                            <li>
34
                            <label for="booking_item_id">Item: </label>
43
                            <label for="booking_item_id">Item: </label>
35
                                <select name="booking_item_id" id="booking_item_id" disabled="disabled">
44
                                <select name="booking_item_id" id="booking_item_id" disabled="disabled">
(-)a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js (-3 / +86 lines)
Lines 180-185 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
180
        }
180
        }
181
    }
181
    }
182
182
183
    // Itemtype select2
184
    $("#booking_itemtype").select2({
185
        dropdownParent: $(".modal-content", "#placeBookingModal"),
186
        width: "50%",
187
        allowClear: true,
188
        dropdownAutoWidth: true,
189
        minimumResultsForSearch: 20,
190
        placeholder: __("Item type"),
191
    });
192
183
    // Item select2
193
    // Item select2
184
    $("#booking_item_id").select2({
194
    $("#booking_item_id").select2({
185
        dropdownParent: $(".modal-content", "#placeBookingModal"),
195
        dropdownParent: $(".modal-content", "#placeBookingModal"),
Lines 227-232 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
227
        if ($bookingItemSelect.data("loaded")) {
237
        if ($bookingItemSelect.data("loaded")) {
228
            $bookingItemSelect.prop("disabled", false);
238
            $bookingItemSelect.prop("disabled", false);
229
        }
239
        }
240
241
        // Enable itemtype selection if item data if also fetched
242
        let $bookingItemtypeSelect = $("#booking_itemtype");
243
        $bookingItemtypeSelect.data("patron", true);
244
        if ($bookingItemtypeSelect.data("loaded")) {
245
            $bookingItemtypeSelect.prop("disabled", false);
246
        }
230
    });
247
    });
231
248
232
    // Adopt periodPicker
249
    // Adopt periodPicker
Lines 285-292 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
285
                // Total bookable items
302
                // Total bookable items
286
                let bookable = 0;
303
                let bookable = 0;
287
304
305
                let itemtypes = new Set();
288
                for (item of bookable_items) {
306
                for (item of bookable_items) {
289
                    bookable++;
307
                    bookable++;
308
290
                    // Populate item select (NOTE: Do we still need this check for pre-existing select option here?)
309
                    // Populate item select (NOTE: Do we still need this check for pre-existing select option here?)
291
                    if (
310
                    if (
292
                        !$("#booking_item_id").find(
311
                        !$("#booking_item_id").find(
Lines 301-312 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
301
                            false
320
                            false
302
                        );
321
                        );
303
                        newOption.setAttribute("data-available", true);
322
                        newOption.setAttribute("data-available", true);
323
                        newOption.setAttribute(
324
                            "data-itemtype",
325
                            item.effective_item_type_id
326
                        );
304
327
305
                        // Append it to the select
328
                        // Append it to the select
306
                        $("#booking_item_id").append(newOption);
329
                        $("#booking_item_id").append(newOption);
307
                    }
330
                    }
331
332
                    // Build list of itemtypes
333
                    itemtypes.add(item.effective_item_type_id);
308
                }
334
                }
309
335
336
                // Filter itemtypes
337
                $("#booking_itemtype option").each(function () {
338
                    const optionValue = $(this).val();
339
                    if (!itemtypes.has(optionValue)) {
340
                        $(this).remove();
341
                    }
342
                });
343
                $("#booking_itemtype").trigger("change");
344
310
                // Set disable function for periodPicker
345
                // Set disable function for periodPicker
311
                let disableExists = periodPicker.config.disable.filter(
346
                let disableExists = periodPicker.config.disable.filter(
312
                    f => f.name === "dateDisable"
347
                    f => f.name === "dateDisable"
Lines 487-492 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
487
                    });
522
                    });
488
                }
523
                }
489
524
525
                // Setup listener for itemtype select2
526
                $("#booking_itemtype").on("select2:select", function (e) {
527
                    effective_itemtype = e.params.data.id
528
                        ? e.params.data.id
529
                        : null;
530
531
                    // Disable items not of this itemtype
532
                    $("#booking_item_id > option").each(function () {
533
                        let option = $(this);
534
                        if (option.val() != 0) {
535
                            let item_itemtype = option.data("itemtype");
536
                            if (item_itemtype == effective_itemtype) {
537
                                if (
538
                                    option.data("available") &&
539
                                    option.data("pickup")
540
                                ) {
541
                                    option.prop("disabled", false);
542
                                }
543
                            } else {
544
                                option.prop("disabled", true);
545
                            }
546
                        }
547
                    });
548
                    $("#booking_item_id").trigger("change.select2");
549
                });
550
490
                // Setup listener for item select2
551
                // Setup listener for item select2
491
                $("#booking_item_id").on("select2:select", function (e) {
552
                $("#booking_item_id").on("select2:select", function (e) {
492
                    booking_item_id = e.params.data.id
553
                    booking_item_id = e.params.data.id
Lines 518-523 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
518
                    // Disable patron selection change
579
                    // Disable patron selection change
519
                    $("#booking_patron_id").prop("disabled", true);
580
                    $("#booking_patron_id").prop("disabled", true);
520
581
582
                    // handle itemtype picker
583
                    if (booking_item_id != 0) {
584
                        let itemtype = e.params.data.element.dataset.itemtype;
585
586
                        $("#booking_itemtype").val(itemtype);
587
                        $("#booking_itemtype").trigger("change.select2");
588
                        $("#booking_itemtype").prop("disabled", true);
589
                    } else {
590
                        $("#booking_itemtype").prop("disabled", false);
591
                    }
592
521
                    // redraw pariodPicker taking selected item into account
593
                    // redraw pariodPicker taking selected item into account
522
                    periodPicker.redraw();
594
                    periodPicker.redraw();
523
                });
595
                });
Lines 691-697 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
691
                periodPicker.redraw();
763
                periodPicker.redraw();
692
                $("#period_fields :input").prop("disabled", false);
764
                $("#period_fields :input").prop("disabled", false);
693
765
694
                // Redraw select with new options and enable
766
                // Redraw itemtype select with new options and enable
767
                let $bookingItemtypeSelect = $("#booking_itemtype");
768
                $bookingItemtypeSelect.trigger("change");
769
                $bookingItemtypeSelect.data("loaded", true);
770
                if ($bookingItemtypeSelect.data("patron")) {
771
                    $bookingItemtypeSelect.prop("disabled", false);
772
                }
773
774
                // Redraw item select with new options and enable
695
                let $bookingItemSelect = $("#booking_item_id");
775
                let $bookingItemSelect = $("#booking_item_id");
696
                $bookingItemSelect.trigger("change");
776
                $bookingItemSelect.trigger("change");
697
                $bookingItemSelect.data("loaded", true);
777
                $bookingItemSelect.data("loaded", true);
Lines 940-949 $("#placeBookingModal").on("hidden.bs.modal", function (e) { Link Here
940
    $("#booking_patron_id").prop("disabled", false);
1020
    $("#booking_patron_id").prop("disabled", false);
941
    booking_patron = undefined;
1021
    booking_patron = undefined;
942
1022
943
    // Restet item select
1023
    // Reset item select
944
    $("#booking_item_id").val(0).trigger("change");
1024
    $("#booking_item_id").val(0).trigger("change");
945
    $("#booking_item_id").prop("disabled", true);
1025
    $("#booking_item_id").prop("disabled", true);
946
1026
1027
    // Reset itemtype select
1028
    $("#booking_itemtype").val(0).trigger("change");
1029
    $("#booking_itemtype").prop("disabled", true);
1030
947
    // Reset pickup library select
1031
    // Reset pickup library select
948
    $("#pickup_library_id").val(null).trigger("change");
1032
    $("#pickup_library_id").val(null).trigger("change");
949
    $("#pickup_library_id").empty();
1033
    $("#pickup_library_id").empty();
950
- 

Return to bug 34440