Bug 34478: SQUASH further changes to batch biblio operations

This patch makes a number of changes to finish incomplete work in
668cd06e1960a3878ec1c976ce7f2e1f93688468

Initial submissions to batch biblio operations have to accommodate
POSTed file data, so this patch makes changes to instances where we were
submitting biblionumbers in a URL.

We could also choose to make a change in tools/batch_delete_records.pl
and tools/batch_record_modification.pl to handle different "list"
operations differently based on the method of submission. This patch
presents only the client-side option.

The cart presented a unique problem in that it requires that data be
passed from the pop-up window to the parent window, something which
can't as easily be done with a form as with a URL. The workaround I came
up with is to dynamically generate the form in the parent page and
trigger the submission from there.

Also changed:

- More updated CSS to handle buttons inside dropdowns inside toolbars.
- Correct op names for the "list" operation in batch modify and delete

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Owen Leonard 2024-02-23 12:08:50 +00:00 committed by Jonathan Druart
parent 41704bdb16
commit 31ed10b82d
Signed by: jonathan.druart
GPG key ID: A085E712BEF0E0F0
9 changed files with 83 additions and 46 deletions

View file

@ -31,7 +31,6 @@
touch-action: manipulation;
cursor: pointer;
background-image: none;
padding: 6px 12px;
box-shadow: none;
border-radius: 4px;
user-select: none;
@ -45,7 +44,6 @@
text-decoration: none;
background-color: #DADADA;
color: #696969;
padding: 6px 12px;
}
&:active {
@ -69,6 +67,17 @@
display: block;
}
}
&+.dropdown-menu {
.btn {
&.btn-default {
border-radius: 0;
color: black;
padding: 3px 20px;
text-align: left;
}
}
}
}
&.btn-link {

View file

@ -39,7 +39,15 @@
[% END %]
[% IF CAN_user_tools_records_batchmod %]
<li><a id="modifybiblio" href="/cgi-bin/koha/tools/batch_record_modification.pl?recordtype=biblio&op=list&recordnumber_list=[% biblionumber | html %]">Modify record using template</a></li>
<li>
<form action="/cgi-bin/koha/tools/batch_record_modification.pl" method="post">
[% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="recordtype" value="biblio" />
<input type="hidden" name="op" value="list" />
<input type="hidden" name="bib_list" value="[% biblionumber | html %]" />
<button type="submit" class="btn btn-default" id="modifybiblio">Modify record using template</a>
</form>
</li>
[% END %]
[% IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) %]

View file

@ -19,11 +19,11 @@
[% END %]
[% IF CAN_user_tools_records_batchmod %]
| <a href="#" id="batch_modify">Batch modify</a>
| <a href="#" class="results_batch_op" data-op="edit">Batch modify</a>
[% END %]
[% IF CAN_user_tools_records_batchdel %]
| <a href="#" id="batch_delete">Batch delete</a>
| <a href="#" class="results_batch_op" data-op="delete">Batch delete</a>
[% END %]
</p>
[% END %]

View file

@ -357,6 +357,12 @@
[% END %]
</div> <!-- /#selection_ops -->
<form id="build_batch_record_modification" method="post" action="/cgi-bin/koha/tools/batch_record_modification.pl">
[% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="recordtype" value="biblio">
<input type="hidden" name="op" value="cud-list">
<textarea id="recordnumber_list" name="bib_list" style="display:none"></textarea>
</form>
</div> <!-- /#searchheader -->
[% END %]

View file

@ -219,6 +219,7 @@
<div class="note"><i class="fa fa-exclamation"></i> Reminder: this action will delete all selected authorities!</div>
[% END %]
<fieldset class="action">
[% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="op" value="cud-delete" />
<input type="hidden" name="recordtype" value="[% recordtype | html %]" />
<input type="submit" class="btn btn-primary" value="Delete selected records" />

View file

@ -21,43 +21,46 @@ function placeHold () {
window.close();
}
function batchDelete(){
var checkedItems = $("input:checkbox:checked");
if ($(checkedItems).size() === 0) {
alert( __("No item was selected") );
function resultsBatchProcess( op ){
if( op == "edit" || op == "delete" ){
let checkedItems = $(".select_record:checked");
if ( checkedItems.size() === 0 ) {
alert( __("No item was selected") );
return false;
} else {
/* form markup for batch edit or delete operations */
let params = [];
const body = window.opener.document.getElementsByTagName("body");
let f = document.createElement("form");
f.setAttribute("method", "post");
if( op == "edit" ){
/* batch edit selected records */
f.setAttribute("action", "/cgi-bin/koha/tools/batch_record_modification.pl");
} else if( op == "delete" ){
/* batch delete selected records */
f.setAttribute("action", "/cgi-bin/koha/tools/batch_delete_records.pl");
}
f.innerHTML = '<input type="hidden" name="recordtype" value="biblio" /><input type="hidden" name="op" value="cud-list" />';
/* Get token from parent window */
csrf = window.opener.document.querySelectorAll('[name="csrf_token"]');
f.append( csrf[0] );
let textarea = document.createElement("textarea");
textarea.setAttribute("name", "bib_list");
textarea.setAttribute("style", "display:none");
checkedItems.each(function() {
params.push( $(this).val() );
});
textarea.value = params.join("/");
f.append( textarea );
body[0].append( f );
f.submit();
window.close();
}
} else {
return false;
}
var newloc;
var bibs = "";
checkedItems.each(function() {
var bib = $(this).val();
bibs += bib + "/";
});
newloc = "/cgi-bin/koha/tools/batch_delete_records.pl?op=list&type=biblio&bib_list=" + bibs;
window.opener.location = newloc;
window.close();
}
function batchModify(){
var checkedItems = $("input:checkbox:checked");
if ($(checkedItems).size() === 0) {
alert( __("No item was selected") );
return false;
}
var newloc;
var bibs = "";
$(checkedItems).each(function() {
var bib = $(this).val();
bibs += bib + "/";
});
newloc = "/cgi-bin/koha/tools/batch_record_modification.pl?op=list&bib_list=" + bibs + "&type=biblio";
window.opener.location = newloc;
window.close();
}
$(document).ready(function(){
@ -146,4 +149,10 @@ $(document).ready(function(){
$(".select_record").on("change",function(){
selRecord( this.value, this.checked );
});
$(".results_batch_op").on("click", function(e){
e.preventDefault();
var op = $(this).data("op");
resultsBatchProcess( op );
});
});

View file

@ -420,6 +420,7 @@ function toggleBatchOp( b ){
function resultsBatchProcess( op ){
var selected = $(".selection:checked");
var form = $("#build_batch_record_modification");
var params = [];
var url = "";
if( op == "edit" ){
@ -430,8 +431,9 @@ function resultsBatchProcess( op ){
selected.each(function() {
params.push( $(this).val() );
});
url = "/cgi-bin/koha/tools/batch_record_modification.pl?op=list&bib_list=" + params.join("/");
location.href = url;
form.attr("action", "/cgi-bin/koha/tools/batch_record_modification.pl");
$("#recordnumber_list").val( params.join("/") );
form.submit();
}
} else if( op == "delete" ){
/* batch delete selected records */
@ -441,8 +443,10 @@ function resultsBatchProcess( op ){
selected.each(function() {
params.push( $(this).val() );
});
url = "/cgi-bin/koha/tools/batch_delete_records.pl?op=list&type=biblio&bib_list=" + params.join("/");
location.href = url;
form.attr("action", "/cgi-bin/koha/tools/batch_delete_records.pl");
$("#recordnumber_list").val( params.join("/") );
form.submit();
}
} else if( op == "merge" ){
/* merge selected records */

View file

@ -61,7 +61,7 @@ if ( $op eq 'form' ) {
]
)
);
} elsif ( $op eq 'list' ) {
} elsif ( $op eq 'cud-list' ) {
# List all records to process
my @record_ids;
if ( my $bib_list = $input->param('bib_list') ) {

View file

@ -89,7 +89,7 @@ if ( $op eq 'form' ) {
]
)
);
} elsif ( $op eq 'cud-list' ) {
} elsif ( $op eq 'list' ) {
# List all records to process
my ( @records, @record_ids );
if ( my $bib_list = $input->param('bib_list') ) {