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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/place_booking.inc (-5 / +1 lines)
Lines 33-43 Link Here
33
                            </li>
33
                            </li>
34
                            <li>
34
                            <li>
35
                                <label for="booking_itemtype">Itemtype: </label>
35
                                <label for="booking_itemtype">Itemtype: </label>
36
                                [% SET itemtypes = ItemTypes.Get() %]
36
                                <select id="booking_itemtype" name="booking_itemtype" disabled="disabled">
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>
37
                                </select>
42
                            <li>
38
                            <li>
43
                            <label for="booking_item_id">Item: </label>
39
                            <label for="booking_item_id">Item: </label>
(-)a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js (-67 / +93 lines)
Lines 129-173 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
129
        placeholder: __("Search for a patron"),
129
        placeholder: __("Search for a patron"),
130
    });
130
    });
131
131
132
    // Lead and Trail days syncing
132
    // Circulation rules update
133
    let leadDays = 0;
133
    let leadDays = 0;
134
    let trailDays = 0;
134
    let trailDays = 0;
135
    let boldDates = [];
135
    let boldDates = [];
136
    let issueLength;
136
    let issueLength;
137
    let renewalLength;
137
    let renewalLength;
138
    let renewalsAllowed;
138
    let renewalsAllowed;
139
140
    // Note: For now, we apply the pickup library rules for issuelength, renewalsallowed and renewalperiod.
141
    // This effectively makes these circulation rules hard coded to CircControl: ItemHomeLibrary + HomeOrHolding: holdingbranch
142
    // Whilst it would be beneficial to make this follow those rules more closely, this would require some significant thinking
143
    // around how to best display this in the calender component for the 'Any item' case.
139
    function getCirculationRules() {
144
    function getCirculationRules() {
140
        let rules_url = "/api/v1/circulation_rules";
145
        let rules_url = "/api/v1/circulation_rules";
141
        $.ajax({
146
        if (booking_patron && pickup_library_id && booking_itemtype_id) {
142
            url: rules_url,
147
            $.ajax({
143
            type: "GET",
148
                url: rules_url,
144
            dataType: "json",
149
                type: "GET",
145
            data: {
150
                dataType: "json",
146
                patron_category_id: booking_patron.category_id,
151
                data: {
147
                item_type_id: booking_itemtype_id,
152
                    patron_category_id: booking_patron.category_id,
148
                library_id: pickup_library_id,
153
                    item_type_id: booking_itemtype_id,
149
                rules: "bookings_lead_period,bookings_trail_period,issuelength,renewalsallowed,renewalperiod",
154
                    library_id: pickup_library_id,
150
            },
155
                    rules: "bookings_lead_period,bookings_trail_period,issuelength,renewalsallowed,renewalperiod",
151
            success: function (response) {
156
                },
152
                let rules = response[0];
157
                success: function (response) {
153
                issueLength = rules.issuelength;
158
                    let rules = response[0];
154
                renewalsAllowed = rules.renewalsallowed;
159
                    issueLength = rules.issuelength;
155
                renewalLength = rules.renewalperiod;
160
                    renewalsAllowed = rules.renewalsallowed;
156
                leadDays = rules.bookings_lead_period;
161
                    renewalLength = rules.renewalperiod;
157
                trailDays = rules.bookings_trail_period;
162
                    leadDays = rules.bookings_lead_period;
158
163
                    trailDays = rules.bookings_trail_period;
159
                // redraw pariodPicker taking selected item into account
164
160
                periodPicker.redraw();
165
                    // redraw pariodPicker taking selected item into account
161
166
                    periodPicker.redraw();
162
                // Enable flatpickr now we have data we need
167
163
                if (dataFetched) {
168
                    // Enable flatpickr now we have data we need
164
                    $("#period_fields :input").prop("disabled", false);
169
                    if (dataFetched) {
165
                }
170
                        $("#period_fields :input").prop("disabled", false);
166
            },
171
                    }
167
            error: function (xhr, status, error) {
172
                },
168
                console.log("Circulation rules fetch failed: ", error);
173
                error: function (xhr, status, error) {
169
            },
174
                    console.log("Circulation rules fetch failed: ", error);
170
        });
175
                },
176
            });
177
        } else {
178
            $("#period_fields :input").prop("disabled", true);
179
        }
171
    }
180
    }
172
181
173
    // Pickup location select2
182
    // Pickup location select2
Lines 304-309 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
304
                "&_per_page=-1",
313
                "&_per_page=-1",
305
            dataType: "json",
314
            dataType: "json",
306
            type: "GET",
315
            type: "GET",
316
            headers: {
317
                "x-koha-embed": "item_type",
318
            },
307
        });
319
        });
308
320
309
        // Fetch list of existing bookings
321
        // Fetch list of existing bookings
Lines 346-357 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
346
358
347
                // Total bookable items
359
                // Total bookable items
348
                let bookable = 0;
360
                let bookable = 0;
349
350
                let itemtypes = new Set();
