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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc (-15 / +3 lines)
Lines 182-202 Link Here
182
                    </form>
182
                    </form>
183
183
184
                    [% IF Koha.Preference('SuspendHoldsIntranet') %]
184
                    [% IF Koha.Preference('SuspendHoldsIntranet') %]
185
                        <form action="/cgi-bin/koha/reserve/modrequest_suspendall.pl" method="post">
185
                        <fieldset class="action">
186
                            [% INCLUDE 'csrf-token.inc' %]
186
                            <button class="btn btn-primary suspend_selected_holds" data-bulk="true"></button>
187
                            <fieldset class="action">
187
                        </fieldset>
188
                                <input type="hidden" name="op" value="cud-suspendall" />
189
                                <input type="hidden" name="from" value="[% patronpage | html %]" />
190
                                <input type="hidden" name="borrowernumber" value="[% patron.borrowernumber | html %]" />
191
                                <input type="submit" class="btn btn-primary" value="Suspend all holds" />
192
193
                                [% IF Koha.Preference('AutoResumeSuspendedHolds') %]
194
                                    <label for="suspend_until">until</label>
195
                                    <input type="text" size="10" id="suspend_until" name="suspend_until" class="flatpickr" data-flatpickr-futuredate="true" />
196
                                    <span class="hint">Specify date on which to resume [% INCLUDE 'date-format.inc' %]: </span>
197
                                [% END %]
198
                            </fieldset>
199
                        </form>
200
188
201
                        <form action="/cgi-bin/koha/reserve/modrequest_suspendall.pl" method="post">
189
                        <form action="/cgi-bin/koha/reserve/modrequest_suspendall.pl" method="post">
202
                            [% INCLUDE 'csrf-token.inc' %]
190
                            [% INCLUDE 'csrf-token.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/holds.js (-31 / +68 lines)
Lines 107-122 function display_pickup_location(state) { Link Here
107
107
108
/* global __ borrowernumber SuspendHoldsIntranet */
108
/* global __ borrowernumber SuspendHoldsIntranet */
109
$(document).ready(function () {
109
$(document).ready(function () {
110
    function suspend_hold(hold_id, end_date) {
110
    var url = window.location.href;
111
        var params;
111
    let patron_page;
112
        if (end_date !== null && end_date !== "")
112
    if (url.indexOf("/circ/circulation.pl?borrowernumber=") !== -1)
113
            params = JSON.stringify({ end_date: end_date });
113
        patron_page = "circ";
114
    else if (url.indexOf("/members/moremember.pl?borrowernumber=") !== -1)
115
        patron_page = "borrower";
116
117
    function suspend_hold(hold_ids, end_date) {
118
        var params = { hold_ids: hold_ids };
119
        if (end_date !== null && end_date !== "") params.end_date = end_date;
114
120
115
        return $.ajax({
121
        return $.ajax({
116
            method: "POST",
122
            method: "POST",
117
            url: "/api/v1/holds/" + encodeURIComponent(hold_id) + "/suspension",
123
            url: "/api/v1/holds/suspension_bulk",
118
            contentType: "application/json",
124
            contentType: "application/json",
119
            data: params,
125
            data: JSON.stringify(params),
120
        });
126
        });
121
    }
127
    }
122
128
Lines 124-129 $(document).ready(function () { Link Here
124
        return $.ajax({
130
        return $.ajax({
125
            method: "DELETE",
131
            method: "DELETE",
126
            url: "/api/v1/holds/" + encodeURIComponent(hold_id) + "/suspension",
132
            url: "/api/v1/holds/" + encodeURIComponent(hold_id) + "/suspension",
133
        }).done(function () {
134
            if ($(".select_hold_all").prop("checked")) {
135
                $(".select_hold_all").click();
136
            }
127
        });
137
        });
128
    }
138
    }
129
139
Lines 502-508 $(document).ready(function () { Link Here
502
                $(".hold-suspend").on("click", function () {
512
                $(".hold-suspend").on("click", function () {
503
                    var hold_id = $(this).data("hold-id");
513
                    var hold_id = $(this).data("hold-id");
504
                    var hold_title = $(this).data("hold-title");
514
                    var hold_title = $(this).data("hold-title");
505
                    $("#suspend-modal-title").html(hold_title);
515
                    $("#suspend-modal-title").html("<i>" + hold_title + "</i>");
506
                    $("#suspend-modal-submit").data("hold-id", hold_id);
516
                    $("#suspend-modal-submit").data("hold-id", hold_id);
507
                    $("#suspend-modal").modal("show");
517
                    $("#suspend-modal").modal("show");
508
                });
518
                });
Lines 596-602 $(document).ready(function () { Link Here
596
                </div>\
606
                </div>\
597
\
607
\
598
                <div class='modal-body'>\
608
                <div class='modal-body'>\
599
                    <input type='hidden' id='suspend-modal-reserve_id' name='reserve_id' />\
600
\
609
\
601
                    <label for='suspend-modal-until'>" +
610
                    <label for='suspend-modal-until'>" +
602
            __("Suspend until:") +
611
            __("Suspend until:") +
Lines 617-622 $(document).ready(function () { Link Here
617
            __("Cancel") +
626
            __("Cancel") +
618
            "</button>\
627
            "</button>\
619
                </div>\
628
                </div>\
629
                <div id='suspend-selected-container'></div>\
620
            </form>\
630
            </form>\
621
            </div>\
631
            </div>\
622
            </div>\
632
            </div>\
Lines 630-660 $(document).ready(function () { Link Here
630
640
631
    $("#suspend-modal-submit").on("click", function (e) {
641
    $("#suspend-modal-submit").on("click", function (e) {
632
        e.preventDefault();
642
        e.preventDefault();
643
        let selected_holds;
644
        if (!$(this).data("hold-id")) {
645
            selected_holds =
646
                "[" +
647
                $(".holds_table .select_hold:checked")
648
                    .toArray()
649
                    .map(el =>
650
                        JSON.stringify({
651
                            hold: $(el).data("id"),
652
                            borrowernumber: $(el).data("borrowernumber"),
653
                            biblionumber: $(el).data("biblionumber"),
654
                        })
655
                    )
656
                    .join(",") +
657
                "]";
658
        } else {
659
            selected_holds =
660
                "[" + JSON.stringify({ hold: $(this).data("hold-id") }) + "]";
661
            $(this).removeData("hold-id");
662
        }
663
633
        var suspend_until_date = $("#suspend-modal-until").val();
664
        var suspend_until_date = $("#suspend-modal-until").val();
634
        if (suspend_until_date !== null)
665
        if (suspend_until_date !== null)
635
            suspend_until_date = $date(suspend_until_date, {
666
            suspend_until_date = $date(suspend_until_date, {
636
                dateformat: "rfc3339",
667
                dateformat: "rfc3339",
637
            });
668
            });
638
        suspend_hold($(this).data("hold-id"), suspend_until_date)
669
639
            .success(function () {
670
        const hold_ids = JSON.parse(selected_holds).map(hold => hold.hold);
640
                holdsTable.api().ajax.reload();
671
        try {
641
            })
672
            suspend_hold(hold_ids, suspend_until_date)
642
            .error(function (jqXHR, textStatus, errorThrown) {
673
                .success(function () {
643
                if (jqXHR.status === 404) {
674
                    holdsTable.api().ajax.reload();
644
                    alert(__("Unable to suspend, hold not found."));
675
                })
645
                } else {
676
                .done(function () {
646
                    alert(
677
                    if ($("#suspend-modal-until").length) {
647
                        __(
678
                        $("#suspend-modal-until").flatpickr().clear(); // clean the input
648
                            "Your request could not be processed. Check the logs for details."
679
                    }
649
                        )
680
                    $("#suspend-modal").modal("hide");
650
                    );
681
                    if ($(".select_hold_all").prop("checked")) {
651
                }
682
                        $(".select_hold_all").click();
652
                holdsTable.api().ajax.reload();
683
                    }
653
            })
684
                });
654
            .done(function () {
685
        } catch (error) {
655
                $("#suspend-modal-until").flatpickr().clear(); // clean the input
686
            if (error.status === 404) {
656
                $("#suspend-modal").modal("hide");
687
                alert(__("Unable to suspend, hold not found."));
657
            });
688
            } else {
689
                alert(
690
                    __(
691
                        "Your request could not be processed. Check the logs for details."
692
                    )
693
                );
694
            }
695
        }
658
    });
696
    });
659
697
660
    function toggle_suspend(node, inputs) {
698
    function toggle_suspend(node, inputs) {
Lines 699-705 $(document).ready(function () { Link Here
699
    });
737
    });
700
738
701
    var MSG_SUSPEND_SELECTED = _("Suspend selected (%s)");
739
    var MSG_SUSPEND_SELECTED = _("Suspend selected (%s)");
702
    var MSG_SUSPEND_SELECTED_HOLDS = _("Suspend selected holds");
740
    var MSG_SUSPEND_SELECTED_HOLDS = _("selected holds");
703
    $(".suspend_selected_holds").html(
741
    $(".suspend_selected_holds").html(
704
        MSG_SUSPEND_SELECTED.format(
742
        MSG_SUSPEND_SELECTED.format(
705
            $(".holds_table .select_hold:checked").length
743
            $(".holds_table .select_hold:checked").length
Lines 711-717 $(document).ready(function () { Link Here
711
        if (!$(".holds_table .select_hold:checked").length) {
749
        if (!$(".holds_table .select_hold:checked").length) {
712
            return false;
750
            return false;
713
        }
751
        }
714
        $(".modal-title").html(MSG_SUSPEND_SELECTED_HOLDS);
752
        $("#suspend-modal-title").html(MSG_SUSPEND_SELECTED_HOLDS);
715
        $("#suspend-modal").modal("show");
753
        $("#suspend-modal").modal("show");
716
        return false;
754
        return false;
717
    });
755
    });
718
- 

Return to bug 40395