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

(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt (-24 / +19 lines)
Lines 189-195 Link Here
189
</div>
189
</div>
190
<!-- / .main -->
190
<!-- / .main -->
191
191
192
[%# Help modal %]
192
[% # Help modal %]
193
<div id="helpModal" class="modal" tabindex="-1" role="dialog" aria-labelledby="helpModalLabel" aria-hidden="true">
193
<div id="helpModal" class="modal" tabindex="-1" role="dialog" aria-labelledby="helpModalLabel" aria-hidden="true">
194
    <div class="modal-dialog">
194
    <div class="modal-dialog">
195
        <div class="modal-content">
195
        <div class="modal-content">
Lines 222-227 Link Here
222
222
223
[% INCLUDE 'opac-bottom.inc' %]
223
[% INCLUDE 'opac-bottom.inc' %]
224
[% BLOCK jsinclude %]
224
[% BLOCK jsinclude %]
225
    [% Asset.js('js/timeout.js') | $raw %]
225
    <script>
226
    <script>
226
        function mungeHistory() {
227
        function mungeHistory() {
227
                    // prevent back button from allowing form resubmission
228
                    // prevent back button from allowing form resubmission
Lines 272-277 Link Here
272
                    $("#sci_barcodes_table").show();
273
                    $("#sci_barcodes_table").show();
273
                    $('#sci_checkin_button').show();
274
                    $('#sci_checkin_button').show();
274
                    $('#sci_refresh_button').show();
275
                    $('#sci_refresh_button').show();
276
                    login_timeout();
275
277
276
                    // Add barcode to the array
278
                    // Add barcode to the array
277
                    barcodes.push(barcode);
279
                    barcodes.push(barcode);
Lines 291-321 Link Here
291
            dofocus();
293
            dofocus();
292
        });
294
        });
293
295
294
296
            document.addEventListener("DOMContentLoaded",function(){
295
                var idleTime = 0;
297
                if ( document.querySelector('#sci_finish_button,#sci_append_button') ){
296
                $(document).ready(function () {
298
                    login_timeout();
297
                    //Increment the idle time counter every second
299
                }
298
                    var idleInterval = setInterval(timerIncrement, 1000);
300
            });
299
301
            function login_timeout(){
300
                    //Zero the idle timer on mouse movement.
302
                //NOTE: There can only be 1 sci_login_timer at a time
301
                    $(this).mousemove(function (e) {
303
                if ( ! window.sci_login_timer ){
302
                        idleTime = 0;
304
                    const idleTimeout = "[% Koha.Preference('SelfCheckInTimeOut') || 120 | html %]";
303
                    });
305
                    const home_href = "/cgi-bin/koha/sci/sci-main.pl";
304
                    $(this).keypress(function (e) {
306
                    const sci_timer = new sc_timer({
305
                        idleTime = 0;
307
                        "idle_timeout": idleTimeout,
308
                        "redirect_url": home_href
306
                    });
309
                    });
307
                });
310
                    window.sci_login_timer = sci_timer;
308
311
                    sci_timer.start_timer();
309
                function timerIncrement() {
310
                    if ( $("#sci_finish_button").is(":visible") || $("#sci_refresh_button").is(":visible") ) {
311
                        idleTime = idleTime + 1;
312
                        idleTimeout = [% refresh_timeout | html %];
313
                        if (idleTime >= idleTimeout ) {
314
                            location.href = '/cgi-bin/koha/sci/sci-main.pl';
315
                        }
316
                    }
317
                }
312
                }
318
313
            }
319
314
320
                function checkBarcodeInput() {
315
                function checkBarcodeInput() {
321
                    var inputField = document.getElementById("barcode_input");
316
                    var inputField = document.getElementById("barcode_input");
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt (-11 / +21 lines)
Lines 55-60 Link Here
55
[% END %]
55
[% END %]
56
[% Asset.js('js/Gettext.js') | $raw %]
56
[% Asset.js('js/Gettext.js') | $raw %]
57
[% Asset.js('js/i18n.js') | $raw %]
57
[% Asset.js('js/i18n.js') | $raw %]
58
[% Asset.js('js/timeout.js') | $raw %]
58
</head>
59
</head>
59
<body id="sco_main" class="sco">
60
<body id="sco_main" class="sco">
60
<div id="wrapper">
61
<div id="wrapper">
Lines 328-334 Link Here
328
                                                            <input type="password" id="patronpw" class="form-control" size="20" name="patronpw" autocomplete="off" />
329
                                                            <input type="password" id="patronpw" class="form-control" size="20" name="patronpw" autocomplete="off" />
329
                                                        </div>
330
                                                        </div>
330
                                                        <div class="col-md-12">
331
                                                        <div class="col-md-12">
331
                                                            <button type="submit" class="btn btn-primary">Log in</button>
332
                                                            <button id="sco_patron_login" type="submit" class="btn btn-primary">Log in</button>
332
                                                        </div>
333
                                                        </div>
333
                                                    </div>
334
                                                    </div>
334
                                                    <!-- /.row -->
335
                                                    <!-- /.row -->
Lines 341-347 Link Here
341
                                                            <input type="text" id="patronid" class="form-control focus" size="20" name="patronid" autocomplete="off" />
342
                                                            <input type="text" id="patronid" class="form-control focus" size="20" name="patronid" autocomplete="off" />
342
                                                        </div>
343
                                                        </div>
343
                                                        <div class="col-md-12">
344
                                                        <div class="col-md-12">
344
                                                            <button type="submit" class="btn btn-primary">Submit</button>
345
                                                            <button id="sco_patron_login" type="submit" class="btn btn-primary">Submit</button>
345
                                                        </div>
346
                                                        </div>
346
                                                    </div>
347
                                                    </div>
347
                                                    <!-- /.row -->
348
                                                    <!-- /.row -->
Lines 401-411 Link Here
401
                        history.replaceState(null, document.title, window.location.href);
402
                        history.replaceState(null, document.title, window.location.href);
402
                    }
403
                    }
403
                }
