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 <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Salah Ghedds 2023-10-04 14:43:54 -04:00 committed by Tomas Cohen Arazi
parent 5d373a55f4
commit c018a9de48
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 41 additions and 4 deletions

View File

@ -47,6 +47,7 @@
<table id="patron-lists-table">
<thead>
<tr>
<input type="button" type="submit" class="btn btn-default btn-sm disabled" value="Delete selected lists" id="delete_selected_lists"/>
<th>Name</th>
<th>Patrons in list</th>
<th>Shared</th>
@ -58,7 +59,10 @@
[% FOREACH l IN lists %]
[% SET shared_by_other = l.owner.id != logged_in_user.id %]
<tr>
<td><a href="/cgi-bin/koha/patron_lists/list.pl?patron_list_id=[% l.patron_list_id | uri %]">[% l.name | html %]</a></td>
<td>
<input class="select_patron" type="checkbox" autocomplete="off" data-patron-list-id="[% l.patron_list_id | html %]">
<a href="/cgi-bin/koha/patron_lists/list.pl?patron_list_id=[% l.patron_list_id | uri %]">[% l.name | html %]</a>
</td>
<td>[% l.patron_list_patrons_rs.count || 0 | html %]</td>
<td>
[% IF l.shared %]
@ -68,6 +72,7 @@
by you
[% END %]
[% END %]
</td>
<td>
<div class="btn-group dropup">
@ -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){

View File

@ -37,7 +37,15 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
);
my $id = $cgi->param('patron_list_id');
my @lists_ids = $cgi->multi_param('patron_lists_ids');
DelPatronList( { patron_list_id => $id } );
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');