From cbf3f18bf1f9f827566ee7def73ec9733bfe5da2 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 4 Dec 2024 21:10:55 +0000 Subject: [PATCH] Bug 36586: Define self-checkin timer using Javascript class This patch rewrites the self-checkin timer code to be defined in a Javascript class which is then instantiated in once in sci-main.pl depending on certain conditions (ie a barcode has been entered, or an item has been checked in by barcode). To test: 1 - Set SelfCheckinTimeout to a small value like 5 2 - Go to the self checkin: http://localhost:8080/cgi-bin/koha/sci/sci-main.pl 3 - Sign in as the SCI user 4 - Watch the page, it should refresh every 5 seconds 5 - Confirm that moving the mouse/typing prevents the reset 6 - Check in an item 7 - Wait and confirm reload of main page happens when idle 8 - Confirm mouse/typing prevents refresh 9 - Sign off! --- .../bootstrap/en/modules/sci/sci-main.tt | 478 +++++++++--------- koha-tmpl/opac-tmpl/bootstrap/js/timeout.js | 39 ++ opac/sci/sci-main.pl | 4 - 3 files changed, 269 insertions(+), 252 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/js/timeout.js diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt index 7bfa4dd8c31..1572315c32e 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt @@ -25,11 +25,10 @@ [% SET SelfCheckInMainUserBlock = AdditionalContents.get( location => "SelfCheckInMainUserBlock", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %] [% INCLUDE 'doc-head-open.inc' %] [% SET OpacLangSelectorMode = Koha.Preference('OpacLangSelectorMode') %] -Self check-in › [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha[% END %] +Self check-in › [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha [% END %] - - + [% IF ( Koha.Preference('OpacFavicon') ) %] @@ -44,28 +43,16 @@ [% ELSE %] [% Asset.css("css/sco.css") | $raw %] [% END %] -[% IF ( Koha.Preference('OPACUserCSS') ) %] - - - -[% END %] +[% IF ( Koha.Preference('OPACUserCSS') ) %][% END %] [% IF Branches.GetBranchSpecificCSS( Branches.GetLoggedInBranchcode() || default_branch) %] - - -[% END %] -[% IF ( Koha.Preference('SelfCheckInUserCSS') ) %] - - - [% END %] +[% IF ( Koha.Preference('SelfCheckInUserCSS') ) %][% END %] [% IF lang && lang != 'en' %] [% Asset.js(lang _ '/js/locale_data.js') | $raw %] @@ -74,130 +61,127 @@ [% Asset.js('js/i18n.js') | $raw %] -[% INCLUDE 'masthead-sci.inc' %] - -
-
-
-
-
-

[% LibraryName | html %] Self check-in

-
- - [% IF ( nopermission ) %] - [%# This is what is displayed if user doesn't have permission %] -
-

Access denied

-

Sorry, this self check-in station has lost authentication. Please contact the administrator to resolve this problem.

-
- [% ELSIF ( different_ip ) %] - [%# This is what is displayed if user doesn't have permission %] -
-

Session lost

-

You are accessing self check-in from a different IP address! Please log in again.

+ [% INCLUDE 'masthead-sci.inc' %] + +
+
+
+
+
+

[% LibraryName | html %] Self check-in

- [% ELSIF ( checkins ) %] - [%# We have results from a check-in attempt %] -
- [% IF ( success && success.size > 0 || errors && errors.size > 0 ) %] - - - - - - - - [% FOREACH success_line IN success %] - - - - - [% END %] - [% FOREACH error IN errors %] - - - - - [% END %] - - -
- Finish -
- [% ELSE %] -
-

Your request included no check-ins.

-
- [% END %] -
- [% ELSE %] - [%# Prompt for barcodes %] -
-
- [% INCLUDE 'csrf-token.inc' %] - Scan -
-
- -
-
- -
-
- + + [% IF ( nopermission ) %] + [%# This is what is displayed if user doesn't have permission %] +
+

Access denied

+

Sorry, this self check-in station has lost authentication. Please contact the administrator to resolve this problem.

+
+ [% ELSIF ( different_ip ) %] + [%# This is what is displayed if user doesn't have permission %] +
+

Session lost

+

You are accessing self check-in from a different IP address! Please log in again.

+
+ [% ELSIF ( checkins ) %] + [%# We have results from a check-in attempt %] +
+ [% IF ( success && success.size > 0 || errors && errors.size > 0 ) %] + + + + + + + + [% FOREACH success_line IN success %] + + + + + [% END %] + [% FOREACH error IN errors %] + + + + + [% END %] + + +
+ Finish +
+ [% ELSE %] +
+

Your request included no check-ins.

-
- -
-
-
- - - - - - - - + [% END %] +
+ [% ELSE %] + [%# Prompt for barcodes %] +
+ + [% INCLUDE 'csrf-token.inc' %] + Scan +
+
+
- - -
- - +
+
- -
- -
- - - -
- - [% END # /IF ( nopermission ) %] - - [% IF ( SelfCheckInMainUserBlock ) %] -
[% PROCESS koha_news_block news => SelfCheckInMainUserBlock %]
- [% END %] -
- -
- -
- -
- - -[%# Help modal %] +
+ +
+
+
+
+
+ + + + + + + + +
+ +
+ + +
+
+
+ +
+ [% END # /IF ( nopermission ) %] + + [% IF ( SelfCheckInMainUserBlock ) %] +
+ [% PROCESS koha_news_block news => SelfCheckInMainUserBlock %] +
+ [% END %] +
+
+
+ +
+ +[% # Help modal %] - -
- -
- +
+
+ [% INCLUDE 'opac-bottom.inc' %] [% BLOCK jsinclude %] +[% Asset.js('js/timeout.js') | $raw %] + [% IF ( Koha.Preference('SelfCheckInUserJS') ) %] - + [% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js b/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js new file mode 100644 index 00000000000..6c508d14c07 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js @@ -0,0 +1,39 @@ +class sc_timer { + constructor(args) { + const idle_timeout = args["idle_timeout"]; + const redirect_url = args["redirect_url"]; + if (idle_timeout) { + this.idle_timeout = idle_timeout; + } + if (redirect_url) { + this.redirect_url = redirect_url; + } + this.idle_time = 0; + } + + start_timer() { + const self = this; + //Increment the idle time counter every 1 second + const idle_interval = setInterval(function () { + self._timer_increment(); + }, 1000); + + document.addEventListener("mousemove", function () { + self.reset_timer(); + }); + document.addEventListener("keypress", function () { + self.reset_timer(); + }); + } + + reset_timer() { + this.idle_time = 0; + } + + _timer_increment() { + this.idle_time++; + if (this.idle_time >= this.idle_timeout) { + location.href = this.redirect_url; + } + } +} diff --git a/opac/sci/sci-main.pl b/opac/sci/sci-main.pl index 34d433a53fc..d254347b5be 100755 --- a/opac/sci/sci-main.pl +++ b/opac/sci/sci-main.pl @@ -102,8 +102,4 @@ if ( $op eq 'cud-check_in' ) { $template->param( success => \@success, errors => \@errors, checkins => 1 ); } -# Make sure timeout has a reasonable value -my $timeout = C4::Context->preference('SelfCheckInTimeout') || 120; -$template->param( refresh_timeout => $timeout ); - output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 }; -- 2.39.5