@@ -, +, @@ You should not see the Force item holds-box. --- 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 --- a/C4/Reserves.pm +++ a/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 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ a/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 %] --- a/reserve/request.pl +++ a/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 ); --- a/reserve/update_forceitemholds.pl +++ a/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; --- a/t/db_dependent/Reserves.t +++ a/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 { --