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

This reverts commit b5bc9cf343.
This commit is contained in:
Fridolin Somers 2025-07-31 14:29:37 +02:00
parent 11b58bc552
commit 46abe2fafb
No known key found for this signature in database
GPG Key ID: 9A8E73E2A8B96537
5 changed files with 60 additions and 94 deletions

View File

@ -202,7 +202,6 @@
[% INCLUDE 'opac-bottom.inc' %]
[% BLOCK jsinclude %]
[% Asset.js('js/timeout.js') | $raw %]
<script>
function mungeHistory() {
@ -254,7 +253,6 @@
$("#sci_barcodes_table").show();
$('#sci_checkin_button').show();
$('#sci_refresh_button').show();
login_timeout();
// Add barcode to the array
barcodes.push(barcode);
@ -274,24 +272,31 @@
dofocus();
});
document.addEventListener("DOMContentLoaded",function(){
if ( document.querySelector('#sci_finish_button,#sci_append_button') ){
login_timeout();
}
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;
});
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
$(this).keypress(function (e) {
idleTime = 0;
});
window.sci_login_timer = sci_timer;
sci_timer.start_timer();
});
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

@ -42,7 +42,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">
[% INCLUDE 'masthead-sco.inc' %]
@ -490,7 +489,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 -->
[% ELSE %]
@ -502,7 +501,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 -->
[% END %]
@ -528,43 +527,31 @@
</div> <!-- / .main -->
<span id="audio-alert"></span>
[% INCLUDE 'opac-bottom.inc' %]
[% BLOCK jsinclude %]
[% INCLUDE 'datatables.inc' %]
<script>
function mungeHistory() {
// prevent back button from allowing form resubmission
if (history && history.pushState) {
history.replaceState(null, document.title, window.location.href);
}
[% INCLUDE 'opac-bottom.inc' %]
[% BLOCK jsinclude %]
[% INCLUDE 'datatables.inc' %]
<script>
function mungeHistory() {
// prevent back button from allowing form resubmission
if (history && history.pushState) {
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();
}
}
function dofocus() { // named function req'd for body onload event by some FF and IE7 security models
// alert("dofocus called");
$(".focus:last").select();
}
var slip_re = /slip/;
function printx_window(print_type) {
var handler = print_type.match(slip_re) ? "printslip" : "moremember";
}
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");
$(".focus:last").select();
}
var slip_re = /slip/;
function printx_window(print_type) {
var handler = print_type.match(slip_re) ? "printslip" : "moremember";
return false;
return false;
}
function checkout_confirm(patronid) {
var barcode = $("#barcode").val();
@ -607,6 +594,7 @@
$(document).ready(function() {
dofocus();
[% IF ( patronid ) %]sco_init();[% END %]
var dTables = $("#loanTable, #holdst, #finestable");
dTables.each(function(){
@ -640,6 +628,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

@ -105,4 +105,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') ) {
@ -141,7 +148,7 @@ my $confirm_required = 0;
my $return_only = 0;
my $batch_checkouts_allowed;
if ($patron) {
if ( $patron ) {
my @batch_category_codes = split ',', C4::Context->preference('SCOBatchCheckoutsValidCategories');
my $categorycode = $patron->categorycode;
if ( $categorycode && grep { $_ eq $categorycode } @batch_category_codes ) {