Bugzilla – Attachment 175919 Details for
Bug 36586
Self-checkouts will get CSRF errors if left inactive for 8 hours
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36586: Define self-checkin timer using Javascript class
Bug-36586-Define-self-checkin-timer-using-Javascri.patch (text/plain), 4.11 KB, created by
David Cook
on 2024-12-24 00:07:37 UTC
(
hide
)
Description:
Bug 36586: Define self-checkin timer using Javascript class
Filename:
MIME Type:
Creator:
David Cook
Created:
2024-12-24 00:07:37 UTC
Size:
4.11 KB
patch
obsolete
>From 16bd8a7c66afd9a2366175b2c9c89573dddc2962 Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Tue, 24 Dec 2024 00:00:40 +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). >--- > .../bootstrap/en/modules/sci/sci-main.tt | 25 ++++++--- > koha-tmpl/opac-tmpl/bootstrap/js/timeout.js | 51 ++++++++++++------- > 2 files changed, 53 insertions(+), 23 deletions(-) > >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 7d9326c34c..5a6f02d776 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 >@@ -254,6 +254,7 @@ > $("#sci_barcodes_table").show(); > $('#sci_checkin_button').show(); > $('#sci_refresh_button').show(); >+ login_timeout(); > > // Add barcode to the array > barcodes.push(barcode); >@@ -273,12 +274,24 @@ > dofocus(); > }); > >- >- let idleTimeout = [% Koha.Preference('SelfCheckInTimeOut') || 120 %]; >- let refresh_button = $("#sci_refresh_button"); >- let finish_button = $("#sci_finish_button"); >- let home_href = "/cgi-bin/koha/sci/sci-main.pl"; >- >+ document.addEventListener("DOMContentLoaded",function(){ >+ if ( document.querySelector('#sci_finish_button') ){ >+ login_timeout(); >+ } >+ }); >+ function login_timeout(){ >+ //NOTE: There can only be 1 sci_login_timer at a time >+ if ( ! window.sci_login_timer ){ >+ const idleTimeout = "[% Koha.Preference('SelfCheckInTimeOut') || 120 | html %]"; >+ const home_href = "/cgi-bin/koha/sci/sci-main.pl"; >+ const sci_timer = new sc_timer({ >+ "idle_timeout": idleTimeout, >+ "redirect_url": home_href >+ }); >+ window.sci_login_timer = sci_timer; >+ sci_timer.start_timer(); >+ } >+ } > > function checkBarcodeInput() { > var inputField = document.getElementById("barcode_input"); >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js b/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js >index 40097dca92..cceb2ce1b3 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js >@@ -1,22 +1,39 @@ >-var idleTime = 0; >-$(document).ready(function () { >- //Increment the idle time counter every second >- var idleInterval = setInterval(timerIncrement, 1000); >+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; >+ } > >- //Zero the idle timer on mouse movement. >- $(this).mousemove(function (e) { >- idleTime = 0; >- }); >- $(this).keypress(function (e) { >- idleTime = 0; >- }); >-}); >+ start_timer() { >+ const self = this; >+ //Increment the idle time counter every 1 second >+ const idle_interval = setInterval(function(){self._timer_increment()},1000); > >-function timerIncrement() { >- if ( finish_button.is(":visible") || refresh_button.is(":visible") ) { >- idleTime = idleTime + 1; >- if (idleTime >= idleTimeout ) { >- location.href = home_href; >+ 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; > } > } >+ > } >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36586
:
175210
|
175239
| 175919