View | Details | Raw Unified | Return to bug 37868
Collapse All | Expand All

(-)a/C4/Reserves.pm (-23 lines)
Lines 129-135 BEGIN { Link Here
129
      ToggleLowestPriority
129
      ToggleLowestPriority
130
130
131
      ReserveSlip
131
      ReserveSlip
132
      ToggleSuspend
133
      SuspendAll
132
      SuspendAll
134
133
135
      CalculatePriority
134
      CalculatePriority
Lines 1462-1489 sub ToggleLowestPriority { Link Here
1462
    _FixPriority({ reserve_id => $reserve_id, rank => '999999' });
1461
    _FixPriority({ reserve_id => $reserve_id, rank => '999999' });
1463
}
1462
}
1464
1463
1465
=head2 ToggleSuspend
1466
1467
  ToggleSuspend( $reserve_id );
1468
1469
This function sets the suspend field to true if is false, and false if it is true.
1470
If the reserve is currently suspended with a suspend_until date, that date will
1471
be cleared when it is unsuspended.
1472
1473
=cut
1474
1475
sub ToggleSuspend {
1476
    my ( $reserve_id, $suspend_until ) = @_;
1477
1478
    my $hold = Koha::Holds->find( $reserve_id );
1479
1480
    if ( $hold->is_suspended ) {
1481
        $hold->resume()
1482
    } else {
1483
        $hold->suspend_hold( $suspend_until );
1484
    }
1485
}
1486
1487
=head2 SuspendAll
1464
=head2 SuspendAll
1488
1465
1489
  SuspendAll(
1466
  SuspendAll(
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc (-5 / +7 lines)
Lines 244-256 Link Here
244
                <td>
244
                <td>
245
                    [% IF Koha.Preference('SuspendHoldsIntranet') %]
245
                    [% IF Koha.Preference('SuspendHoldsIntranet') %]
246
                        [% UNLESS ( hold.found ) %]
246
                        [% UNLESS ( hold.found ) %]
247
                            <button class="btn btn-default btn-xs toggle-suspend" data-reserve-id="[% hold.reserve_id | html %]" data-biblionumber="[% hold.biblionumber | html %]">
247
                            [% IF ( hold.suspend ) %]
248
                                [% IF ( hold.suspend ) %]
248
                                <button class="btn btn-default btn-xs unsuspend-hold" data-reserve-id="[% hold.reserve_id | html %]" data-biblionumber="[% hold.biblionumber | html %]">
249
                                    <i class="fa fa-play" aria-hidden="true"></i> Unsuspend
249
                                    <i class="fa fa-play" aria-hidden="true"></i> Unsuspend
250
                                [% ELSE %]
250
                                </button>
251
                            [% ELSE %]
252
                                <button class="btn btn-default btn-xs suspend-hold" data-reserve-id="[% hold.reserve_id | html %]" data-biblionumber="[% hold.biblionumber | html %]">
251
                                    <i class="fa fa-pause" aria-hidden="true"></i> Suspend
253
                                    <i class="fa fa-pause" aria-hidden="true"></i> Suspend
252
                                [% END %]
254
                                </button>
253
                            </button>
255
                            [% END %]
254
256
255
                            [% IF Koha.Preference('AutoResumeSuspendedHolds') %]
257
                            [% IF Koha.Preference('AutoResumeSuspendedHolds') %]
256
                                <label for="suspend_until_[% hold.reserve_id | html %]">[% IF ( hold.suspend ) %] on [% ELSE %] until [% END %]</label>
258
                                <label for="suspend_until_[% hold.reserve_id | html %]">[% IF ( hold.suspend ) %] on [% ELSE %] until [% END %]</label>
(-)a/koha-tmpl/intranet-tmpl/prog/js/holds.js (-23 / +42 lines)
Lines 445-481 $(document).ready(function() { Link Here
445
        });
445
        });
446
    });
446
    });
