]> git.datanom.net - qtadmin.git/blame - js/timer.js
Fix bug in session handler
[qtadmin.git] / js / timer.js
CommitLineData
5c7b972e 1/* vim: set ts=4 tw=4 sw=4 noet: */
46a4a959 2var timerRef=setInterval(function(){myTimer()}, 1000);
6df4b805 3var timeStart = new Date().getTime() + timeout;
b2103a3c 4var last = -1;
6df4b805
MR
5
6function myTimer() {
b95d1cdb
MR
7 var elapsed = new Date().getTime();
8 var expire = timeStart - elapsed;
9 var timeLeft = Math.round(((expire % 86400000) % 3600000) / 60000);
6df4b805 10
c5c78f09 11 if (timeLeft < 0) {
b95d1cdb 12 clearInterval(timerRef);
59c941ce 13 console.log('Session expired, reload page');
b2103a3c 14 last = -1;
7ff23fee 15 location.reload();
4dc7954a 16 } else if (timeLeft == 1) {
b2103a3c
MR
17 if (timeLeft < last || last == -1) {
18 last = timeLeft;
c5c78f09 19 timeLeft = '< ' + timeLeft + ' min';
e0ed91d7 20 console.log('Session soon to expire');
b2103a3c
MR
21 document.getElementById("time").style.background = "red";
22 document.getElementById("timer").innerHTML = timeLeft;
23 }
59c941ce 24 } else {
a0224728 25 if ((timeLeft < last && timeLeft > 0) || last == -1) {
59c941ce
MR
26 last = timeLeft;
27 console.log('Session valid < ' + timeLeft);
28 timeLeft = '< ' + timeLeft + ' min';
95176a69 29 document.getElementById("timer").innerHTML = timeLeft;
59c941ce 30 }
b95d1cdb 31 }
6df4b805 32}
This page took 0.05549 seconds and 5 git commands to generate.