From 7b97235a63795a99ce8c0520cefcbc0a713cb524 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 14 Sep 2023 12:22:55 -0400 Subject: [PATCH] Bug 34784: Implement feature in staff interface Some libraries would like to auto-populate item callnumbers for items on a record based on the system preference "itemcallnumber". Only items with empty callnumbers would affected. This would add a button "Populate empty item callnumbers" on catalogue/detail.pl, as well as a "Populate callnumber" button for each line in the holdings table to set the callnumber for that specific item. Test Plan: 1) Set the systempreference to something ( "245a" will make the callnumber the record title for testing purposes ) 2) Apply this patch set 3) Restart all the things! 4) Browse to a record details page, note no new buttons 5) Enable the new syspref EnablePopulateCallnumbers 5) Reload the record details, note the new "Populate callnumbers" button in the cataloging toolbar 7) Add one or more items with no callnumber to the record 8) Test the "Populate callnumbers" button 9) Add another item with no callnumber to the record 10) Test the "Populate callnumber" button for that single item Signed-off-by: David Nind --- .../data/mysql/atomicupdate/bug_34784.pl | 19 +++++++++ installer/data/mysql/mandatory/sysprefs.sql | 5 ++- .../prog/en/includes/cat-toolbar.inc | 8 ++++ .../admin/preferences/cataloguing.pref | 6 +++ .../prog/en/modules/catalogue/detail.tt | 3 ++ koha-tmpl/intranet-tmpl/prog/js/catalog.js | 39 +++++++++++++++++++ 6 files changed, 78 insertions(+), 2 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_34784.pl diff --git a/installer/data/mysql/atomicupdate/bug_34784.pl b/installer/data/mysql/atomicupdate/bug_34784.pl new file mode 100755 index 0000000000..448e54c67b --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_34784.pl @@ -0,0 +1,19 @@ +use Modern::Perl; + +return { + bug_number => "34784", + description => "Add ability to populate empty item callnumbers for a record based on the itemcallnumber syspref", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do( + q{ + INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) + VALUES ('EnablePopulateCallnumbers','0','','Enable populate callnumber feature','YesNo') + } + ); + + say $out "Added new system preference 'EnablePopulateCallnumbers'"; + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 044361b6ad..72b949c9a7 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -228,11 +228,12 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'), ('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'), ('EnableExpiredPasswordReset', '0', NULL, 'Enable ability for patrons with expired password to reset their password directly', 'YesNo'), +('EnableItemGroupHolds','0','','Enable item groups holds feature','YesNo'), +('EnableItemGroups','0','','Enable the item groups feature','YesNo'), ('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''), ('EnablePointOfSale','0',NULL,'Enable the point of sale feature to allow anonymous transactions with the accounting system. (Requires UseCashRegisters)','YesNo'), +('EnablePopulateCallnumbers','0','','Enable populate callnumber feature','YesNo'), ('EnableSearchHistory','0','','Enable or disable search history','YesNo'), -('EnableItemGroups','0','','Enable the item groups feature','YesNo'), -('EnableItemGroupHolds','0','','Enable item groups holds feature','YesNo'), ('EnhancedMessagingPreferences','1','','If ON, allows patrons to select to receive additional messages about items due or nearly due.','YesNo'), ('EnhancedMessagingPreferencesOPAC', '1', NULL, 'If ON, show patrons messaging setting on the OPAC.', 'YesNo'), ('ERMModule', '0', NULL, 'Enable the e-resource management module', 'YesNo'), 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 93818826d2..6a64686b92 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -211,6 +211,14 @@ [% END %] [% END %] +[% IF Koha.Preference('EnablePopulateCallnumbers') %] +[% IF ( CAN_user_editcatalogue_edit_catalogue || CAN_user_editcatalogue_edit_items || CAN_user_tools_items_batchmod || CAN_user_tools_items_batchdel ) or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) %] +
+ +
+[% END %] +[% END %] + [% FOREACH p IN plugins %] [% p.intranet_catalog_biblio_enhancements_toolbar_button | $raw %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref index 5a6346ed46..37eff97140 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref @@ -77,6 +77,12 @@ Cataloging: 0: "Don't show" - buttons on the bibliographic details page to print item spine labels. - + - pref: EnablePopulateCallnumbers + choices: + 1: Show + 0: "Don't show" + - buttons on the bibliographic details page to populate empty item callnumbers from the record based on the itemcallnumber system preference. + - Record structure: - - "Fill in the default language for field 008 Range 35-37 of MARC21 records (e.g. eng, nor, ger, see MARC Code List for Languages):" diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 05da5acf56..9fc75ebf99 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -652,6 +652,9 @@ [% ELSE %] Edit [% END %] + [% IF !item.itemcallnumber && Koha.Preference('EnablePopulateCallnumbers') %] + + [% END %] [% END %] [% IF bundlesEnabled %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/catalog.js b/koha-tmpl/intranet-tmpl/prog/js/catalog.js index 8a3694fb8d..d04a71c25f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/catalog.js +++ b/koha-tmpl/intranet-tmpl/prog/js/catalog.js @@ -124,6 +124,45 @@ $(document).ready(function() { }) .tooltip(); + $("#populate-callnumbers-biblio") + .on('click', function() { + if ( confirm(__('Are you sure you want to populate callnumbers for all items without a callnumber on this record?')) ) { + const biblionumber = $(this).data('biblionumber'); + $.post( `/api/v1/biblios/${biblionumber}/items/populate_empty_callnumbers`, function( data ) { + const items_updated = data.items_updated; + const callnumber = data.callnumber; + let msg = __('Items populated with the callnumber "%s": %s').format(callnumber, items_updated); + + if ( items_updated ) { + msg += __('\nReload the page?'); + if( confirm(msg) ) { + location.reload(true); + } + } else { + alert(msg); + } + }); + } + }).tooltip(); + + $(".populate-callnumber-item") + .on('click', function() { + if ( confirm(__('Are you sure you want to populate the callnumber for this item?')) ) { + const biblionumber = $(this).data('biblionumber'); + const itemnumber = $(this).data('itemnumber'); + const button = $(this); + $.post( `/api/v1/biblios/${biblionumber}/items/${itemnumber}/populate_empty_callnumbers`, function( data ) { + const callnumber = data.callnumber; + let msg = __('Item populated with the callnumber "%s"\nReload the page?').format(callnumber); + if( confirm(msg) ) { + location.reload(true); + } else { + button.hide(); + } + }); + } + }).tooltip(); + $(".addtolist").on("click", function (e) { e.preventDefault(); var shelfnumber = $(this).data("shelfnumber"); -- 2.30.2