From 31ed10b82d33d043b5fc25f90908a38c67144bcc Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 23 Feb 2024 12:08:50 +0000 Subject: [PATCH] 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 --- .../intranet-tmpl/prog/css/src/_toolbar.scss | 13 ++- .../prog/en/includes/cat-toolbar.inc | 10 ++- .../prog/en/modules/basket/basket.tt | 4 +- .../prog/en/modules/catalogue/results.tt | 6 ++ .../en/modules/tools/batch_delete_records.tt | 1 + koha-tmpl/intranet-tmpl/prog/js/cart.js | 79 +++++++++++-------- .../intranet-tmpl/prog/js/pages/results.js | 12 ++- tools/batch_delete_records.pl | 2 +- tools/batch_record_modification.pl | 2 +- 9 files changed, 83 insertions(+), 46 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/_toolbar.scss b/koha-tmpl/intranet-tmpl/prog/css/src/_toolbar.scss index 4bf8263491..6246b5cff2 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/src/_toolbar.scss +++ b/koha-tmpl/intranet-tmpl/prog/css/src/_toolbar.scss @@ -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 { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc index 8bae438519..f786961e35 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -39,7 +39,15 @@ [% END %] [% IF CAN_user_tools_records_batchmod %] -
  • Modify record using template
  • +
  • +
    + [% INCLUDE 'csrf-token.inc' %] + + + +
  • [% END %] [% IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt index dd0cbac25d..efd48a74d9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt @@ -19,11 +19,11 @@ [% END %] [% IF CAN_user_tools_records_batchmod %] - | Batch modify + | Batch modify [% END %] [% IF CAN_user_tools_records_batchdel %] - | Batch delete + | Batch delete [% END %]

    [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt index c84a6d2f9b..058961463a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -357,6 +357,12 @@ [% END %] +
    + [% INCLUDE 'csrf-token.inc' %] + + + +
    [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt index 601b983f2a..d9930db1da 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt @@ -219,6 +219,7 @@
    Reminder: this action will delete all selected authorities!
    [% END %]
    + [% INCLUDE 'csrf-token.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/cart.js b/koha-tmpl/intranet-tmpl/prog/js/cart.js index a8fc5508bd..9b95c0f06e 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cart.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cart.js @@ -21,43 +21,46 @@ function placeHold () { window.close(); } -function batchDelete(){ - 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_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") ); +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 = ''; + /* 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_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 ); + }); }); diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/results.js b/koha-tmpl/intranet-tmpl/prog/js/pages/results.js index 4d4f2d74b9..283044d2ae 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/results.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/results.js @@ -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 */ diff --git a/tools/batch_delete_records.pl b/tools/batch_delete_records.pl index 0ebc53df37..9164235bc8 100755 --- a/tools/batch_delete_records.pl +++ b/tools/batch_delete_records.pl @@ -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') ) { diff --git a/tools/batch_record_modification.pl b/tools/batch_record_modification.pl index b89f67294e..ec3b339e40 100755 --- a/tools/batch_record_modification.pl +++ b/tools/batch_record_modification.pl @@ -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') ) { -- 2.39.5