Bugzilla – Attachment 165997 Details for
Bug 36120
Add pickup locations to bookings
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36120: Ensure pickup location and item can be picked in either order
Bug-36120-Ensure-pickup-location-and-item-can-be-p.patch (text/plain), 10.21 KB, created by
Martin Renvoize (ashimema)
on 2024-05-01 15:03:59 UTC
(
hide
)
Description:
Bug 36120: Ensure pickup location and item can be picked in either order
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-05-01 15:03:59 UTC
Size:
10.21 KB
patch
obsolete
>From 9f4f98c627f2b7ea550abaf66fff6052d2575963 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 18 Apr 2024 17:56:15 +0100 >Subject: [PATCH] Bug 36120: Ensure pickup location and item can be picked in > either order > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > .../prog/js/modals/place_booking.js | 170 +++++++++++------- > 1 file changed, 101 insertions(+), 69 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js >index 385604350b9..4a27fd2d36f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js >@@ -110,68 +110,79 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > placeholder: __("Search for a patron"), > }); > >- $("#booking_patron_id").on("select2:select", function (e) { >- booking_patron = e.params.data; >- $("#pickup_library_id").prop("disabled", false); >- }); >- > // Pickup location select2 > let pickup_url = "/api/v1/biblios/" + biblionumber + "/pickup_locations"; >- $("#pickup_library_id").kohaSelect({ >+ $("#pickup_library_id").select2({ > dropdownParent: $(".modal-content", "#placeBookingModal"), > width: "50%", > dropdownAutoWidth: true, >+ minimumResultsForSearch: 10, > allowClear: false, >- ajax: { >+ placeholder: __("Pickup location"), >+ }); >+ >+ // Item select2 >+ $("#booking_item_id").select2({ >+ dropdownParent: $(".modal-content", "#placeBookingModal"), >+ width: "50%", >+ dropdownAutoWidth: true, >+ minimumResultsForSearch: 10, >+ allowClear: false, >+ }); >+ >+ // Patron selection triggers >+ $("#booking_patron_id").on("select2:select", function (e) { >+ booking_patron = e.params.data; >+ >+ // Fetch pickup locations and enable picker >+ let $pickupSelect = $("#pickup_library_id"); >+ $.ajax({ > url: pickup_url, >- delay: 300, // wait 300 milliseconds before triggering the request >- cache: true, >+ type: "GET", > dataType: "json", >- data: function (params) { >- var search_term = params.term === undefined ? "" : params.term; >- var query = { >- q: JSON.stringify({ >- name: { "-like": "%" + search_term + "%" }, >- }), >- _order_by: "name", >- _page: params.page, >- }; >- query["patron_id"] = booking_patron.patron_id; >- return query; >+ data: { >+ _order_by: "name", >+ _per_page: "-1", >+ patron_id: booking_patron.patron_id, > }, >- processResults: function (data) { >- var results = []; >- data.results.forEach(function (pickup_location) { >- results.push({ >- id: pickup_location.library_id.escapeHtml(), >- text: pickup_location.name.escapeHtml(), >- needs_override: pickup_location.needs_override, >- pickup_items: pickup_location.pickup_items, >- }); >+ success: function (response) { >+ $pickupSelect.empty(); >+ >+ $.each(response, function (index, pickup_location) { >+ let option = $( >+ '<option value="' + >+ pickup_location.library_id + >+ '">' + >+ pickup_location.name + >+ "</option>" >+ ); >+ >+ option.attr( >+ "data-needs_override", >+ pickup_location.needs_override >+ ); >+ option.attr( >+ "data-pickup_items", >+ pickup_location.pickup_items.join(",") >+ ); >+ >+ $pickupSelect.append(option); > }); >- return { >- results: results, >- pagination: { more: data.pagination.more }, >- }; >+ >+ $pickupSelect.prop("disabled", false); >+ $pickupSelect.val(null).trigger("change"); > }, >- }, >- templateResult: function (state) { >- var $text; >- if (state.needs_override === true) { >- $text = $( >- "<span>" + >- state.text + >- '</span> <span style="float:right;" title="' + >- __( >- "This pickup location is not allowed according to circulation rules" >- ) + >- '"><i class="fa fa-exclamation-circle" aria-hidden="true"></i></span>' >- ); >- } else { >- $text = $("<span>" + state.text + "</span>"); >- } >- return $text; >- }, >+ error: function (xhr, status, error) { >+ console.log("Pickup location fetch failed: ", error); >+ }, >+ }); >+ >+ // Enable item selection if item data is also fetched >+ let $bookingItemSelect = $("#booking_item_id"); >+ $bookingItemSelect.data("patron", true); >+ if ($bookingItemSelect.data("loaded")) { >+ $bookingItemSelect.prop("disabled", false); >+ } > }); > > // Adopt periodPicker >@@ -224,15 +235,6 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > bookings.unshift(booking); > } > >- // Item select2 >- $("#booking_item_id").select2({ >- dropdownParent: $(".modal-content", "#placeBookingModal"), >- width: "50%", >- dropdownAutoWidth: true, >- minimumResultsForSearch: 20, >- placeholder: __("Select item"), >- }); >- > // Update flatpickr mode > periodPicker.set("mode", "range"); > >@@ -254,10 +256,7 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > false, > false > ); >- newOption.setAttribute( >- "data-available", >- true >- ); >+ newOption.setAttribute("data-available", true); > > // Append it to the select > $("#booking_item_id").append(newOption); >@@ -450,20 +449,46 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > ? e.params.data.id > : null; > >+ // Disable invalid pickup locations >+ $("#pickup_library_id > option").each(function () { >+ let option = $(this); >+ if (booking_item_id == 0) { >+ option.prop("disabled", false); >+ } else { >+ let valid_items = String( >+ option.data("pickup_items") >+ ) >+ .split(",") >+ .map(Number); >+ if ( >+ valid_items.includes(parseInt(booking_item_id)) >+ ) { >+ option.prop("disabled", false); >+ } else { >+ option.prop("disabled", true); >+ } >+ } >+ }); >+ $("#pickup_library_id").trigger("change.select2"); >+ >+ // Disable patron selection change >+ $("#booking_patron_id").prop("disabled", true); >+ > // redraw pariodPicker taking selected item into account > periodPicker.redraw(); > }); > > // Setup listener for pickup location select2 > $("#pickup_library_id").on("select2:select", function (e) { >- let valid_items = e.params.data.pickup_items; >- valid_items.push(0); >+ let valid_items = >+ e.params.data.element.dataset.pickup_items.split(","); >+ valid_items.push("0"); > > // Disable items not available at the pickup location > $("#booking_item_id > option").each(function () { > let option = $(this); > let item_id = option.val(); >- if (valid_items.includes(parseInt(item_id))) { >+ if (valid_items.includes(item_id)) { > option.attr("data-pickup", true); > if (option.data("available")) { > option.prop("disabled", false); >@@ -474,6 +499,9 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > } > }); > $("#booking_item_id").trigger("change.select2"); >+ >+ // Disable patron selection change >+ $("#booking_patron_id").prop("disabled", true); > }); > > // Set onChange for flatpickr >@@ -564,8 +592,12 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > $("#period_fields :input").prop("disabled", false); > > // Redraw select with new options and enable >- $("#booking_item_id").trigger("change"); >- $("#booking_item_id").prop("disabled", false); >+ let $bookingItemSelect = $("#booking_item_id"); >+ $bookingItemSelect.trigger("change"); >+ $bookingItemSelect.data("loaded", true); >+ if ($bookingItemSelect.data("patron")) { >+ $bookingItemSelect.prop("disabled", false); >+ } > > // Set the flag to indicate that data has been fetched > dataFetched = true; >-- >2.44.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36120
:
162911
|
162912
|
162914
|
162915
|
162916
|
162917
|
162918
|
162919
|
162920
|
162921
|
162922
|
162923
|
162924
|
162925
|
162926
|
162927
|
162928
|
162976
|
163218
|
163219
|
163220
|
163221
|
163222
|
163223
|
163224
|
163435
|
163436
|
163437
|
163438
|
163439
|
163440
|
163441
|
163442
|
163443
|
163444
|
163445
|
163446
|
163447
|
163448
|
163565
|
163566
|
163567
|
163568
|
163569
|
163570
|
163571
|
163603
|
163604
|
163605
|
163606
|
163607
|
163608
|
163609
|
163610
|
163611
|
163612
|
163613
|
163635
|
163636
|
165140
|
165175
|
165176
|
165177
|
165178
|
165179
|
165180
|
165181
|
165182
|
165183
|
165184
|
165185
|
165186
|
165187
|
165188
|
165214
|
165215
|
165216
|
165419
|
165420
|
165421
|
165422
|
165423
|
165424
|
165425
|
165426
|
165427
|
165428
|
165429
|
165430
|
165431
|
165432
|
165433
|
165434
|
165435
|
165984
|
165985
|
165986
|
165987
|
165988
|
165989
|
165990
|
165991
|
165992
|
165993
|
165994
|
165995
|
165996
| 165997 |
165998
|
165999
|
166000
|
166001
|
166002