Revert "Bug 36586: Define self-checkin timer using Javascript class"

This reverts commit ff403dcfb3.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit a827e5dbe3)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Lucas Gass 2025-07-10 14:35:30 +00:00 committed by Paul Derscheid
parent d58f2d4542
commit faf0af11d2
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
5 changed files with 44 additions and 78 deletions

View File

@ -189,7 +189,7 @@
</main>
<!-- / .main -->
[% # Help modal %]
[%# Help modal %]
<div id="helpModal" class="modal" tabindex="-1" role="dialog" aria-labelledby="helpModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
@ -222,7 +222,6 @@
[% INCLUDE 'opac-bottom.inc' %]
[% BLOCK jsinclude %]
[% Asset.js('js/timeout.js') | $raw %]
<script>
function mungeHistory() {
// prevent back button from allowing form resubmission
@ -273,7 +272,6 @@
$("#sci_barcodes_table").show();
$('#sci_checkin_button').show();
$('#sci_refresh_button').show();
login_timeout();
// Add barcode to the array
barcodes.push(barcode);
@ -293,24 +291,31 @@
dofocus();
});
document.addEventListener("DOMContentLoaded",function(){
if ( document.querySelector('#sci_finish_button,#sci_append_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
var idleTime = 0;
$(document).ready(function () {
//Increment the idle time counter every second
var idleInterval = setInterval(timerIncrement, 1000);
//Zero the idle timer on mouse movement.
$(this).mousemove(function (e) {
idleTime = 0;
});
window.sci_login_timer = sci_timer;
sci_timer.start_timer();
$(this).keypress(function (e) {
idleTime = 0;
});
});
function timerIncrement() {
if ( $("#sci_finish_button").is(":visible") || $("#sci_refresh_button").is(":visible") ) {
idleTime = idleTime + 1;
idleTimeout = [% refresh_timeout | html %];
if (idleTime >= idleTimeout ) {
location.href = '/cgi-bin/koha/sci/sci-main.pl';
}
}
}
}
function checkBarcodeInput() {
var inputField = document.getElementById("barcode_input");

View File

@ -55,7 +55,6 @@
[% END %]
[% Asset.js('js/Gettext.js') | $raw %]
[% Asset.js('js/i18n.js') | $raw %]
[% Asset.js('js/timeout.js') | $raw %]
</head>
<body id="sco_main" class="sco">
<div id="wrapper">
@ -339,7 +338,7 @@
<input type="password" id="patronpw" class="form-control" size="20" name="patronpw" autocomplete="off" />
</div>
<div class="col-md-12">
<button id="sco_patron_login" type="submit" class="btn btn-primary">Log in</button>
<button type="submit" class="btn btn-primary">Log in</button>
</div>
</div>
<!-- /.row -->
@ -352,7 +351,7 @@
<input type="text" id="patronid" class="form-control focus" size="20" name="patronid" autocomplete="off" />
</div>
<div class="col-md-12">
<button id="sco_patron_login" type="submit" class="btn btn-primary">Submit</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
<!-- /.row -->
@ -412,23 +411,11 @@
history.replaceState(null, document.title, window.location.href);
}
}
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();
}
var mainTimeout;
function sco_init() {
mainTimeout = setTimeout(function() {
location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout';
}, [% SelfCheckTimeout | html %]);
}
function dofocus() { // named function req'd for body onload event by some FF and IE7 security models
// alert("dofocus called");
@ -481,6 +468,7 @@
$(document).ready(function() {
dofocus();
[% IF ( patronid ) %]sco_init();[% END %]
var dTables = $("#loanTable, #holdst, #finestable");
dTables.each(function(){
@ -512,6 +500,7 @@
$("#logout_form").on("click", function(e){
e.preventDefault(e);
clearTimeout(mainTimeout);
[% IF Koha.Preference('SelfCheckReceiptPrompt') %]
confirmModal("", _("Would you like to print a receipt?"), _("Print receipt and end session"), _("End session"), function(result) {
if ( result ){

View File

@ -1,39 +0,0 @@
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;
}
}
}

View File

@ -102,4 +102,8 @@ 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 };

View File

@ -74,6 +74,13 @@ 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') ) {