Files
notifications-admin/app/assets/javascripts/timeoutPopup.js

46 lines
1.4 KiB
JavaScript
Raw Normal View History

(function(global) {
2023-08-16 10:55:24 -06:00
"use strict";
const sessionTimer = document.getElementById("sessionTimer");
2023-08-16 10:55:24 -06:00
setTimeout(function() {
var timeTillSessionEnd = new Date().getTime() + (5 * 60 * 1000);
var x = setInterval(function() {
var now = new Date().getTime();
var difference = timeTillSessionEnd - now;
var minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((difference % (1000 * 60)) / 1000);
2023-09-12 15:17:06 -04:00
document.getElementById("timeLeft").innerHTML = + minutes + "m " + seconds + "s";
2023-09-12 11:30:27 -06:00
showTimer();
document.getElementById("logOutTimer").addEventListener("click", logoutByUser);
document.getElementById("extendSessionTimer").addEventListener("click", extendSession);
2023-09-12 11:30:27 -06:00
if (difference < 0) {
clearInterval(x);
2023-09-12 11:30:27 -06:00
closeTimer();
redirectToSignin();
}
}, 1000);
2023-09-12 11:30:27 -06:00
}, 60 * 1000);
function redirectToSignin() {
window.location.href = '/sign-in';
2023-08-16 10:55:24 -06:00
}
function logoutByUser() {
window.location.href = '/sign-out';
}
2023-08-16 10:55:24 -06:00
function extendSession() {
window.location.reload();
}
2023-08-16 10:55:24 -06:00
2023-09-12 11:30:27 -06:00
function showTimer() {
sessionTimer.showModal();
}
2023-09-12 11:30:27 -06:00
function closeTimer() {
sessionTimer.close();
}
})(window);