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!
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
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 <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Bug 36586: Fix tidy
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
ee32b5aa7b
commit
ff403dcfb3
|
|
@ -189,7 +189,7 @@
|
|||
</div>
|
||||
<!-- / .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,6 +222,7 @@
|
|||
|
||||
[% INCLUDE 'opac-bottom.inc' %]
|
||||
[% BLOCK jsinclude %]
|
||||
[% Asset.js('js/timeout.js') | $raw %]
|
||||
<script>
|
||||
function mungeHistory() {
|
||||
// prevent back button from allowing form resubmission
|
||||
|
|
@ -272,6 +273,7 @@
|
|||
$("#sci_barcodes_table").show();
|
||||
$('#sci_checkin_button').show();
|
||||
$('#sci_refresh_button').show();
|
||||
login_timeout();
|
||||
|
||||
// Add barcode to the array
|
||||
barcodes.push(barcode);
|
||||
|
|
@ -291,31 +293,24 @@
|
|||
dofocus();
|
||||
});
|
||||
|
||||
|
||||
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;
|
||||
});
|
||||
$(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';
|
||||
}
|
||||
}
|
||||
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
|
||||
});
|
||||
window.sci_login_timer = sci_timer;
|
||||
sci_timer.start_timer();
|
||||
}
|
||||
}
|
||||
|
||||
function checkBarcodeInput() {
|
||||
var inputField = document.getElementById("barcode_input");
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@
|
|||
[% 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">
|
||||
|
|
@ -328,7 +329,7 @@
|
|||
<input type="password" id="patronpw" class="form-control" size="20" name="patronpw" autocomplete="off" />
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<button type="submit" class="btn btn-primary">Log in</button>
|
||||
<button id="sco_patron_login" type="submit" class="btn btn-primary">Log in</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.row -->
|
||||
|
|
@ -341,7 +342,7 @@
|
|||
<input type="text" id="patronid" class="form-control focus" size="20" name="patronid" autocomplete="off" />
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<button id="sco_patron_login" type="submit" class="btn btn-primary">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.row -->
|
||||
|
|
@ -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 %]
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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 };
|
||||
|
|
|
|||
|
|
@ -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') ) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue