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 491-497 $(document).ready(function () { Link Here
491
                $(".hold-suspend").on("click", function () {
501
                $(".hold-suspend").on("click", function () {
492
                    var hold_id = $(this).data("hold-id");
502
                    var hold_id = $(this).data("hold-id");
493
                    var hold_title = $(this).data("hold-title");
503
                    var hold_title = $(this).data("hold-title");
494
                    $("#suspend-modal-title").html(hold_title);
504
                    $("#suspend-modal-title").html("<i>" + hold_title + "</i>");
495
                    $("#suspend-modal-submit").data("hold-id", hold_id);
505
                    $("#suspend-modal-submit").data("hold-id", hold_id);
496
                    $("#suspend-modal").modal("show");
506
                    $("#suspend-modal").modal("show");
497
                });
507
                });
Lines 585-591 $(document).ready(function () { Link Here
585
                </div>\
595
                </div>\
586
\
596
\
587
                <div class='modal-body'>\
597
                <div class='modal-body'>\
588
                    <input type='hidden' id='suspend-modal-reserve_id' name='reserve_id' />\
589
\
598
\
590
                    <label for='suspend-modal-until'>" +
599
                    <label for='suspend-modal-until'>" +
591
            __("Suspend until:") +
600
            __("Suspend until:") +
Lines 606-611 $(document).ready(function () { Link Here
606
            __("Cancel") +
615
            __("Cancel") +
607
            "</button>\
616
            "</button>\
608
                </div>\
617
                </div>\
618
                <div id='suspend-selected-container'></div>\
609
            </form>\
619
            </form>\
610
            </div>\
620
            </div>\
611
            </div>\
621
            </div>\
Lines 619-649 $(document).ready(function () { Link Here
619
629
620
    $("#suspend-modal-submit").on("click", function (e) {
630
    $("#suspend-modal-submit").on("click", function (e) {
621
        e.preventDefault();
631
        e.preventDefault();
632
        let selected_holds;
633
        if (!$(this).data("hold-id")) {
634
            selected_holds =
635
                "[" +
636
                $(".holds_table .select_hold:checked")
637
                    .toArray()
638
                    .map(el =>
639
                        JSON.stringify({
640
                            hold: $(el).data("id"),
641
                            borrowernumber: $(el).data("borrowernumber"),
642
                            biblionumber: $(el).data("biblionumber"),
643
                        })
644
                    )
645
                    .join(",") +
646
                "]";
647
        } else {
648
            selected_holds =
649
                "[" + JSON.stringify({ hold: $(this).data("hold-id") }) + "]";
650
            $(this).removeData("hold-id");
651
        }
652
622
        var suspend_until_date = $("#suspend-modal-until").val();
653
        var suspend_until_date = $("#suspend-modal-until").val();
623
        if (suspend_until_date !== null)
654
        if (suspend_until_date !== null)
624
            suspend_until_date = $date(suspend_until_date, {
655
            suspend_until_date = $date(suspend_until_date, {
625
                dateformat: "rfc3339",
656
                dateformat: "rfc3339",
626
            });
657
            });
627
        suspend_hold($(this).data("hold-id"), suspend_until_date)
658
628
            .success(function () {
659
        const hold_ids = JSON.parse(selected_holds).map(hold => hold.hold);
629
                holdsTable.api().ajax.reload();
660
        try {
630
            })
661
            suspend_hold(hold_ids, suspend_until_date)
631
            .error(function (jqXHR, textStatus, errorThrown) {
662
                .success(function () {
632
                if (jqXHR.status === 404) {
663
                    holdsTable.api().ajax.reload();
633
                    alert(__("Unable to suspend, hold not found."));
664
                })
634
                } else {
665
                .done(function () {
635
                    alert(
666
                    if ($("#suspend-modal-until").length) {
636
                        __(
667
                        $("#suspend-modal-until").flatpickr().clear(); // clean the input
637
                            "Your request could not be processed. Check the logs for details."
668
                    }
638
                        )
669
                    $("#suspend-modal").modal("hide");
639
                    );
670
                    if ($(".select_hold_all").prop("checked")) {
640
                }
671
                        $(".select_hold_all").click();
641
                holdsTable.api().ajax.reload();
672
                    }
642
            })
673
                });
643
            .done(function () {
674
        } catch (error) {
644
                $("#suspend-modal-until").flatpickr().clear(); // clean the input
675
            if (error.status === 404) {
645
                $("#suspend-modal").modal("hide");
676
                alert(__("Unable to suspend, hold not found."));
646
            });
677
            } else {
678
                alert(
679
                    __(
680
                        "Your request could not be processed. Check the logs for details."
681
                    )
682
                );
683
            }
684
        }
647
    });
685
    });
648
686
649
    function toggle_suspend(node, inputs) {
687
    function toggle_suspend(node, inputs) {
Lines 688-694 $(document).ready(function () { Link Here
688
    });
726
    });
689
727
690
    var MSG_SUSPEND_SELECTED = _("Suspend selected (%s)");
728
    var MSG_SUSPEND_SELECTED = _("Suspend selected (%s)");
691
    var MSG_SUSPEND_SELECTED_HOLDS = _("Suspend selected holds");
729
    var MSG_SUSPEND_SELECTED_HOLDS = _("selected holds");
692
    $(".suspend_selected_holds").html(
730
    $(".suspend_selected_holds").html(
693
        MSG_SUSPEND_SELECTED.format(
731
        MSG_SUSPEND_SELECTED.format(
694
            $(".holds_table .select_hold:checked").length
732
            $(".holds_table .select_hold:checked").length
Lines 700-706 $(document).ready(function () { Link Here
700
        if (!$(".holds_table .select_hold:checked").length) {
738
        if (!$(".holds_table .select_hold:checked").length) {
701
            return false;
739
            return false;
702
        }
740
        }
703
        $(".modal-title").html(MSG_SUSPEND_SELECTED_HOLDS);
741
        $("#suspend-modal-title").html(MSG_SUSPEND_SELECTED_HOLDS);
704
        $("#suspend-modal").modal("show");
742
        $("#suspend-modal").modal("show");
705
        return false;
743
        return false;
706
    });
744
    });
707
- 

Return to bug 40395