From bdc6fc773778df7eebd130a6a12c68cbe6b160fa 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 call numbers for items on a record based on the system preference "itemcallnumber". Only items with empty call numbers would affected. This would add a button "Populate empty item call numbers" on catalogue/detail.pl, as well as a "Populate call number" button for each line in the holdings table to set the call number for that specific item. Test Plan: 1) Set the systempreference to something ( "245a" will make the call number 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 call numbers" button in the cataloging toolbar 7) Add one or more items with no call number to the record 8) Test the "Populate call numbers" button 9) Add another item with no call number to the record 10) Test the "Populate call number" button for that single item --- .../data/mysql/atomicupdate/bug_34784.pl | 19 ++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../prog/en/includes/cat-toolbar.inc | 4 ++ .../tables/items/catalogue_detail.inc | 11 ++++- .../admin/preferences/cataloguing.pref | 6 +++ koha-tmpl/intranet-tmpl/prog/js/catalog.js | 44 +++++++++++++++++++ 6 files changed, 83 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 00000000000..6320a094652 --- /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 call numbers for a record based on the itemcallnumber system preference", + 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 call number 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 34ada9d8376..4acd793c2e2 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -251,6 +251,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('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 call number feature','YesNo'), ('EnableSearchHistory','0','','Enable or disable search history','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'), 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 36d924b9524..6a36f731178 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -59,6 +59,10 @@ [% END %] + [% IF Koha.Preference('EnablePopulateCallnumbers') && ( ( 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 ) ) %] +
  • Populate call numbers
  • + [% END %] + [% IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) %]
  • Manage items
  • [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc index 7e44c02a5a1..32bc98fc6e7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers/tables/items/catalogue_detail.inc @@ -775,11 +775,18 @@ data: function( row, type, val, meta ) { let nodes = ''; if ( can_edit_items_from.includes(row.home_library_id) || !can_edit_items_from.length ){ - [% IF Koha.Preference('LocalCoverImages') OR Koha.Preference('OPACLocalCoverImages') %] + [% SET show_itemcallnumber_link = !item.itemcallnumber && Koha.Preference('EnablePopulateCallnumbers') %] + [% SET show_local_covers_link = Koha.Preference('LocalCoverImages') OR Koha.Preference('OPACLocalCoverImages') %] + [% IF show_itemcallnumber_link || show_local_covers_link %] nodes += '
    '; nodes += ' %s'.format(row.biblio_id, row.item_id, _("Edit")); nodes += ' '; nodes += '
    '; [% ELSE %] 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 ffd9b7e5498..a1ac3f64aa0 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 catalog details page to populate empty item call numbers 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/js/catalog.js b/koha-tmpl/intranet-tmpl/prog/js/catalog.js index ec37cb08940..eea77ecdf79 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/catalog.js +++ b/koha-tmpl/intranet-tmpl/prog/js/catalog.js @@ -118,6 +118,50 @@ $(document).ready(function() { }); $("#export").remove(); // Hide embedded export form if JS menus available + $("#populate-callnumbers-biblio") + .on('click', function() { + if ( confirm(__('Are you sure you want to populate call numbers for all items without a callnumber on this record?')) ) { + const biblionumber = $(this).data('biblionumber'); + $.post( `/api/v1/rpc/biblios/${biblionumber}/items/populate_empty_callnumbers`, function( data ) { + const items_updated = data.modified_item_ids; + const callnumber = data.callnumber; + let msg = ""; + if( items_updated ){ + msg += __('Items populated with the call number "%s": %s').format(callnumber, items_updated); + } else { + msg += __('No ttems were updated'); + } + + if ( items_updated ) { + msg += __('\nReload the page?'); + if( confirm(msg) ) { + location.reload(true); + } + } else { + alert(msg); + } + }); + } + }).tooltip(); + + $("body") + .on('click','.populate-callnumber-item', function() { + if ( confirm(__('Are you sure you want to populate the call number for this item?')) ) { + const biblionumber = $(this).data('biblionumber'); + const itemnumber = $(this).data('itemnumber'); + const button = $(this); + $.post( `/api/v1/rpc/biblios/${biblionumber}/items/${itemnumber}/populate_empty_callnumbers`, function( data ) { + const callnumber = data.callnumber; + let msg = __('Item populated with the call number "%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.39.5