447
447
448
    $(".toggle-suspend").on('click', function(e) {
448
    function toggle_suspend(node, inputs) {
449
        e.preventDefault();
449
        let reserve_id = $(node).data("reserve-id");
450
        let reserve_id     = $(this).data('reserve-id');
450
        let biblionumber = $(node).data("biblionumber");
451
        let biblionumber   = $(this).data('biblionumber');
452
        let suspend_until  = $('#suspend_until_' + reserve_id).val();
453
        let suspendForm = $("#hold-actions-form").attr({
451
        let suspendForm = $("#hold-actions-form").attr({
454
            action: 'request.pl',
452
            action: "request.pl",
455
            method: 'post'
453
            method: "post",
456
        });
457
        let sus_op = $("<input />").attr({
458
            type: 'hidden',
459
            name: 'op',
460
            value: 'cud-toggleSuspend'
461
        });
454
        });
462
        let sus_bn = $("<input />").attr({
455
        let sus_bn = $("<input />").attr({
463
            type: 'hidden',
456
            type: "hidden",
464
            name: 'biblionumber',
457
            name: "biblionumber",
465
            value: biblionumber
458
            value: biblionumber,
466
        });
459
        });
467
        let sus_ri = $("<input />").attr({
460
        let sus_ri = $("<input />").attr({
468
            type: 'hidden',
461
            type: "hidden",
469
            name: 'reserve_id',
462
            name: "reserve_id",
470
            value: reserve_id,
463
            value: reserve_id,
471
        });
464
        });
472
        let sus_su = $("<input />").attr({
465
        inputs.push(sus_bn, sus_ri);
473
            type: 'hidden',
466
        suspendForm.append(inputs);
474
            name: 'suspend_until',
475
            value: suspend_until
476
        });
477
        suspendForm.append( sus_op, sus_bn, sus_ri, sus_su );
478
        $("#hold-actions-form").submit();
467
        $("#hold-actions-form").submit();
479
        return false;
468
        return false;
469
    }
470
    $(".suspend-hold").on("click", function (e) {
471
        e.preventDefault();
472
        let reserve_id = $(this).data("reserve-id");
473
        let suspend_until = $("#suspend_until_" + reserve_id).val();
474
        let inputs = [
475
            $("<input />").attr({
476
                type: "hidden",
477
                name: "op",
478
                value: "cud-suspend",
479
            }),
480
            $("<input />").attr({
481
                type: "hidden",
482
                name: "suspend_until",
483
                value: suspend_until,
484
            }),
485
        ];
486
        return toggle_suspend(this, inputs);
487
    });
488
    $(".unsuspend-hold").on("click", function (e) {
489
        e.preventDefault();
490
        let inputs = [
491
            $("<input />").attr({
492
                type: "hidden",
493
                name: "op",
494
                value: "cud-unsuspend",
495
            }),
496
        ];
497
        return toggle_suspend(this, inputs);
480
    });
498
    });