404
                }
404
                var mainTimeout;
405
                document.addEventListener("DOMContentLoaded",function(){
405
                function sco_init() {
406
                    if ( document.querySelector('#sco_patron_login,#logout_form') ){
406
                    mainTimeout = setTimeout(function() {
407
                        login_timeout();
407
                        location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout';
408
                    }
408
                    }, [% SelfCheckTimeout | html %]);
409
                });
410
                function login_timeout(){
411
                    //NOTE: There can only be 1 sco_login_timer at a time
412
                    if ( ! window.sco_login_timer ){
413
                        const idleTimeout = "[% Koha.Preference('SelfCheckTimeout') || 120 | html %]";
414
                        const home_href = "/cgi-bin/koha/sco/sco-main.pl?op=logout";
415
                        const sco_timer = new sc_timer({
416
                            "idle_timeout": idleTimeout,
417
                            "redirect_url": home_href
418
                        });
419
                        window.sco_login_timer = sco_timer;
420
                        sco_timer.start_timer();
421
                    }
409
                }
422
                }
410
                function dofocus() {    // named function req'd for body onload event by some FF and IE7 security models
423
                function dofocus() {    // named function req'd for body onload event by some FF and IE7 security models
411
                    // alert("dofocus called");
424
                    // alert("dofocus called");
Lines 458-464 Link Here
458
471
459
                $(document).ready(function() {
472
                $(document).ready(function() {
460
                    dofocus();
473
                    dofocus();
461
                    [% IF ( patronid ) %]sco_init();[% END %]
462
474
463
                    var dTables = $("#loanTable, #holdst, #finestable");
475
                    var dTables = $("#loanTable, #holdst, #finestable");
464
                    dTables.each(function(){
476
                    dTables.each(function(){
Lines 490-507 Link Here
490
502
491
                    $("#logout_form").on("click", function(e){
503
                    $("#logout_form").on("click", function(e){
492
                        e.preventDefault(e);
504
                        e.preventDefault(e);
493
                        clearTimeout(mainTimeout);
494
                        [% IF Koha.Preference('SelfCheckReceiptPrompt') %]
505
                        [% IF Koha.Preference('SelfCheckReceiptPrompt') %]
495
                            var confirmStart = Date.now();
506
                            var confirmStart = Date.now();
496
                            confirmModal("", _("Would you like to print a receipt?"), _("Print receipt and end session"), _("End session"), function(result) {
507
                            confirmModal("", _("Would you like to print a receipt?"), _("Print receipt and end session"), _("End session"), function(result) {
497
                                if ( result && (Date.now() - confirmStart) < [% SelfCheckTimeout | html %] ) {
508
                                if ( result && (Date.now() - confirmStart) < [% Koha.Preference('SelfCheckTimeout') | html %] ) {
498
                                    var win = window.open("/cgi-bin/koha/sco/printslip.pl?print=qslip");
509
                                    var win = window.open("/cgi-bin/koha/sco/printslip.pl?print=qslip");
499
                                    location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout';
510
                                    location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout';
500
                                } else {
511
                                } else {
501
                                    location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout';
512
                                    location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout';
502
                                }
513
                                }
503
                            })
514
                            })
504
                        sco_init();
505
                        [% ELSE %]
515
                        [% ELSE %]
506
                            location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout';
516
                            location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout';
507
                        [% END %]
517
                        [% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js (+39 lines)
Line 0 Link Here
1
class sc_timer {
2
    constructor(args) {
3
        const idle_timeout = args["idle_timeout"];
4
        const redirect_url = args["redirect_url"];
5
        if (idle_timeout) {
6
            this.idle_timeout = idle_timeout;
7
        }
8
        if (redirect_url) {
9
            this.redirect_url = redirect_url;
10
        }
11
        this.idle_time = 0;
12
    }
13
14
    start_timer() {
15
        const self = this;
16
        //Increment the idle time counter every 1 second
17
        const idle_interval = setInterval(function () {
18
            self._timer_increment();
19
        }, 1000);
20
21
        document.addEventListener("mousemove", function () {
22
            self.reset_timer();
23
        });
24
        document.addEventListener("keypress", function () {
25
            self.reset_timer();
26
        });
27
    }
28
29
    reset_timer() {
30
        this.idle_time = 0;
31
    }
32
33
    _timer_increment() {
34
        this.idle_time++;
35
        if (this.idle_time >= this.idle_timeout) {
36
            location.href = this.redirect_url;
37
        }
38
    }
39
}
(-)a/opac/sci/sci-main.pl (-4 lines)
Lines 102-109 if ( $op eq 'cud-check_in' ) { Link Here
102
    $template->param( success => \@success, errors => \@errors, checkins => 1 );
102
    $template->param( success => \@success, errors => \@errors, checkins => 1 );
103
}
103
}
104
104
105
# Make sure timeout has a reasonable value
106
my $timeout = C4::Context->preference('SelfCheckInTimeout') || 120;
107
$template->param( refresh_timeout => $timeout );
108
109
output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 };
105
output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 };
(-)a/opac/sco/sco-main.pl (-8 lines)
Lines 74-86 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
74
    }
74
    }
75
);
75
);
76
76
77
# Get the self checkout timeout preference, or use 120 seconds as a default
78
my $selfchecktimeout = 120000;
79
if ( C4::Context->preference('SelfCheckTimeout') ) {
80
    $selfchecktimeout = C4::Context->preference('SelfCheckTimeout') * 1000;
81
}
82
$template->param( SelfCheckTimeout => $selfchecktimeout );
83
84
# Checks policy laid out by SCOAllowCheckin, defaults to 'on' if preference is undefined
77
# Checks policy laid out by SCOAllowCheckin, defaults to 'on' if preference is undefined
85
my $allowselfcheckreturns = 1;
78
my $allowselfcheckreturns = 1;
86
if ( defined C4::Context->preference('SCOAllowCheckin') ) {
79
if ( defined C4::Context->preference('SCOAllowCheckin') ) {
87
- 

Return to bug 36586