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

(-)a/Koha/ILL/Request/Workflow/ConfirmAuto.pm (+116 lines)
Line 0 Link Here
1
package Koha::ILL::Request::Workflow::ConfirmAuto;
2
3
# Copyright 2023 PTFS Europe Ltd
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use base qw(Koha::ILL::Request::Workflow);
23
24
use JSON qw( encode_json );
25
use Koha::ILL::Backends;
26
27
=head1 NAME
28
29
Koha::ILL::Request::Workflow::ConfirmAuto - Koha ILL ConfirmAuto Workflow
30
31
=head1 SYNOPSIS
32
33
Object-oriented class that provides the AutoILLBackendPriority confirmation screen
34
35
=head1 DESCRIPTION
36
37
This class provides the ability to verify if it should render the AutoILLBackendPriority
38
confirmation screen and handle the template params accordingly
39
40
=head1 API
41
42
=head2 Class Methods
43
44
=head3 show_confirm_auto
45
46
    my $show_confirm_auto =
47
    Koha::ILL::Request::Workflow::ConfirmAuto->show_confirm_auto($params);
48
49
Given $request, returns true if confirm auto should be shown
50
51
=cut
52
53
sub show_confirm_auto {
54
    my ( $self, $request ) = @_;
55
56
    return
57
58
        # AutoILLBackendPriority is enabled
59
        C4::Context->preference("AutoILLBackendPriority")
60
61
        # Confirm auto has not yet been submitted
62
        && !$self->{metadata}->{confirm_auto_submitted}
63
64
        # The form has been submitted and the backend is able to create the request
65
        && $request->_backend_capability( 'can_create_request', $self->{metadata} );
66
67
}
68
69
=head3 confirm_auto_template_params
70
71
Given $params, returns the template parameters for rendering the confirm auto screen
72
73
=cut
74
75
sub confirm_auto_template_params {
76
    my ( $self, $params ) = @_;
77
78
    $params->{method} = 'confirmautoill' if $self->{ui_context} eq 'staff';
79
    delete $params->{stage}              if $self->{ui_context} eq 'staff';
80
81
    my @backends = $self->get_priority_backends();
82
    return (
83
        whole              => $params,
84
        metadata           => $self->prep_metadata($params),
85
        core_fields        => Koha::ILL::Backend::Standard->_get_core_fields,
86
        auto_backends_json => scalar encode_json( \@backends ),
87
        $self->{ui_context} eq 'opac'
88
        ? (
89
            illrequestsview => 1,
90
            message         => $params->{message},
91
            op              => 'confirmautoill',
92
            )
93
        : ()
94
    );
95
}
96
97
=head3 get_priority_backends
98
99
Returns backends ordered by AutoILLBackendPriority
100
101
=cut
102
103
sub get_priority_backends {
104
    my ( $self, $params ) = @_;
105
106
    my @backends;
107
    my @priority_enabled_backends = split ",", C4::Context->preference('AutoILLBackendPriority');
108
    foreach my $backend (@priority_enabled_backends) {
109
        my $loaded_backend          = Koha::ILL::Request->new->load_backend($backend);
110
        my $availability_check_info = $loaded_backend->_backend->availability_check_info( $self->{metadata} );
111
        push @backends, $availability_check_info if $availability_check_info;
112
    }
113
    return @backends;
114
}
115
116
1;
(-)a/ill/ill-requests.pl (+7 lines)
Lines 31-36 use Koha::ILL::Request; Link Here
31
use Koha::ILL::Batches;
31
use Koha::ILL::Batches;
32
use Koha::ILL::Request::Workflow::Availability;
32
use Koha::ILL::Request::Workflow::Availability;
33
use Koha::ILL::Request::Workflow::TypeDisclaimer;
33
use Koha::ILL::Request::Workflow::TypeDisclaimer;
34
use Koha::ILL::Request::Workflow::ConfirmAuto;
34
use Koha::Libraries;
35
use Koha::Libraries;
35
use Koha::Plugins;
36
use Koha::Plugins;
36
37
Lines 134-139 if ($backends_available) { Link Here
134
        # Before request creation operations - Preparation
135
        # Before request creation operations - Preparation
135
        my $availability    = Koha::ILL::Request::Workflow::Availability->new( $params, 'staff' );
136
        my $availability    = Koha::ILL::Request::Workflow::Availability->new( $params, 'staff' );
136
        my $type_disclaimer = Koha::ILL::Request::Workflow::TypeDisclaimer->new( $params, 'staff' );
137
        my $type_disclaimer = Koha::ILL::Request::Workflow::TypeDisclaimer->new( $params, 'staff' );
138
        my $confirm_auto    = Koha::ILL::Request::Workflow::ConfirmAuto->new( $params, 'staff' );
137
139
138
        # ILLCheckAvailability operation
140
        # ILLCheckAvailability operation
139
        if ( $availability->show_availability($request) ) {
141
        if ( $availability->show_availability($request) ) {
Lines 145-150 if ($backends_available) { Link Here
145
            $op = 'typedisclaimer';
147
            $op = 'typedisclaimer';
146
            $template->param( $type_disclaimer->type_disclaimer_template_params($params) );
148
            $template->param( $type_disclaimer->type_disclaimer_template_params($params) );
147
149
150
            # ConfirmAuto operation
151
        } elsif ( $confirm_auto->show_confirm_auto($request) ) {
152
            $op = 'confirmautoill';
153
            $template->param( $confirm_auto->confirm_auto_template_params($params) );
154
148
            # Ready to create ILL request
155
            # Ready to create ILL request
149
        } else {
156
        } else {
150
            my $backend_result = $request->backend_create($params);
157
            my $backend_result = $request->backend_create($params);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt (+48 lines)
Lines 46-51 Link Here
46
            [% WRAPPER breadcrumb_item bc_active= 1 %]
46
            [% WRAPPER breadcrumb_item bc_active= 1 %]
47
                <span>Request type disclaimer</span>
47
                <span>Request type disclaimer</span>
48
            [% END %]
48
            [% END %]
49
        [% ELSIF op == 'confirmautoill' %]
50
            [% WRAPPER breadcrumb_item %]
51
                <a href="/cgi-bin/koha/ill/ill-requests.pl">ILL requests</a>
52
            [% END %]
53
            [% WRAPPER breadcrumb_item bc_active= 1 %]
54
                <span>Confirm automatic request</span>
55
            [% END %]
49
        [% ELSE %]
56
        [% ELSE %]
50
            [% WRAPPER breadcrumb_item bc_active= 1 %]
57
            [% WRAPPER breadcrumb_item bc_active= 1 %]
51
                <span>ILL requests</span>
58
                <span>ILL requests</span>
Lines 846-851 Link Here
846
                        </fieldset>
853
                        </fieldset>
847
                    </form>
854
                    </form>
848
                </div>
855
                </div>
856
            [% ELSIF op == 'confirmautoill' %]
857
                <!-- confirmautoill -->
858
                <h1>Confirm automatic request</h1>
859
                <div id="results" class="page-section">
860
                    <form method="post" id="confirmautoill-form">
861
                        <fieldset class="rows">
862
                            <h3>Confirm backend:</h3>
863
                            <p id="autoillbackends"></p>
864
                            <p id="autoillbackend-message" class="text-info"></p>
865
                        </fieldset>
866
                        <fieldset class="action">
867
                            [% FOREACH key IN whole.keys %]
868
                                [% value = whole.$key %]
869
                                [% IF key != 'method' && key != 'custom_key' && key != 'custom_value' %]
870
                                    <input type="hidden" name="[% key | html %]" value="[% value | html %]" />
871
                                [% END %]
872
                            [% END %]
873
                            [% custom_keys = whole.custom_key.split('\0') %]
874
                            [% custom_values = whole.custom_value.split('\0') %]
875
                            [% i = 0 %]
876
                            [% FOREACH custom_key IN custom_keys %]
877
                                <input type="hidden" name="custom_key" value="[% custom_key | html %]" />
878
                                <input type="hidden" name="custom_value" value="[% custom_values.$i | html %]" />
879
                                [% i = i + 1 %]
880
                            [% END %]
881
                            <input type="hidden" name="method" value="create" />
882
                            <input type="hidden" name="stage" value="form" />
883
                            <input type="hidden" name="confirm_auto_submitted" value="1" />
884
                            <input type="submit" value="Confirm" />
885
                            <a class="cancel" href="ill-requests.pl">Cancel</a>
886
                        </fieldset>
887
                    </form>
888
                </div>
849
            [% ELSIF op == 'batch_list' || op == 'batch_create' %]
889
            [% ELSIF op == 'batch_list' || op == 'batch_create' %]
850
                [% INCLUDE 'ill-batch.inc' %]
890
                [% INCLUDE 'ill-batch.inc' %]
851
            [% ELSE %]
891
            [% ELSE %]
Lines 886-891 Link Here
886
        [% ELSE %]
926
        [% ELSE %]
887
        var services = [];
927
        var services = [];
888
        [% END %]
928
        [% END %]
929
        [% IF auto_backends_json.length > 0 %]
930
        var auto_backends = [% auto_backends_json | $raw %];
931
        [% ELSE %]
932
        var auto_backends = [];
933
        [% END %]
889
        [% IF metadata.length > 0 %]
934
        [% IF metadata.length > 0 %]
890
        var metadata = "[% metadata | $raw %]";
935
        var metadata = "[% metadata | $raw %]";
891
        [% END %]
936
        [% END %]
Lines 918-923 Link Here
918
    [% IF (op == 'availability' || op == 'generic_confirm') && Koha.Preference('ILLCheckAvailability') %]
963
    [% IF (op == 'availability' || op == 'generic_confirm') && Koha.Preference('ILLCheckAvailability') %]
919
        [% Asset.js("js/ill-availability.js") | $raw %]
964
        [% Asset.js("js/ill-availability.js") | $raw %]
920
    [% END %]
965
    [% END %]
966
    [% IF (op == 'confirmautoill' && Koha.Preference('AutoILLBackendPriority')) %]
967
        [% Asset.js("js/ill-autobackend.js") | $raw %]
968
    [% END %]
921
    [% IF op == 'availability' && Koha.Preference('ILLCheckAvailability') %]
969
    [% IF op == 'availability' && Koha.Preference('ILLCheckAvailability') %]
922
        <script>
970
        <script>
923
            $(document).ready(function () {
971
            $(document).ready(function () {
(-)a/koha-tmpl/intranet-tmpl/prog/js/ill-autobackend.js (+169 lines)
Line 0 Link Here
1
$(document).ready(function () {
2
    let auto_ill_el = "#confirmautoill-form #autoillbackends";
3
    let auto_ill_message_el = "#confirmautoill-form #autoillbackend-message";
4
5
    confirmAutoInit();
6
    getBackendsAvailability(auto_backends, metadata);
7
8
    /**
9
     * Retrieves the backend availability for a given auto backend and metadata.
10
     *
11
     * @param {Object} auto_backend - The auto backend object.
12
     * @param {string} metadata - The metadata string.
13
     * @return {Promise} A Promise that resolves to the JSON response.
14
     */
15
    async function getBackendAvailability(auto_backend, metadata) {
16
        return $.ajax({
17
            url: auto_backend.endpoint + metadata,
18
            type: "GET",
19
            dataType: "json",
20
            beforeSend: function () {
21
                _addBackendPlaceholderEl(auto_backend.name);
22
                _addBackendOption(auto_backend.name);
23
                _addVerifyingMessage(auto_backend.name);
24
                auto_backend.available = 0;
25
            },
26
            success: function (data) {
27
                _addSuccessMessage(auto_backend.name);
28
                auto_backend.available = 1;
29
            },
30
            error: function (request, textstatus) {
31
                if (textstatus === "timeout") {
32
                    _addErrorMessage(
33
                        auto_backend.name,
34
                        __("Verification timed out.")
35
                    );
36
                } else {
37
                    let message = "Error";
38
                    if (request.hasOwnProperty("responseJSON")) {
39
                        if (request.responseJSON.error) {
40
                            message = request.responseJSON.error;
41
                        } else if (request.responseJSON.errors) {
42
                            message = request.responseJSON.errors
43
                                .map(error => error.message)
44
                                .join(", ");
45
                        }
46
                    }
47
                    _addErrorMessage(auto_backend.name, message);
48
                }
49
            },
50
            timeout: 10000,
51
        });
52
    }
53
54
    /**
55
     * Asynchronously checks the availability of multiple auto backends.
56
     *
57
     * @param {Array} auto_backends - An array of auto backends to check availability for.
58
     * @param {Object} metadata - Additional metadata for the availability check.
59
     * @return {void}
60
     */
61
    function getBackendsAvailability(auto_backends, metadata) {
62
        let promises = [];
63
        for (const auto_backend of auto_backends) {
64
            try {
65
                const prom = getBackendAvailability(auto_backend, metadata);
66
                promises.push(prom);
67
            } catch (e) {
68
                console.log(e);
69
            }
70
        }
71
        Promise.allSettled(promises).then(() => {
72
            let auto_backend = auto_backends.find(backend => backend.available);
73
            if (typeof auto_backend === "undefined") {
74
                _setAutoBackend("Standard");
75
            } else {
76
                _setAutoBackend(auto_backend.name);
77
            }
78
            $('#confirmautoill-form .action input[type="submit"]').prop(
79
                "disabled",
80
                false
81
            );
82
        });
83
        _addBackendPlaceholderEl("Standard");
84
        _addBackendOption("Standard");
85
    }
86
87
    function _addSuccessMessage(auto_backend_name) {
88
        _removeVerifyingMessage(auto_backend_name);
89
        $(auto_ill_el + " > #backend-" + auto_backend_name).append(
90
            '<span class="text-success"><i class="fa-solid fa-check"></i> ' +
91
                __("Available.").format(auto_backend_name) +
92
                "</span>"
93
        );
94
    }
95
96
    function _addErrorMessage(auto_backend_name, message) {
97
        _removeVerifyingMessage(auto_backend_name);
98
        $(auto_ill_el + " > #backend-" + auto_backend_name).append(
99
            '<span class="text-danger"> <i class="fa-solid fa-xmark"></i> ' +
100
                __("Not readily available:").format(auto_backend_name) +
101
                " " +
102
                message +
103
                "</span>"
104
        );
105
        $(
106
            auto_ill_el +
107
                " > #backend-" +
108
                auto_backend_name +
109
                ' input[type="radio"]'
110
        ).prop("disabled", true);
111
    }
112
113
    function _addBackendOption(auto_backend_name) {
114
        $(auto_ill_el + " > #backend-" + auto_backend_name).append(
115
            ' <input type="radio" id="' +
116
                auto_backend_name +
117
                '" name="backend" value="' +
118
                auto_backend_name +
119
                '">' +
120
                ' <label for="' +
121
                auto_backend_name +
122
                '" class="radio">' +
123
                auto_backend_name +
124
                "</label> "
125
        );
126
    }
127
128
    function _addVerifyingMessage(auto_backend_name) {
129
        $(auto_ill_el + " > #backend-" + auto_backend_name).append(
130
            '<span id="verifying-availabilty" class="text-info"><i id="issues-table-load-delay-spinner" class="fa fa-spinner fa-pulse fa-fw"></i> ' +
131
                __("Verifying availability...").format(auto_backend_name) +
132
                "</span>"
133
        );
134
    }
135
    function _removeVerifyingMessage(auto_backend_name) {
136
        $(
137
            auto_ill_el +
138
                " #backend-" +
139
                auto_backend_name +
140
                " #verifying-availabilty"
141
        ).remove();
142
    }
143
144
    function _setAutoBackend(auto_backend_name) {
145
        $(
146
            '#confirmautoill-form #autoillbackends input[id="' +
147
                auto_backend_name +
148
                '"]'
149
        ).prop("checked", true);
150
        $(auto_ill_message_el).html(
151
            __(
152
                "The recommended backend for your request is <strong>%s</strong>."
153
            ).format(auto_backend_name)
154
        );
155
    }
156
157
    function _addBackendPlaceholderEl(auto_backend_name) {
158
        $(auto_ill_el).append('<div id="backend-' + auto_backend_name + '">');
159
    }
160
161
    function confirmAutoInit() {
162
        $('#confirmautoill-form .action input[name="backend"]').remove();
163
        $('#confirmautoill-form .action input[type="submit"]').prop(
164
            "disabled",
165
            true
166
        );
167
        $(auto_ill_message_el).html(__("Fetching backends availability..."));
168
    }
169
});
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-illrequests.tt (-1 / +41 lines)
Lines 46-51 Link Here
46
                [% WRAPPER breadcrumb_item bc_active= 1 %]
46
                [% WRAPPER breadcrumb_item bc_active= 1 %]
47
                    <span>Ill request disclaimer</span>
47
                    <span>Ill request disclaimer</span>
48
                [% END %]
48
                [% END %]
49
            [% ELSIF op == 'confirmautoill' %]
50
                [% WRAPPER breadcrumb_item bc_active= 1 %]
51
                    <span>Confirm automatic request</span>
52
                [% END %]
49
            [% END %]
53
            [% END %]
50
        [% ELSE %]
54
        [% ELSE %]
51
            [% WRAPPER breadcrumb_item bc_active= 1 %]
55
            [% WRAPPER breadcrumb_item bc_active= 1 %]
Lines 114-120 Link Here
114
                            [% IF can_patron_place_ill_in_opac %]
118
                            [% IF can_patron_place_ill_in_opac %]
115
                                <div id="illrequests-create-button" class="dropdown btn-group">
119
                                <div id="illrequests-create-button" class="dropdown btn-group">
116
                                    [% IF Koha.Preference('AutoILLBackendPriority') %]
120
                                    [% IF Koha.Preference('AutoILLBackendPriority') %]
117
                                        <a id="ill-new" class="btn btn-primary" href="/cgi-bin/koha/opac-illrequests.pl?method=create&amp;backend=Standard"> <i class="fa fa-plus" aria-hidden="true"></i> Create a new request </a>
121
                                        <a id="ill-new" class="btn btn-primary" href="/cgi-bin/koha/opac-illrequests.pl?method=create&amp;backend=Standard"> <i class="fa fa-plus" aria-hidden="true"></i> Create a new auto request </a>
118
                                    [% ELSIF backends.size > 1 %]
122
                                    [% ELSIF backends.size > 1 %]
119
                                        <button class="btn btn-primary dropdown-toggle" type="button" id="ill-backend-dropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
123
                                        <button class="btn btn-primary dropdown-toggle" type="button" id="ill-backend-dropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
120
                                            <i class="fa fa-plus" aria-hidden="true"></i> Create a new request <span class="caret"></span>
124
                                            <i class="fa fa-plus" aria-hidden="true"></i> Create a new request <span class="caret"></span>
Lines 318-323 Link Here
318
                                    </fieldset>
322
                                    </fieldset>
319
                                </form>
323
                                </form>
320
                            </div>
324
                            </div>
325
                        [% ELSIF op == 'confirmautoill' %]
326
                            <h1>Confirming automatic request</h1>
327
                            <div id="results" class="page-section">
328
                                <form method="post" id="confirmautoill-form">
329
                                    [% INCLUDE 'csrf-token.inc' %]
330
                                    <fieldset class="rows">
331
                                        <p id="autoillbackends"></p>
332
                                        <p id="autoillbackend-message" class="text-info"></p>
333
                                    </fieldset>
334
                                    <fieldset class="action">
335
                                        [% FOREACH key IN whole.keys %]
336
                                            [% value = whole.$key %]
337
                                            [% IF key != 'custom_key' && key != 'custom_value' && key != 'csrf_token' %]
338
                                                <input type="hidden" name="[% key | html %]" value="[% value | html %]" />
339
                                            [% END %]
340
                                        [% END %]
341
                                        [% custom_keys = whole.custom_key.split('\0') %]
342
                                        [% custom_values = whole.custom_value.split('\0') %]
343
                                        [% i = 0 %]
344
                                        [% FOREACH custom_key IN custom_keys %]
345
                                            <input type="hidden" name="custom_key" value="[% custom_key | html %]" />
346
                                            <input type="hidden" name="custom_value" value="[% custom_values.$i | html %]" />
347
                                            [% i = i + 1 %]
348
                                        [% END %]
349
                                        <input type="hidden" name="confirm_auto_submitted" value="1" />
350
                                    </fieldset>
351
                                </form>
352
                            </div>
321
                        [% END # / IF op == 'cud-create' %]
353
                        [% END # / IF op == 'cud-create' %]
322
                    </div>
354
                    </div>
323
                    <!-- / #illrequests -->
355
                    <!-- / #illrequests -->
Lines 346-351 Link Here
346
        [% ELSE %]
378
        [% ELSE %]
347
            var services = [];
379
            var services = [];
348
        [% END %]
380
        [% END %]
381
        [% IF auto_backends_json.length > 0 %]
382
        var auto_backends = [% auto_backends_json | $raw %];
383
        [% ELSE %]
384
        var auto_backends = [];
385
        [% END %]
349
        [% IF metadata.length > 0 %]
386
        [% IF metadata.length > 0 %]
350
            var metadata = "[% metadata | $raw %]";
387
            var metadata = "[% metadata | $raw %]";
351
        [% END %]
388
        [% END %]
Lines 358-363 Link Here
358
            });
395
            });
359
        </script>
396
        </script>
360
    [% END %]
397
    [% END %]
398
    [% IF op == 'confirmautoill' %]
399
        [% Asset.js("js/ill-autobackend.js") | $raw %]
400
    [% END %]
361
    <!-- prettier-ignore-start -->
401
    <!-- prettier-ignore-start -->
362
    [% TRY %]
402
    [% TRY %]
363
        [% PROCESS backend_jsinclude %]
403
        [% PROCESS backend_jsinclude %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/ill-autobackend.js (+161 lines)
Line 0 Link Here
1
$(document).ready(function () {
2
    let auto_ill_el = "#confirmautoill-form #autoillbackends";
3
    let auto_ill_message_el = "#confirmautoill-form #autoillbackend-message";
4
5
    confirmAutoInit();
6
    getBackendsAvailability(auto_backends, metadata);
7
8
    /**
9
     * Retrieves the backend availability for a given auto backend and metadata.
10
     *
11
     * @param {Object} auto_backend - The auto backend object.
12
     * @param {string} metadata - The metadata string.
13
     * @return {Promise} A Promise that resolves to the JSON response.
14
     */
15
    async function getBackendAvailability(auto_backend, metadata) {
16
        return $.ajax({
17
            url: auto_backend.endpoint + metadata,
18
            type: "GET",
19
            dataType: "json",
20
            beforeSend: function () {
21
                _addBackendPlaceholderEl(auto_backend.name);
22
                _addBackendOption(auto_backend.name);
23
                _addVerifyingMessage(auto_backend.name);
24
                auto_backend.available = 0;
25
            },
26
            success: function (data) {
27
                _addSuccessMessage(auto_backend.name);
28
                auto_backend.available = 1;
29
            },
30
            error: function (request, textstatus) {
31
                if (textstatus === "timeout") {
32
                    _addErrorMessage(
33
                        auto_backend.name,
34
                        __("Verification timed out.")
35
                    );
36
                } else {
37
                    let message = "Error";
38
                    if (request.hasOwnProperty("responseJSON")) {
39
                        if (request.responseJSON.error) {
40
                            message = request.responseJSON.error;
41
                        } else if (request.responseJSON.errors) {
42
                            message = request.responseJSON.errors
43
                                .map(error => error.message)
44
                                .join(", ");
45
                        }
46
                    }
47
                    _addErrorMessage(auto_backend.name, message);
48
                }
49
            },
50
            timeout: 10000,
51
        });
52
    }
53
54
    /**
55
     * Asynchronously checks the availability of multiple auto backends.
56
     *
57
     * @param {Array} auto_backends - An array of auto backends to check availability for.
58
     * @param {Object} metadata - Additional metadata for the availability check.
59
     * @return {void}
60
     */
61
    function getBackendsAvailability(auto_backends, metadata) {
62
        let promises = [];
63
        for (const auto_backend of auto_backends) {
64
            try {
65
                const prom = getBackendAvailability(auto_backend, metadata);
66
                promises.push(prom);
67
            } catch (e) {
68
                console.log(e);
69
            }
70
        }
71
        Promise.allSettled(promises).then(() => {
72
            let auto_backend = auto_backends.find(backend => backend.available);
73
            if (typeof auto_backend === "undefined") {
74
                _setAutoBackend("Standard");
75
            } else {
76
                _setAutoBackend(auto_backend.name);
77
            }
78
            $('#confirmautoill-form .action input[type="submit"]').prop(
79
                "disabled",
80
                false
81
            );
82
        });
83
        _addBackendPlaceholderEl("Standard");
84
        _addBackendOption("Standard");
85
    }
86
87
    function _addSuccessMessage(auto_backend_name) {
88
        _removeVerifyingMessage(auto_backend_name);
89
        $(auto_ill_el + " > #backend-" + auto_backend_name).append(
90
            '<span class="text-success"><i class="fa-solid fa-check"></i> ' +
91
                __("Available.").format(auto_backend_name) +
92
                "</span>"
93
        );
94
    }
95
96
    function _addErrorMessage(auto_backend_name, message) {
97
        _removeVerifyingMessage(auto_backend_name);
98
        $(auto_ill_el + " > #backend-" + auto_backend_name).append(
99
            '<span class="text-danger"> <i class="fa-solid fa-xmark"></i> ' +
100
                __("Not readily available:").format(auto_backend_name) +
101
                " " +
102
                message +
103
                "</span>"
104
        );
105
    }
106
107
    function _addBackendOption(auto_backend_name) {
108
        $(auto_ill_el + " > #backend-" + auto_backend_name).append(
109
            ' <input type="radio" id="' +
110
                auto_backend_name +
111
                '" name="backend" value="' +
112
                auto_backend_name +
113
                '">' +
114
                ' <label for="' +
115
                auto_backend_name +
116
                '" class="radio">' +
117
                auto_backend_name +
118
                "</label> "
119
        );
120
    }
121
122
    function _addVerifyingMessage(auto_backend_name) {
123
        $(auto_ill_el + " > #backend-" + auto_backend_name).append(
124
            '<span id="verifying-availabilty" class="text-info"><i id="issues-table-load-delay-spinner" class="fa fa-spinner fa-pulse fa-fw"></i> ' +
125
                __("Verifying availability...").format(auto_backend_name) +
126
                "</span>"
127
        );
128
    }
129
    function _removeVerifyingMessage(auto_backend_name) {
130
        $(
131
            auto_ill_el +
132
                " #backend-" +
133
                auto_backend_name +
134
                " #verifying-availabilty"
135
        ).remove();
136
    }
137
138
    function _setAutoBackend(auto_backend_name) {
139
        $(
140
            '#confirmautoill-form #autoillbackends input[id="' +
141
                auto_backend_name +
142
                '"]'
143
        ).prop("checked", true);
144
        $("#confirmautoill-form").submit();
145
    }
146
147
    function _addBackendPlaceholderEl(auto_backend_name) {
148
        $(auto_ill_el)
149
            .append('<div id="backend-' + auto_backend_name + '">')
150
            .hide();
151
    }
152
153
    function confirmAutoInit() {
154
        $('#confirmautoill-form .action input[name="backend"]').remove();
155
        $(auto_ill_message_el).html(
156
            '<span id="verifying-availabilty" class="text-info"><i id="issues-table-load-delay-spinner" class="fa fa-spinner fa-pulse fa-fw"></i> ' +
157
                __("Placing your request...") +
158
                "</span>"
159
        );
160
    }
161
});
(-)a/opac/opac-illrequests.pl (-1 / +11 lines)
Lines 33-38 use Koha::ILL::Request; Link Here
33
use Koha::Libraries;
33
use Koha::Libraries;
34
use Koha::Patrons;
34
use Koha::Patrons;
35
use Koha::ILL::Request::Workflow::Availability;
35
use Koha::ILL::Request::Workflow::Availability;
36
use Koha::ILL::Request::Workflow::ConfirmAuto;
36
use Koha::ILL::Request::Workflow::TypeDisclaimer;
37
use Koha::ILL::Request::Workflow::TypeDisclaimer;
37
38
38
my $query = CGI->new;
39
my $query = CGI->new;
Lines 117-122 if ( $op eq 'list' ) { Link Here
117
        # Before request creation operations - Preparation
118
        # Before request creation operations - Preparation
118
        my $availability    = Koha::ILL::Request::Workflow::Availability->new( $params, 'opac' );
119
        my $availability    = Koha::ILL::Request::Workflow::Availability->new( $params, 'opac' );
119
        my $type_disclaimer = Koha::ILL::Request::Workflow::TypeDisclaimer->new( $params, 'opac' );
120
        my $type_disclaimer = Koha::ILL::Request::Workflow::TypeDisclaimer->new( $params, 'opac' );
121
        my $confirm_auto    = Koha::ILL::Request::Workflow::ConfirmAuto->new( $params, 'opac' );
120
122
121
        # ILLCheckAvailability operation
123
        # ILLCheckAvailability operation
122
        if ( $availability->show_availability($request) ) {
124
        if ( $availability->show_availability($request) ) {
Lines 135-140 if ( $op eq 'list' ) { Link Here
135
                $template->output, undef,
137
                $template->output, undef,
136
                { force_no_caching => 1 };
138
                { force_no_caching => 1 };
137
            exit;
139
            exit;
140
141
            # ConfirmAuto operation
142
        } elsif ( $confirm_auto->show_confirm_auto($request) ) {
143
            $op = 'confirmautoill';
144
            $template->param( $confirm_auto->confirm_auto_template_params($params) );
145
            output_html_with_http_headers $query, $cookie,
146
                $template->output, undef,
147
                { force_no_caching => 1 };
148
            exit;
138
        }
149
        }
139
150
140
        my $patron = Koha::Patrons->find( { borrowernumber => $loggedinuser } );
151
        my $patron = Koha::Patrons->find( { borrowernumber => $loggedinuser } );
141
- 

Return to bug 35604