Bug 33560: Batch edit link broken if subscriptions are selected using "select all" link

This patch revises the process by which the serials search results page
redirects to the batch edit page based on which checkboxes are checked.

To test, apply the patch and go to serials. You should have some
subscriptions which are open and some which are closed.

- Perform a search which will return at least one result under each tab
  (Open and Closed).
  - Checking one or more checkboxes should activate the "Edit selected
    serials" link, which should work correctly to redirect you to the
    batch edit page.
  - Unchecking all the checkboxes should make the edit link disappear.
  - Check that the "Select all" and "Clear all" links work the same way
    manually checking checkboxes does.
  - Confirm that controls under each tab work correctly just for the
    results under that tab.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Owen Leonard 2023-04-18 16:51:04 +00:00 committed by Tomas Cohen Arazi
parent c652ed4b1d
commit 9e26828a62
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -65,16 +65,16 @@
<a class="select-all" href="#" data-tab="[% tab | html %]"><i class="fa fa-check"></i> Select all</a>
|
<a class="clear-all" href="#" data-tab="[% tab | html %]"><i class="fa fa-remove"></i> Clear all</a>
<span class="itemselection_actions">
<span class="itemselection_actions [% tab | html %]">
| Actions:
<a class="itemselection_action_modify"><i class="fa fa-pencil"></i> Edit selected serials</a>
<a href="#" data-tab="[% tab | html %]" class="itemselection_action_modify"><i class="fa fa-pencil"></i> Edit selected serials</a>
</span>
</div>
[% END %]
<table>
<thead>
<tr>
<th></th>
<th class="NoSort noExport"></th>
<th>ISSN</th>
<th class="anti-the">Title</th>
<th>Notes</th>
@ -96,7 +96,7 @@
<tr>
<td>
[% UNLESS subscription.cannotedit %]
<input type="checkbox" name="subscriptionid" value="[% subscription.subscriptionid | html %]" />
<input type="checkbox" name="subscriptionid" value="[% subscription.subscriptionid | html %]" class="[% tab | html %]" />
[% ELSE %]
<input type="checkbox" name="subscriptionid" value="[% subscription.subscriptionid | html %]" disabled="disabled" title="You cannot edit this subscription" />
[% END %]
@ -322,30 +322,30 @@
[% Asset.js("js/serials-toolbar.js") | $raw %]
<script>
function itemSelectionBuildEditLink(div) {
var subscription_ids = new Array();
$("input[name='subscriptionid'][type='checkbox']:checked", div).each(function() {
subscription_ids.push($(this).val());
});
if (subscription_ids.length > 0) {
var url = "[% edit_action_link | html %]";
url += '&subscriptionid=' + subscription_ids.join('&subscriptionid=');
$('a.itemselection_action_modify').attr('href', url);
} else {
return false;
}
return true;
}
function itemSelectionBuildEditLink( tab ) {
var subscription_ids = new Array();
$( "input:checkbox." + tab + ":checked" ).each(function() {
subscription_ids.push( $(this).val() );
});
function itemSelectionBuildActionLinks(tab) {
var div = $("#" + tab);
var modify_link_ok = itemSelectionBuildEditLink(div);
if (modify_link_ok) {
$('.itemselection_actions', div).show();
} else {
$('.itemselection_actions', div).hide();
}
if (subscription_ids.length > 0) {
var url = "[% edit_action_link | html %]";
url += '&subscriptionid=' + subscription_ids.join('&subscriptionid=');
location.href = url;
} else {
return false;
}
}
function enableCheckboxActions( tab ){
// Enable/disable controls if checkboxes are checked
var checked_count = $("input:checkbox." + tab + ":checked").length;
if( checked_count > 0 ){
$(".itemselection_actions." + tab ).show();
} else {
$(".itemselection_actions." + tab ).hide();
}
}
$(document).ready(function() {
var osrlt = $("#opened_panel table").dataTable($.extend(true, {}, dataTablesDefaults, {
@ -385,17 +385,24 @@
$('.select-all, .clear-all').on('click', function(e) {
e.preventDefault();
var checkboxes = $(this).parents('form').find('input[type="checkbox"]');
checkboxes.prop('checked', $(this).hasClass('select-all'));
var tab = $(this).data("tab");
itemSelectionBuildActionLinks(tab);
var checkboxes = $("input:checkbox." + tab );
checkboxes.prop('checked', $(this).hasClass('select-all')).change();
enableCheckboxActions(tab);
});
itemSelectionBuildActionLinks("opened");
itemSelectionBuildActionLinks("closed");
enableCheckboxActions("opened");
enableCheckboxActions("closed");
$("input[name='subscriptionid'][type='checkbox']").change(function() {
var div = $(this).parents('form').parent().attr("id");
itemSelectionBuildActionLinks(div);
var tab = $(this).attr("class");
enableCheckboxActions( tab );
});
$(".itemselection_action_modify").on("click", function(e){
e.preventDefault();
var tab = $(this).data("tab");
itemSelectionBuildEditLink( tab );
});
[% IF ( mana ) %]