499
481
});
500
});
(-)a/opac/opac-modrequest-suspend.pl (-4 / +7 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
21
use C4::Output;
21
use C4::Output;
22
use C4::Reserves qw( ToggleSuspend SuspendAll );
22
use C4::Reserves qw( SuspendAll );
23
use C4::Auth qw( get_template_and_user );
23
use C4::Auth qw( get_template_and_user );
24
24
25
use Koha::Patrons;
25
use Koha::Patrons;
Lines 38-48 my $suspend = $query->param('suspend'); Link Here
38
my $suspend_until = $query->param('suspend_until') || undef;
38
my $suspend_until = $query->param('suspend_until') || undef;
39
my $reserve_id    = $query->param('reserve_id');
39
my $reserve_id    = $query->param('reserve_id');
40
40
41
if ( ( $op eq 'cud-suspend' || $op eq 'cud-unsuspend' ) && $reserve_id ) {
41
if ( $op eq 'cud-suspend' ) {
42
    my $patron = Koha::Patrons->find($borrowernumber);
42
    my $patron = Koha::Patrons->find($borrowernumber);
43
    my $hold   = $patron->holds->find($reserve_id);
43
    my $hold   = $patron->holds->find($reserve_id);
44
    ToggleSuspend( $reserve_id, $suspend_until )
44
    $hold->suspend_hold($suspend_until) if $hold && $hold->is_cancelable_from_opac;
45
        if $hold && $hold->is_cancelable_from_opac;
45
} elsif ( $op eq 'cud-unsuspend' ) {
46
    my $patron = Koha::Patrons->find($borrowernumber);
47
    my $hold   = $patron->holds->find($reserve_id);
48
    $hold->resume if $hold && $hold->is_cancelable_from_opac;
46
}
49
}
47
elsif( $op eq 'cud-suspend_all' || $op eq 'cud-unsuspend_all' ) {
50
elsif( $op eq 'cud-suspend_all' || $op eq 'cud-unsuspend_all' ) {
48
    SuspendAll(
51
    SuspendAll(
(-)a/reserve/request.pl (-3 / +8 lines)
Lines 33-39 use List::MoreUtils qw( uniq ); Link Here
33
use Date::Calc qw( Date_to_Days );
33
use Date::Calc qw( Date_to_Days );
34
use C4::Output qw( output_html_with_http_headers );
34
use C4::Output qw( output_html_with_http_headers );
35
use C4::Auth qw( get_template_and_user );
35
use C4::Auth qw( get_template_and_user );
36
use C4::Reserves qw( RevertWaitingStatus AlterPriority ToggleLowestPriority ToggleSuspend CanBookBeReserved GetMaxPatronHoldsForRecord CanItemBeReserved IsAvailableForItemLevelRequest );
36
use C4::Reserves qw( RevertWaitingStatus AlterPriority ToggleLowestPriority CanBookBeReserved GetMaxPatronHoldsForRecord CanItemBeReserved IsAvailableForItemLevelRequest );
37
use C4::Items qw( get_hostitemnumbers_of );
37
use C4::Items qw( get_hostitemnumbers_of );
38
use C4::Koha qw( getitemtypeimagelocation );
38
use C4::Koha qw( getitemtypeimagelocation );
39
use C4::Serials qw( CountSubscriptionFromBiblionumber );
39
use C4::Serials qw( CountSubscriptionFromBiblionumber );
Lines 120-129 elsif ( $op eq 'cud-setLowestPriority' ) { Link Here
120
    my $reserve_id = $input->param('reserve_id');
120
    my $reserve_id = $input->param('reserve_id');
121
    ToggleLowestPriority($reserve_id);
121
    ToggleLowestPriority($reserve_id);
122
}
122
}
123
elsif ( $op eq 'cud-toggleSuspend' ) {
123
elsif ( $op eq 'cud-suspend' ) {
124
    my $reserve_id    = $input->param('reserve_id');
124
    my $reserve_id    = $input->param('reserve_id');
125
    my $suspend_until = $input->param('suspend_until');
125
    my $suspend_until = $input->param('suspend_until');
126
    ToggleSuspend( $reserve_id, $suspend_until );
126
    my $hold          = Koha::Holds->find($reserve_id);
127
    $hold->suspend_hold($suspend_until) if $hold;
128
} elsif ( $op eq 'cud-unsuspend' ) {
129
    my $reserve_id = $input->param('reserve_id');
130
    my $hold       = Koha::Holds->find($reserve_id);
131
    $hold->resume() if $hold;
127
}
132
}
128
elsif ( $op eq 'cud-cancel_bulk' ) {
133
elsif ( $op eq 'cud-cancel_bulk' ) {
129
    my $cancellation_reason = $input->param("cancellation-reason");
134
    my $cancellation_reason = $input->param("cancellation-reason");
(-)a/t/db_dependent/Holds.t (-11 / +2 lines)
Lines 7-13 use t::lib::TestBuilder; Link Here
7
7
8
use C4::Context;
8
use C4::Context;
9
9
10
use Test::More tests => 74;
10
use Test::More tests => 72;
11
use Test::Exception;
11
use Test::Exception;
12
12
13
use MARC::Record;
13
use MARC::Record;
Lines 15-21 use MARC::Record; Link Here
15
use C4::Biblio;
15
use C4::Biblio;
16
use C4::Calendar;
16
use C4::Calendar;
17
use C4::Items;
17
use C4::Items;
18
use C4::Reserves qw( AddReserve CalculatePriority ModReserve ToggleSuspend AutoUnsuspendReserves SuspendAll ModReserveMinusPriority AlterPriority CanItemBeReserved CheckReserves MoveReserve );
18
use C4::Reserves qw( AddReserve CalculatePriority ModReserve AutoUnsuspendReserves SuspendAll ModReserveMinusPriority AlterPriority CanItemBeReserved CheckReserves MoveReserve );
19
use C4::Circulation qw( CanBookBeRenewed );
19
use C4::Circulation qw( CanBookBeRenewed );
20
20
21
use Koha::Biblios;
21
use Koha::Biblios;
Lines 160-173 ModReserve({ # call without reserve_id Link Here
160
$hold = Koha::Holds->find( $reserve_id );
160
$hold = Koha::Holds->find( $reserve_id );
161
ok( $hold->priority eq '3', "Test ModReserve, priority changed correctly" );
161
ok( $hold->priority eq '3', "Test ModReserve, priority changed correctly" );
162
162
163
ToggleSuspend( $reserve_id );
164
$hold = Koha::Holds->find( $reserve_id );
165
ok( ! $hold->suspend, "Test ToggleSuspend(), no date" );
166
167
ToggleSuspend( $reserve_id, '2012-01-01' );
168
$hold = Koha::Holds->find( $reserve_id );
169
is( $hold->suspend_until, '2012-01-01 00:00:00', "Test ToggleSuspend(), with date" );
170
171
AutoUnsuspendReserves();
163
AutoUnsuspendReserves();
172
$hold = Koha::Holds->find( $reserve_id );
164
$hold = Koha::Holds->find( $reserve_id );
173
ok( ! $hold->suspend, "Test AutoUnsuspendReserves()" );
165
ok( ! $hold->suspend, "Test AutoUnsuspendReserves()" );
174
- 

Return to bug 37868