From e3e38193b6665073d84413af7c9a3905081b25ac 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. --- C4/Reserves.pm | 12 +++++ .../prog/en/modules/reserve/request.tt | 44 ++++++++++++++++++ reserve/request.pl | 1 + reserve/update_forceitemholds.pl | 49 ++++++++++++++++++++ 4 files changed, 106 insertions(+), 0 deletions(-) create mode 100755 reserve/update_forceitemholds.pl diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 476f366..010d8d5 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -2451,6 +2451,18 @@ sub CheckBiblioForceItemHolds { return 1 if $rec && $rec->force_item_holds; } +=head2 ModBiblioForceItemHolds + +=cut + +sub ModBiblioForceItemHolds { + my ( $biblionumber, $newmode ) = @_; + my $rec = Koha::Database->new()->schema()->resultset('Biblio')->find( $biblionumber ); + return 0 if !$rec; + my $rv = $rec->update({ force_item_holds => $newmode? 1: 0 }); + return $rv ? 1 : 0; +} + =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..b974ee5 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( obj.responseText == '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..c604f0a --- /dev/null +++ b/reserve/update_forceitemholds.pl @@ -0,0 +1,49 @@ +#!/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 2 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::Context; +use C4::Auth; +use C4::Output; +use C4::Reserves qw//; + +=head1 DESCRIPTION + +Update force item holds for a specific biblio + +=cut + +my $input = new CGI; +my $biblio = $input->param('biblio'); +my $mode = $input->param('mode'); + +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; +#output_html_with_http_headers $input, $cookie, $template->output; -- 1.7.7.6