From 1a21131883dc3a9d6d68db36fae1da863a6476c5 Mon Sep 17 00:00:00 2001 From: Emily-Rose Francoeur Date: Mon, 30 Oct 2023 14:39:21 -0400 Subject: [PATCH] Bug 31579: Improve reserve/request.pl to avoid mistakes with pick up locations The patch has been updated to ensure it does not break the existing behavior. The test plan have also been updated. This patch improve the behavior of the intranet reservation page cgi-bin/koha/reserve/request.pl It ensures that when you change the "pickup at" value in the "Hold details" section, the "Allowed pickup locations" values of each item are also changed (in the table) System preferences ensure that "UseBranchTransferLimits" is set to "Don't enforce" Prerequisites have 4 different branches (libraries): library A - logged in library, the one used to log into the intranet by the employee library B - item's home library library C - item's holding library found in the file of the user who will have the reservation library D - another library have 2 library groups (each of them is set as "Is local hold group"): group A - contains "library A" and "library B" group B - contains "library C" and "library D" have a record with multiple copies create an item for each library A, B, C, D with homebranch = holdingbranch (with barcode) Circulation rules in the "Circulation and fine rules", under "Default holds policy by item type": select the same item type you use for the items you created before set "Hold pickup library match" to "item's hold group" click on "+ Add" Test plan 1- Find a user record 2- Change the user library (set it to library C) and save 3- Click on "Search to hold" 4- Find the notice you created 5- Click on "Place a hold > Place hold for [User]" 6- Check the "pickup at" field in the top section and those in the column "Allowed pickup locations" 7- Change the library of the top "pickup at" field 8- Check the "Allowed pickup locations" of each item 9- Notice that the "Allowed pickup locations" columns are not adjusted 10- Apply the patch 11- Refresh the page 12- Repeat steps 6,7 and 8 13- Notice that the pickup locations change only if they are in the same library group 14- Go to "Circulation and fine rule" (in Koha administration) and delete the the rule you created under "Default holds policy by item type" 15- Repeat step 1,3,4,5,6,7 and 8 16- Notice that all the "Allowed pickup locations" columns are adjusted --- .../prog/en/modules/reserve/request.tt | 55 +++++++++++++++++-- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index 3f0a1973b4..56f0a9f062 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -1330,6 +1330,8 @@ $.fn.select2.defaults.set("width", "100%" ); $.fn.select2.defaults.set("dropdownAutoWidth", true ); + var pickup_locations_by_item = {}; + $(document).ready(function() { $('#cancellation-reason-fieldset').hide(); $('.rank-request').on('change', function() { @@ -1366,15 +1368,57 @@ ToggleHoldsToPlace(); }); - [% IF Koha.Preference('UseBranchTransferLimits') %] - $("#pickup").on('change', function(){ - var pickup = $("#pickup").val(); + function setPickupLocation (select) { + var item_id = select.data('item-id'); + var url = '/api/v1/items/' + encodeURIComponent(item_id) + '/pickup_locations'; + + $.ajax({ + dataType: 'json', + url: url, + data: { + "q": JSON.stringify({ + "name": { + "-like":'%'+(($.param().term === undefined) ? '' : $.param().term)+'%' + } + }), + "_order_by": "name", + "_page": $.param().page, + "patron_id": select.data('patron-id') + }, + success: function(data) { + pickup_locations_by_item[`${item_id}`] = []; + data.forEach(function (pickup_location) { + pickup_locations_by_item[`${item_id}`].push({ + "id": pickup_location.library_id, + "name": pickup_location.name + }); + }); + } + }); + } + + $("#pickup").on('change', function() { + var pickup = $("#pickup").val(); + [% IF Koha.Preference('UseBranchTransferLimits') %] var url = "?pickup=" + pickup; url += "&borrowernumber=" + borrowernumber; url += "&biblionumber=" + biblionumbers[0]; window.location.replace(url); - }); - [% END %] + [% ELSE %] + $(".pickup_locations").each(function () { + const pickup_locations = pickup_locations_by_item[$(this).data('item-id')]; + if (pickup_locations) { + const location = pickup_locations.find((pickup_location) => pickup_location.id === pickup); + if (location) { + var option = $("