From 54bb21b1f36cbf47d8055b475ba5107c0b8d8419 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 29 Apr 2025 11:19:58 +0000 Subject: [PATCH] Bug 36586: Add sc-timer to sco This patch implements the timer form the last patch on the sco To test: 1 - Set SelfCheckTimout to 5 or something low for testing 2 - Go to the self checkout module 3 - Either sign in or confirm you have AutoSelfCheck user setup 4 - Observe the page reloads every 5 seocnds (or as you set above) 5 - Sign in as a patron 6 - Confirm on idle you are logged out to home page 7 - Sign off! Signed-off-by: David Nind --- .../bootstrap/en/modules/sco/sco-main.tt | 32 ++++++++++++------- opac/sco/sco-main.pl | 7 ---- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt index d2d87448b2..84c20c616b 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt @@ -55,6 +55,7 @@ [% END %] [% Asset.js('js/Gettext.js') | $raw %] [% Asset.js('js/i18n.js') | $raw %] +[% Asset.js('js/timeout.js') | $raw %]
@@ -328,7 +329,7 @@
- +
@@ -341,7 +342,7 @@
- +
@@ -401,11 +402,23 @@ history.replaceState(null, document.title, window.location.href); } } - var mainTimeout; - function sco_init() { - mainTimeout = setTimeout(function() { - location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout'; - }, [% SelfCheckTimeout | html %]); + document.addEventListener("DOMContentLoaded",function(){ + if ( document.querySelector('#sco_patron_login,#logout_form') ){ + login_timeout(); + } + }); + function login_timeout(){ + //NOTE: There can only be 1 sco_login_timer at a time + if ( ! window.sco_login_timer ){ + const idleTimeout = "[% Koha.Preference('SelfCheckTimeout') || 120 | html %]"; + const home_href = "/cgi-bin/koha/sco/sco-main.pl?op=logout"; + const sco_timer = new sc_timer({ + "idle_timeout": idleTimeout, + "redirect_url": home_href + }); + window.sco_login_timer = sco_timer; + sco_timer.start_timer(); + } } function dofocus() { // named function req'd for body onload event by some FF and IE7 security models // alert("dofocus called"); @@ -458,7 +471,6 @@ $(document).ready(function() { dofocus(); - [% IF ( patronid ) %]sco_init();[% END %] var dTables = $("#loanTable, #holdst, #finestable"); dTables.each(function(){ @@ -490,18 +502,16 @@ $("#logout_form").on("click", function(e){ e.preventDefault(e); - clearTimeout(mainTimeout); [% IF Koha.Preference('SelfCheckReceiptPrompt') %] var confirmStart = Date.now(); confirmModal("", _("Would you like to print a receipt?"), _("Print receipt and end session"), _("End session"), function(result) { - if ( result && (Date.now() - confirmStart) < [% SelfCheckTimeout | html %] ) { + if ( result && (Date.now() - confirmStart) < [% Koha.Preference('SelfCheckTimeout') | html %] ) { var win = window.open("/cgi-bin/koha/sco/printslip.pl?print=qslip"); location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout'; } else { location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout'; } }) - sco_init(); [% ELSE %] location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout'; [% END %] diff --git a/opac/sco/sco-main.pl b/opac/sco/sco-main.pl index 9ecae7c76c..e1cc93d802 100755 --- a/opac/sco/sco-main.pl +++ b/opac/sco/sco-main.pl @@ -74,13 +74,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -# Get the self checkout timeout preference, or use 120 seconds as a default -my $selfchecktimeout = 120000; -if ( C4::Context->preference('SelfCheckTimeout') ) { - $selfchecktimeout = C4::Context->preference('SelfCheckTimeout') * 1000; -} -$template->param( SelfCheckTimeout => $selfchecktimeout ); - # Checks policy laid out by SCOAllowCheckin, defaults to 'on' if preference is undefined my $allowselfcheckreturns = 1; if ( defined C4::Context->preference('SCOAllowCheckin') ) { -- 2.39.5