From d37e4f99f3549fdae2b75ca8cbc9df68dfb5ee1a Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 3 May 2018 12:00:28 -0400 Subject: [PATCH] Bug 17378: Add ability to specify maximum number of items per record Some libraries want to be able to specify a hard limit on the number of items a record can have. It would be nice to have this set per record type, but since most libraries use item level itemtypes, that would make it confusing and non-intuitive. The simplest and most straight forward approach would just be to have a system preference. Koha should then just report that it failed to create an item if the librarian has hit the upper limit specified in the system preference. Test Plan: 1) Apply this patch 2) Run updatedatabase.pl 3) Set the new syspref RecordItemLimit to 3 4) Find a record with 4 or more records 5) Note in the catalog toolbar you cannot choose the add new item option 6) Note in the items editor you can edit items but not add new ones --- installer/data/mysql/atomicupdate/bug_17378.sql | 2 + installer/data/mysql/sysprefs.sql | 1 + .../intranet-tmpl/prog/en/includes/cat-toolbar.inc | 11 +++- .../en/modules/admin/preferences/cataloguing.pref | 3 ++ .../prog/en/modules/cataloguing/additem.tt | 58 +++++++++++++++------- koha-tmpl/intranet-tmpl/prog/js/catalog.js | 2 +- 6 files changed, 56 insertions(+), 21 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_17378.sql diff --git a/installer/data/mysql/atomicupdate/bug_17378.sql b/installer/data/mysql/atomicupdate/bug_17378.sql new file mode 100644 index 0000000000..b315ec828f --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_17378.sql @@ -0,0 +1,2 @@ +INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES +('RecordItemLimit',NULL,NULL,'If this number is exceeded, a librarian will be unable to manually add more items to a record','Integer'); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 34e5cc4744..a07b619f74 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -451,6 +451,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('QueryWeightFields','1',NULL,'If ON, enables field weighting','YesNo'), ('QuoteOfTheDay','0',NULL,'Enable or disable display of Quote of the Day on the OPAC home page','YesNo'), ('RandomizeHoldsQueueWeight','0',NULL,'if ON, the holds queue in circulation will be randomized, either based on all location codes, or by the location codes specified in StaticHoldsQueueWeight','YesNo'), +('RecordItemLimit',NULL,NULL,'If this number is exceeded, a librarian will be unable to manually add more items to a record','Integer'), ('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'), ('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'), ('RenewalLog','0','','If ON, log information about renewals','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 781b79714d..18715b7332 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -1,3 +1,4 @@ +[% USE Koha %] [% INCLUDE 'blocking_errors.inc' %]
@@ -55,7 +56,15 @@ CAN_user_serials_create_subscription ) %] [% END %] [% END %] - [% IF ( CAN_user_editcatalogue_edit_items ) %]
  • Attach item
  • [% END %] + [% IF ( CAN_user_editcatalogue_edit_items ) %] + [% IF Koha.Preference('RecordItemLimit') && count > Koha.Preference('RecordItemLimit') %] +
  • + Attach item +
  • + [% ELSE %] +
  • Attach item
  • + [% END %] + [% END %] [% IF ( EasyAnalyticalRecords ) %][% IF ( CAN_user_editcatalogue_edit_items ) %]
  • Link to host item[% END %][% END %] [% IF ( LocalCoverImages || OPACLocalCoverImages) %][% IF ( CAN_user_tools_upload_local_cover_images ) %]
  • Upload image[% END %][% 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 cc75b6dfb4..bd5f9fd74e 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 @@ -47,6 +47,9 @@ Cataloging: no: "Don't display" - buttons on the bib details page to print item spine labels. - + - If a record has more than + - pref: RecordItemLimit + - items, don't allow a librarian to add more manually. 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/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index 6b86b21447..cf8a0e1c33 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -17,6 +17,9 @@ browser.show(); $(document).ready(function(){ + [% IF opisadd && Koha.Preference('RecordItemLimit') && item_loop.size > Koha.Preference('RecordItemLimit') %] + $("#f fieldset.rows").hide(); + [% END %] // Remove the onclick event defined in browser.js, // otherwise the deletion confirmation will not work correctly @@ -118,6 +121,13 @@ function CheckMultipleAdd(f) { if (f>99) { return confirm(_("You are about to add %s items. Continue?").format(f)); } + [% IF Koha.Preference('RecordItemLimit') %] + [% SET max_new_items = Koha.Preference('RecordItemLimit') - item_loop.size %] + if (f > [% max_new_items %]) { + alert(_("You are exceeding the [% Koha.Preference('RecordItemLimit') %] limit of items per record. You can only add [% max_new_items %] new item(s).")); + return false; + } + [% END %] } function Dopop(link,i) { defaultvalue=document.forms[0].field_value[i].value; @@ -336,31 +346,41 @@ function confirm_deletion() {
    [% IF ( opisadd ) %] - - - - - - - - - -
    - - - Cancel -

    The barcode you enter will be incremented for each additional item.

    -
    + [% IF Koha.Preference('RecordItemLimit') && item_loop.size > Koha.Preference('RecordItemLimit') %] +
    + [% item_loop.size %] items are attached to this record exceeding the threshold of [% Koha.Preference('RecordItemLimit') %] items. You cannot add more items. +
    + [% ELSE %] + + + + + + + + + +
    + + + Cancel +

    The barcode you enter will be incremented for each additional item.

    +
    + [% END %] [% ELSE %] - + [% IF Koha.Preference('RecordItemLimit') && item_loop.size > Koha.Preference('RecordItemLimit') %] + + [% ELSE %] + + [% END %] Cancel [% END %]
    diff --git a/koha-tmpl/intranet-tmpl/prog/js/catalog.js b/koha-tmpl/intranet-tmpl/prog/js/catalog.js index 19ccd522e2..8951fe1bac 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/catalog.js +++ b/koha-tmpl/intranet-tmpl/prog/js/catalog.js @@ -102,7 +102,7 @@ $(document).ready(function() { return false; }); $("#export").remove(); // Hide embedded export form if JS menus available - $("#deletebiblio").tooltip(); + $("#deletebiblio,#attachitem").tooltip(); $("#batchedit-disabled,#batchdelete-disabled,#deleteallitems-disabled") .on("click",function(e){ e.preventDefault(); -- 2.15.1 (Apple Git-101)