351
                for (item of bookable_items) {
361
                for (item of bookable_items) {
352
                    bookable++;
362
                    bookable++;
353
363
354
                    // Populate item select (NOTE: Do we still need this check for pre-existing select option here?)
364
                    // Populate item select
355
                    if (
365
                    if (
356
                        !$("#booking_item_id").find(
366
                        !$("#booking_item_id").find(
357
                            "option[value='" + item.item_id + "']"
367
                            "option[value='" + item.item_id + "']"
Lines 374-391 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
374
                        $("#booking_item_id").append(newOption);
384
                        $("#booking_item_id").append(newOption);
375
                    }
385
                    }
376
386
377
                    // Build list of itemtypes
387
                    // Populate item types select
378
                    itemtypes.add(item.effective_item_type_id);
388
                    if (
379
                }
389
                        !$("#booking_itemtype").find(
380
390
                            "option[value='" +
381
                // Filter itemtypes
391
                                item.item_type.item_type_id +
382
                $("#booking_itemtype option").each(function () {
392
                                "']"
383
                    const optionValue = $(this).val();
393
                        ).length
384
                    if (!itemtypes.has(optionValue)) {
394
                    ) {
385
                        $(this).remove();
395
                        // Create a DOM Option and de-select by default
396
                        let newTypeOption = new Option(
397
                            escape_str(item.item_type.description),
398
                            item.item_type.item_type_id,
399
                            false,
400
                            false
401
                        );
402
                        $("#booking_itemtype").append(newTypeOption);
386
                    }
403
                    }
387
                });
404
                }
388
                $("#booking_itemtype").trigger("change");
405
                $("#booking_itemtype").val(null).trigger("change");
389
406
390
                // Set disable function for periodPicker
407
                // Set disable function for periodPicker
391
                let disableExists = periodPicker.config.disable.filter(
408
                let disableExists = periodPicker.config.disable.filter(
Lines 568-595 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
568
                }
585
                }
569
586
570
                // Setup listener for itemtype select2
587
                // Setup listener for itemtype select2
571
                $("#booking_itemtype").on("select2:select", function (e) {
588
                $("#booking_itemtype").on("change", function (e) {
572
                    booking_itemtype_id = e.params.data.id
589
                    let selectedValue = $(this).val(); // Get selected value (null if cleared)
573
                        ? e.params.data.id
590
                    booking_itemtype_id = selectedValue ? selectedValue : null;
574
                        : null;
591
575
592
                    // Handle item selectionue
576
                    // Disable items not of this itemtype
593
                    if (!booking_itemtype_id) {
577
                    $("#booking_item_id > option").each(function () {
594
                        // Enable all items for selection
578
                        let option = $(this);
595
                        $("#booking_item_id > option").prop("disabled", false);
579
                        if (option.val() != 0) {
596
                    } else {
580
                            let item_itemtype = option.data("itemtype");
597
                        // Disable items not of this itemtype
581
                            if (item_itemtype == booking_itemtype_id) {
598
                        $("#booking_item_id > option").each(function () {
582
                                if (
599
                            let option = $(this);
583
                                    option.data("available") &&
600
                            if (option.val() != 0) {
584
                                    option.data("pickup")
601
                                let item_itemtype = option.data("itemtype");
585
                                ) {
602
                                if (item_itemtype == booking_itemtype_id) {
586
                                    option.prop("disabled", false);
603
                                    if (
604
                                        option.data("available") &&
605
                                        option.data("pickup")
606
                                    ) {
607
                                        option.prop("disabled", false);
608
                                    }
609
                                } else {
610
                                    option.prop("disabled", true);
587
                                }
611
                                }
588
                            } else {
589
                                option.prop("disabled", true);
590
                            }
612
                            }
591
                        }
613
                        });
592
                    });
614
                    }
593
                    $("#booking_item_id").trigger("change.select2");
615
                    $("#booking_item_id").trigger("change.select2");
594
616
595
                    // Update circulation rules
617
                    // Update circulation rules
Lines 667-672 $("#placeBookingModal").on("show.bs.modal", function (e) { Link Here
667
689
668
                    // Disable patron selection change
690
                    // Disable patron selection change
669
                    $("#booking_patron_id").prop("disabled", true);
691
                    $("#booking_patron_id").prop("disabled", true);
692
693
                    pickup_library_id = $("#pickup_library_id").val();
694
695
                    // Populate circulation rules
696
                    getCirculationRules();
670
                });
697
                });
671
698
672
                // Set onChange for flatpickr
699
                // Set onChange for flatpickr
Lines 1226-1232 $("#placeBookingModal").on("hidden.bs.modal", function (e) { Link Here
1226
    $("#booking_item_id").prop("disabled", true);
1253
    $("#booking_item_id").prop("disabled", true);
1227
1254
1228
    // Reset itemtype select
1255
    // Reset itemtype select
1229
    $("#booking_itemtype").val(0).trigger("change");
1256
    $("#booking_itemtype").val(null).trigger("change");
1230
    $("#booking_itemtype").prop("disabled", true);
1257
    $("#booking_itemtype").prop("disabled", true);
1231
    booking_itemtype_id = undefined;
1258
    booking_itemtype_id = undefined;
1232
1259
1233
- 

Return to bug 37354