From 743f40a202ba915dccbf35058e5b7ecf707e3e67 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Mon, 6 Apr 2020 20:39:35 +0000 Subject: [PATCH] Bug 23349: Add batch operations to staff interface catalog search results This patch adds three new options to the staff interface catalog search results for users with cataloging permission: batch edit, batch delete, and merge. The choices are found in an "Edit" menu which is disabled by default. Checking any boxes in the search results table enables the button. To test, apply the patch and log in to Koha as a user with edit_catalogue permission. - Perform a search in the catalog - You should see a disabled "Edit" button in the toolbar at the top of the search results table. - Check a single checkbox. The button should become enabled. - Test the "Batch edit" and "Batch delete" menu items. They should work correctly. - Test the "Merge records" item. It should warn you that you must select at least two records. - Check more than one checkbox and test each menu item again. All should work as expected. - Log in to the staff client as a user who does not have edit_catalogue permission. The "Edit" menu should no longer appear on the search results page. Signed-off-by: Abbey Holt Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- .../prog/en/modules/catalogue/results.tt | 10 +++ .../intranet-tmpl/prog/js/pages/results.js | 68 ++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) 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 c24843edcc..220d7de5ea 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -165,6 +165,16 @@ +
+ + +
[% END %] [% IF ( searchdesc ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/results.js b/koha-tmpl/intranet-tmpl/prog/js/pages/results.js index 0887f4ae8c..4eaf172125 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/results.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/results.js @@ -1,4 +1,4 @@ -/* global KOHA biblionumber new_results_browser addMultiple vShelfAdd openWindow search_result SEARCH_RESULTS PREF_AmazonCoverImages PREF_LocalCoverImages PREF_IntranetCoce PREF_CoceProviders CoceHost CoceProviders addRecord delSingleRecord PREF_BrowseResultSelection resetSearchContext addBibToContext delBibToContext getContextBiblioNumbers MSG_NO_ITEM_SELECTED MSG_NO_ITEM_SELECTED holdfor_cardnumber holdforclub strQuery MSG_NON_RESERVES_SELECTED PREF_NotHighlightedWords PLACE_HOLD */ +/* global KOHA biblionumber new_results_browser addMultiple vShelfAdd openWindow search_result SEARCH_RESULTS PREF_AmazonCoverImages PREF_LocalCoverImages PREF_IntranetCoce PREF_CoceProviders CoceHost CoceProviders addRecord delSingleRecord PREF_BrowseResultSelection resetSearchContext addBibToContext delBibToContext getContextBiblioNumbers MSG_NO_ITEM_SELECTED MSG_NO_ITEM_SELECTED holdfor_cardnumber holdforclub strQuery MSG_NON_RESERVES_SELECTED PREF_NotHighlightedWords PLACE_HOLD _ */ if( PREF_AmazonCoverImages ){ $(window).load(function() { @@ -152,6 +152,11 @@ $(document).ready(function() { } $(".selection").change(function(){ + if( $(".selection:checked").length > 0 ){ + toggleBatchOp( true ); + } else { + toggleBatchOp( false ); + } if ( $(this).is(':checked') == true ) { addBibToContext( $(this).val() ); } else { @@ -170,6 +175,16 @@ $(document).ready(function() { } } }); + + if( $(".selection:checked") > 0 ){ + toggleBatchOp( true ); + } + + $(".results_batch_op").on("click", function(e){ + e.preventDefault(); + var op = $(this).data("op"); + resultsBatchProcess( op ); + }); }); @@ -306,3 +321,54 @@ function verify_images() { } }); } + +function toggleBatchOp( b ){ + var results_batch_ops = $("#results_batch_ops"); + if( b ){ + results_batch_ops.removeClass("disabled"); + } else { + results_batch_ops.addClass("disabled"); + } +} + +function resultsBatchProcess( op ){ + var selected = $(".selection:checked"); + var params = []; + var url = ""; + if( op == "edit" ){ + // batch edit selected records + if ( selected.length < 1 ){ + alert( _("You must select at least one record") ); + } else { + 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; + } + } else if( op == "delete" ){ + // batch delete selected records + if ( selected.length < 1) { + alert( _("You must select at least one record") ); + } else { + 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; + } + } else if( op == "merge" ){ + // merge selected records + if ( selected.length < 2) { + alert( _("At least two records must be selected for merging") ); + } else { + selected.each(function() { + params.push('biblionumber=' + $(this).val()); + }); + url = "/cgi-bin/koha/cataloguing/merge.pl?" + params.join("&"); + location.href = url; + } + } else { + return false; + } +} -- 2.39.5