From b6233aeb84aa7b0ca5480199f7111b88ffee958c Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Wed, 30 Jul 2025 11:28:48 +0000 Subject: [PATCH] Bug 40551: Make patron page holds table use API endpoint for cancellation Test plan, k-t-d, patches applied: 1) Search for 'music': http://localhost:8081/cgi-bin/koha/catalogue/search.pl?q=music 2) Click the 'Select all' link on the left of the search toolbar 3) Click the 'Place hold' button on the same toolbar 4) On the patron input, add 'koha' 5) You need to pick the 'Pickup location' specifically for each hold. Click 'Place holds' 6) On this screen (reserve/request.pl) ensure the table(s) work. Selecting all works. Canceling selected works (it doesn't refresh immediatelly, it's a background job). Suspend works as before, sorting, etc. 7) Now visit the patron details page: http://localhost:8081/cgi-bin/koha/members/moremember.pl?borrowernumber=51 8) Click the 'Holds' tab. 9) Test that selecting multiple holds and canceling selected works. 10) Test that canceling a specific hold works. 11) Repeat steps 8-10 but for the circulation page from patron details at: http://localhost:8081/cgi-bin/koha/circ/circulation.pl?borrowernumber=51 Signed-off-by: Phillip Berg Signed-off-by: Andrew Fuerste Henry Signed-off-by: Lucas Gass --- koha-tmpl/intranet-tmpl/prog/js/holds.js | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/js/holds.js b/koha-tmpl/intranet-tmpl/prog/js/holds.js index 38bab55f47..5e6537fa72 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/holds.js +++ b/koha-tmpl/intranet-tmpl/prog/js/holds.js @@ -1177,6 +1177,62 @@ $(document).ready(function () { return false; }); + if (holds_table_patron_page()) { + $("#cancelModalConfirmBtn").click(function (e) { + e.preventDefault(); + let formInputs = {}; + formInputs["reserve_id"] = $( + "#cancel_modal_form :input[name='reserve_id']" + ) + .map(function () { + return $(this).val(); + }) + .get(); + formInputs["cancellation-reason"] = $( + "#cancel_modal_form :input[name='cancellation-reason']" + ).val(); + cancel_holds( + formInputs["reserve_id"], + formInputs["cancellation-reason"] + ) + .success(function () { + holdsTable.api().ajax.reload(); + }) + .fail(function (jqXHR) { + $("#cancelModal .modal-body").prepend( + '
' + + jqXHR.responseJSON.error + + "
" + ); + $("#cancelModalConfirmBtn").prop("disabled", true); + }) + .done(function () { + $("#cancelModal").modal("hide"); + if ($(".select_hold_all").prop("checked")) { + $(".select_hold_all").click(); + } + }); + }); + } + + function cancel_holds(hold_ids, cancellation_reason) { + return $.ajax({ + method: "DELETE", + url: "/api/v1/holds/cancellation_bulk", + contentType: "application/json", + data: JSON.stringify({ + hold_ids: hold_ids, + cancellation_reason: cancellation_reason, + }), + }); + } + + $("#cancelModal").on("hidden.bs.modal", function () { + $("#cancelModal .modal-body .alert-danger").remove(); + $("#cancelModalConfirmBtn").prop("disabled", false); + holdsTable.api().ajax.reload(); + }); + $("#group-modal-submit").click(function (e) { e.preventDefault(); let selected_holds = get_selected_holds_data();