From 196ef3896d3251ea127d9ae3fbe6a111e803696a Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 5 Mar 2015 15:24:06 +0100 Subject: [PATCH] Bug 13479: Enable/disable forced item holds on biblio level Content-Type: text/plain; charset=utf-8 This is a follow-up of report 13478. If you set OPACItemHolds to 'selectiveforce', you can now enable or disable forced item holds on biblio level on the Holds tab of the staff detail page. TEST PLAN: [1] Run the adjusted unit test (t/db_dependent/Reserves.t). [2] Set OPACItemHolds to Allow. [3] Check the Holds tab of staff catalog detail. You should not see the Force item holds-box. [4] Set OPACItemHolds to Selectively force. [5] Goto the Holds tab of staff catalog detail. [6] Enable forced item holds. Check behavior with placing hold in OPAC. [6] Disable forced item holds. Check behavior with placing hold in OPAC. --- C4/Reserves.pm | 15 ++++++ .../prog/en/modules/reserve/request.tt | 44 ++++++++++++++++++ reserve/request.pl | 1 + reserve/update_forceitemholds.pl | 47 ++++++++++++++++++++ t/db_dependent/Reserves.t | 10 ++++- 5 files changed, 116 insertions(+), 1 deletions(-) create mode 100755 reserve/update_forceitemholds.pl diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 476f366..22709a0 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -2451,6 +2451,21 @@ sub CheckBiblioForceItemHolds { return 1 if $rec && $rec->force_item_holds; } +=head2 ModBiblioForceItemHolds + + This routine updates force_item_holds for a specific biblionumber. + It returns true if the update seems to be successful. + +=cut + +sub ModBiblioForceItemHolds { + my ( $biblionumber, $newmode ) = @_; + my $rec = Koha::Database->new()->schema()->resultset('Biblio')->find( $biblionumber ); + return if !$rec; + my $rv = $rec->update({ force_item_holds => $newmode? 1: 0 }); + return 1 if $rv; +} + =head1 AUTHOR Koha Development Team diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index db044b5..45691b3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -1,3 +1,4 @@ +[% USE Koha %] [% USE KohaDates %] [% INCLUDE 'doc-head-open.inc' %] [% UNLESS ( multi_hold ) %] @@ -24,6 +25,12 @@ $(document).ready(function() { [% IF AutoResumeSuspendedHolds %] $(".suspend_until_datepicker, .datepickerfrom, .datepickerto").datepicker("option", "minDate", 1); [% END %] + [% IF biblioloop && biblioloop.0.forceitemhold %] + [%# we only check the first biblio (0) because we do not show the form for multiple biblios %] + $("#forceitemhold_enabled").toggle(); + [% ELSE %] + $("#forceitemhold_disabled").toggle(); + [% END %] }); function check() { @@ -98,6 +105,27 @@ function checkMultiHold() { return true; } +function UpdateForceItemHold(biblio,mode) { + $(".forceitemholdbtn").prop("disabled",true); + var url = 'update_forceitemholds.pl?biblio=' + biblio+ "&mode=" + mode; + var req = $.ajax({ + url: url, + type: "GET", + dataType: "text" + }); + req.done( function( data, status, obj ) { + if( data == '1' ) { + $("#forceitemhold_disabled").toggle(); + $("#forceitemhold_enabled").toggle(); + } + $(".forceitemholdbtn").prop("disabled",false); + }); + req.fail( function( obj, status, err ) { + alert('Something went wrong. Please try again later.'); + $(".forceitemholdbtn").prop("disabled",false); + }); +} + $(document).ready(function() { $("input.needsoverride").click(function() { // This must be before the radio button/checkbox switch logic var itemnumber = this.value; @@ -207,6 +235,22 @@ function checkMultiHold() { [% END %] + [% IF !multi_hold && Koha.Preference('OPACItemHolds')=='selectiveforce' %] +
+
+ + + +
+
+ [% END %] + [% UNLESS ( multi_hold ) %]

Place a hold on [% INCLUDE 'biblio-default-view.inc' %][% title |html %]

[% ELSE %] diff --git a/reserve/request.pl b/reserve/request.pl index ce0e70f..ca0bb89 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -582,6 +582,7 @@ foreach my $biblionumber (@biblionumbers) { $biblioloopiter{title} = $dat->{title}; $biblioloopiter{rank} = $fixedRank; $biblioloopiter{reserveloop} = \@reserveloop; + $biblioloopiter{forceitemhold} = C4::Reserves::CheckBiblioForceItemHolds( $biblionumber ); if (@reserveloop) { $template->param( reserveloop => \@reserveloop ); diff --git a/reserve/update_forceitemholds.pl b/reserve/update_forceitemholds.pl new file mode 100755 index 0000000..2ac21dd --- /dev/null +++ b/reserve/update_forceitemholds.pl @@ -0,0 +1,47 @@ +#!/usr/bin/perl + +# Copyright 2015 Koha Development Team +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use CGI qw ( -utf8 ); +use C4::Auth; +use C4::Reserves qw//; + +=head1 DESCRIPTION + +Update force item holds for a specific biblio + +=cut + +my $input = new CGI; +my $biblio = $input->param('biblio')||0; +my $mode = $input->param('mode'); + +#this statement is for authorization +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { template_name => "acqui/ajax.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + } +); + +my $rv = C4::Reserves::ModBiblioForceItemHolds( $biblio, $mode ); +print $input->header(-type => 'text/plain', -charset => 'UTF-8'); +print $rv//0; diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index d4be510..d437a69 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 57; +use Test::More tests => 59; use MARC::Record; use DateTime::Duration; @@ -522,6 +522,14 @@ isnt( C4::Reserves::CheckBiblioForceItemHolds($bibnum), 1, 'For Allow this bib should return false again'); #End of tests for CheckBiblioForceItemHolds +#Tests for ModBiblioForceItemHolds +my $temp= C4::Reserves::ModBiblioForceItemHolds( $bibnum, 1); +is( $temp, 1, 'Test 1 for ModBiblioForceItemHolds'); +($temp)= $dbh->selectrow_array("SELECT max(biblionumber) FROM biblio"); +$temp= C4::Reserves::ModBiblioForceItemHolds( $temp+1, 1); +isnt( $temp, 1, 'Test 2 for ModBiblioForceItemHolds'); +#End of tests for ModBiblioForceItemHolds + $dbh->rollback; sub count_hold_print_messages { -- 1.7.7.6