From c018a9de48805336bfba80e02554bbc777c9aadf Mon Sep 17 00:00:00 2001 From: Salah Ghedds Date: Wed, 4 Oct 2023 14:43:54 -0400 Subject: [PATCH] Bug 34977: The "Patron Lists" only allows deleting one list at a time In the patrons lists, it's only possible to delete on list at a time. This patch add the possibility to select lists and delete them at once. TEST PLAN 1. Apply the patch. 2. Create at least 2 patron lists (Navigate to Tools > Patron lists > New patron list). 3. Select the lists you want to delete. 4. Click the "Delete selected lists" button. 5. Confirm that the selected lists have been deleted. 6. Ensure that the button cannot be used if no list is selected. Signed-off-by: David Nind Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- .../prog/en/modules/patron_lists/lists.tt | 35 +++++++++++++++++-- patron_lists/delete.pl | 12 +++++-- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/lists.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/lists.tt index 2866a8b04d..c212ac48f2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/lists.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/lists.tt @@ -47,6 +47,7 @@ + @@ -58,7 +59,10 @@ [% FOREACH l IN lists %] [% SET shared_by_other = l.owner.id != logged_in_user.id %] - +
Name Patrons in list Shared
[% l.name | html %] + + [% l.name | html %] + [% l.patron_list_patrons_rs.count || 0 | html %] [% IF l.shared %] @@ -68,6 +72,7 @@ by you [% END %] [% END %] +
@@ -147,17 +152,41 @@ var patronExportModal = $("#patronExportModal"); var patronExportModalBody = $("#patronExportModal .modal-body"); + let selectedPatronLists = new Array(); + $('#patron-lists-table').dataTable($.extend(true, {}, dataTablesDefaults, { "autoWidth": false, "aoColumnDefs": [ - { "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] } + {"bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ]} ], "sPaginationType": "full" } )); $(".delete_patron").on("click", function(){ $(".dropdown").removeClass("open"); var list = $(this).data("list-name"); - return confirmDelete( _("Are you sure you want to delete the list %s?").format(list) ); + return confirmDelete( _("Are you sure you want to delete the list %s?").format(list)); + }); + + $("#delete_selected_lists").on("click", function() { + if (selectedPatronLists.length != 0) { + if (confirm(_("Are you sure you want to delete the selected lists ?"))) { + var delete_lists_url = '/cgi-bin/koha/patron_lists/delete.pl?patron_lists_ids=' + selectedPatronLists.join("&patron_lists_ids="); + window.location.href = delete_lists_url; + } + } + }); + + $(".select_patron").on("click", function() { + if($(this).is(':checked')){ + $("#delete_selected_lists").attr("class","btn btn-default btn-sm"); + selectedPatronLists.push($(this).data("patron-list-id")); + } + else { + selectedPatronLists = selectedPatronLists.filter(item => item !== $(this).data("patron-list-id")); + if(selectedPatronLists.length === 0){ + $("#delete_selected_lists").attr("class","btn btn-default btn-sm disabled"); + } + } }); $(".print_cards").on("click", function(e){ diff --git a/patron_lists/delete.pl b/patron_lists/delete.pl index 773ec3d168..56aa9ba2ca 100755 --- a/patron_lists/delete.pl +++ b/patron_lists/delete.pl @@ -37,7 +37,15 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( ); my $id = $cgi->param('patron_list_id'); - -DelPatronList( { patron_list_id => $id } ); +my @lists_ids = $cgi->multi_param('patron_lists_ids'); + +if (defined $id && $id ne '') { + DelPatronList({ patron_list_id => $id }); +} +if (@lists_ids) { + foreach my $list_id (@lists_ids) { + DelPatronList({ patron_list_id => $list_id }); + } +} print $cgi->redirect('lists.pl'); -- 2.39.5