From 595bcd86bb4ed8698d16293abb4838a49175c8b0 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Wed, 24 Jul 2024 22:44:05 +0000 Subject: [PATCH] Bug 37351: Rework checkbox JS to work with paginating dataTable To Test: 1. Log in to staff client 2. Place items on items for borrowers 2-1 Place enough holds as noted above 2-2 Trap holds for borrowers 3. Open Circulation->Holds Awaiting Pickup (circ/waitingreserves.pl) 4. Click a checkbox for one or mroe holds Note->The 'Cancel selected (0)' button changes to 'Cancel selected (1)', etc. 5. Cancel selected Holds using the (Cancel selected (#) button) 6. Confirm Cancellation 7. Wait for background processes to complete, then verify holds are cancelled. 8. Return to Open Circulation->Holds Awaiting Pickup (circ/waitingreserves.pl) 9. Ensure button shows "Cancel selected (0)" 10. Click "Next >" to navigate to page 2 of holds 11. Click a checkbox for one or more holds Note->The 'Cancel selected (0)' button DOES NOT increase as boxes are selected. 12. Cancel selected Holds using the (Cancel selected (#) button) 13. Confirm Cancellation 14. Wait for background processes to complete, then verify holds are cancelled. Note-> Holds were not cancelled 15. APPLY PATCH 16. Try step 9-14 again. This time the 'Cancel selected (0)' button should update even when you paginate. 17. Make sure you try all the tables, Holds waiting, Holds waiting over X, Holds with cancellation requests. Signed-off-by: Roman Dolny Signed-off-by: Martin Renvoize (cherry picked from commit bbd1fa0bfa2604e60eb38072569d7af5ec6808d8) Signed-off-by: Lucas Gass (cherry picked from commit ca43567e86220d1a5ef645d23b500ef4a6362169) Signed-off-by: Fridolin Somers --- .../prog/en/modules/circ/waitingreserves.tt | 56 ++++++++++--------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/waitingreserves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/waitingreserves.tt index 75f50f1f64..83e6691afe 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/waitingreserves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/waitingreserves.tt @@ -264,39 +264,41 @@ }); $('.holds_table').each(function() { - var table = $(this); - var parent = table.parents('.tab-pane'); - - $('.holds_table .select_hold_all', parent).each(function() { - var count = $('.select_hold:not(:checked)', table).length; - $('.select_hold_all', table).prop('checked', !count); - }); - - $('.cancel_selected_holds', parent).html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked', parent).length)); - - $('.holds_table .select_hold_all', parent).click(function() { - var count = $('.select_hold:checked', table).length; - $('.select_hold', table).prop('checked', !count); - $(this).prop('checked', !count); - $('.cancel_selected_holds', parent).data('ids', $('.holds_table .select_hold:checked', parent).toArray().map(el => $(el).data('id'))).html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked', parent).length)); - localStorage.selectedWaitingHolds = JSON.stringify($('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id'))); - }); - - $('.holds_table .select_hold', parent).click(function() { - var count = $('.select_hold:not(:checked)', table).length; - $('.select_hold_all', table).prop('checked', !count); - $('.cancel_selected_holds', parent).data('ids', $('.holds_table .select_hold:checked', parent).toArray().map(el => $(el).data('id'))).html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked', parent).length)); - localStorage.selectedWaitingHolds = JSON.stringify($('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id'))); - }); - - $('.cancel_selected_holds', parent).click(function(e) { + var table = $(this); + var parent = table.parents('.tab-pane'); + var this_dt = $(this).closest('.holds_table').dataTable(); + parent.find('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format(this_dt.$(".select_hold:checked", {"page": "all"}).length)); + parent.find('.cancel_selected_holds').click(function(e) { e.preventDefault(); if($('.select_hold:checked', table).length) { cancel_link = $(this); $('#cancelModal').modal(); } return false; - }); + }); + }); + + $('.holds_table').on('click', '.select_hold_all', function() { + var table = $(this); + var parent = table.parents('.tab-pane'); + var this_dt = $(this).closest('.holds_table').dataTable(); + var all_pages = this_dt.fnGetNodes(); + + var all_checked = this_dt.find('.select_hold_all').prop('checked'); + this_dt.find('.select_hold' , all_pages).prop('checked', all_checked); + + var count = this_dt.$(".select_hold:checked", {"page": "all"}).length; + parent.find('.cancel_selected_holds').data('ids', this_dt.$(".select_hold:checked", {"page": "all"}).toArray().map(el => $(el).data('id'))).html(MSG_CANCEL_SELECTED.format(count)); + localStorage.selectedWaitingHolds = JSON.stringify(this_dt.$(".select_hold:checked", {"page": "all"}).toArray().map(el => $(el).data('id'))); + }); + + $('.holds_table').on('click', '.select_hold', function() { + var table = $(this); + var parent = table.parents('.tab-pane'); + var this_dt = $(this).closest('.holds_table').dataTable(); + var count = this_dt.$(".select_hold:checked", {"page": "all"}).length; + parent.find('.cancel_selected_holds').data('ids', this_dt.$(".select_hold:checked", {"page": "all"}).toArray().map(el => $(el).data('id'))).html(MSG_CANCEL_SELECTED.format(count)); + localStorage.selectedWaitingHolds = JSON.stringify(this_dt.$(".select_hold:checked", {"page": "all"}).toArray().map(el => $(el).data('id'))); }); var activeTab = localStorage.getItem("waitingreserves_activetab"); -- 2.39.5