Bugzilla – Attachment 165998 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: (follow-up) Only display locations for bookable items
Bug-36120-follow-up-Only-display-locations-for-boo.patch (text/plain), 5.87 KB, created by
Martin Renvoize (ashimema)
on 2024-05-01 15:04:02 UTC
(
hide
)
Description:
Bug 36120: (follow-up) Only display locations for bookable items
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-05-01 15:04:02 UTC
Size:
5.87 KB
patch
obsolete
>From cad8d5450d7ba6cd957f8f77b5476fa8d10e3066 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 19 Apr 2024 16:20:42 +0100 >Subject: [PATCH] Bug 36120: (follow-up) Only display locations for bookable > items > >This patch updates the pickup locations picker to only include locations >for items that are bookable. > >We should look at doing this on the API level as it highlights some >issues with re-using item holds pickup location rules. > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > .../prog/js/modals/place_booking.js | 97 ++++++++++++++----- > 1 file changed, 71 insertions(+), 26 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 4a27fd2d36f..a649408f176 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js >@@ -7,6 +7,23 @@ let bookable_items, > booking_item_id, > booking_patron; > >+function containsAny(integers1, integers2) { >+ // Create a hash set to store integers from the second array >+ let integerSet = {}; >+ for (let i = 0; i < integers2.length; i++) { >+ integerSet[integers2[i]] = true; >+ } >+ >+ // Check if any integer from the first array exists in the hash set >+ for (let i = 0; i < integers1.length; i++) { >+ if (integerSet[integers1[i]]) { >+ return true; // Found a match, return true >+ } >+ } >+ >+ return false; // No match found >+} >+ > $("#placeBookingModal").on("show.bs.modal", function (e) { > // Get context > let button = $(e.relatedTarget); >@@ -120,6 +137,37 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > allowClear: false, > placeholder: __("Pickup location"), > }); >+ function setLocationsPicker(response) { >+ let $pickupSelect = $("#pickup_library_id"); >+ let bookableItemnumbers = bookable_items.map(function(object) { return object.item_id; }); >+ $pickupSelect.empty(); >+ >+ $.each(response, function(index, pickup_location) { >+ if (containsAny(pickup_location.pickup_items, bookableItemnumbers)) { >+ 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); >+ } >+ }); >+ >+ $pickupSelect.prop("disabled", false); >+ $pickupSelect.val(null).trigger("change"); >+ } > > // Item select2 > $("#booking_item_id").select2({ >@@ -135,7 +183,6 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > booking_patron = e.params.data; > > // Fetch pickup locations and enable picker >- let $pickupSelect = $("#pickup_library_id"); > $.ajax({ > url: pickup_url, > type: "GET", >@@ -146,31 +193,18 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > patron_id: booking_patron.patron_id, > }, > 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); >- }); >- >- $pickupSelect.prop("disabled", false); >- $pickupSelect.val(null).trigger("change"); >+ if (dataFetched === true) { >+ setLocationsPicker(response); >+ >+ } else { >+ var interval = setInterval(function() { >+ if (dataFetched === true) { >+ // Data is fetched, execute the callback and stop the interval >+ setLocationsPicker(response); >+ clearInterval(interval); >+ } >+ }, 100); >+ }; > }, > error: function (xhr, status, error) { > console.log("Pickup location fetch failed: ", error); >@@ -820,14 +854,25 @@ $("#placeBookingForm").on("submit", function (e) { > }); > > $("#placeBookingModal").on("hidden.bs.modal", function (e) { >+ >+ // Reset patron select > $("#booking_patron_id").val(null).trigger("change"); > $("#booking_patron_id").empty(); >+ $("#booking_patron_id").prop("disabled", false); > booking_patron = undefined; >+ >+ // Restet item select > $("#booking_item_id").val(0).trigger("change"); >+ $("#booking_item_id").prop("disabled", true); >+ >+ // Reset pickup library select > $("#pickup_library_id").val(null).trigger("change"); > $("#pickup_library_id").empty(); > $("#pickup_library_id").prop("disabled", true); >+ >+ // Reset booking period picker > $("#period").get(0)._flatpickr.clear(); >+ $("#period").prop("disabled", true); > $("#booking_start_date").val(""); > $("#booking_end_date").val(""); > $("#booking_id").val(""); >-- >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