prevent reviving the session if the page is being reloaded after signing a task [SCI-10515]

This commit is contained in:
sboursen-scinote 2024-04-10 01:21:35 +02:00
parent 9c559a0c65
commit 271702e2a8

View file

@ -36,7 +36,7 @@
timeoutID = setTimeout(functionCallback, timeoutTime); timeoutID = setTimeout(functionCallback, timeoutTime);
} }
function toogleDocumentTitle(timeString = null) { function toggleDocumentTitle(timeString = null) {
var sleepEmoticon = String.fromCodePoint(0x1F62A); var sleepEmoticon = String.fromCodePoint(0x1F62A);
var originalTitle = document.title.split(sleepEmoticon).pop().trim(); var originalTitle = document.title.split(sleepEmoticon).pop().trim();
@ -70,21 +70,21 @@
function reviveSession() { function reviveSession() {
$.post($('meta[name=\'revive-url\']').attr('content')); $.post($('meta[name=\'revive-url\']').attr('content'));
toogleDocumentTitle(); toggleDocumentTitle();
window.localStorage.removeItem('sessionEnd'); window.localStorage.removeItem('sessionEnd');
setSessionTimeout(initializeSessionCountdown, oneSecondTimeout); setSessionTimeout(initializeSessionCountdown, oneSecondTimeout);
} }
function initializeSessionReviveCallbacks() { function initializeSessionReviveCallbacks() {
$('#session-expire').modal().off('hide.bs.modal').on('hide.bs.modal', function() { $('#session-expire').modal().off('hide.bs.modal').on('hide.bs.modal', function() {
if (sessionExpireIn() > 0) { if (sessionExpireIn() > 0 && sessionExpireIn() < expireLimit) {
reviveSession(); reviveSession();
} }
}); });
// for manual page reload // for manual page reload
$(window).off('beforeunload').on('beforeunload', function() { $(window).off('beforeunload').on('beforeunload', function() {
if (sessionExpireIn() > 0) { if (sessionExpireIn() > 0 && sessionExpireIn() < expireLimit) {
reviveSession(); reviveSession();
} }
}); });
@ -98,7 +98,7 @@
initializeSessionCountdown(); initializeSessionCountdown();
} else if (expireIn > 0 && expireIn <= expireLimit) { } else if (expireIn > 0 && expireIn <= expireLimit) {
timeString = newTimerStr(expireIn / 1000); timeString = newTimerStr(expireIn / 1000);
toogleDocumentTitle(timeString); toggleDocumentTitle(timeString);
$('.expiring').text(I18n.t('devise.sessions.expire_modal.session_end_in.header', { time: timeString })); $('.expiring').text(I18n.t('devise.sessions.expire_modal.session_end_in.header', { time: timeString }));
if (!$('#session-expire').hasClass('in')) { if (!$('#session-expire').hasClass('in')) {
@ -107,7 +107,7 @@
setSessionTimeout(sessionCountdown, oneSecondTimeout); setSessionTimeout(sessionCountdown, oneSecondTimeout);
} else if (expireIn <= 0) { } else if (expireIn <= 0) {
toogleDocumentTitle(); toggleDocumentTitle();
$('#session-expire').modal('hide'); $('#session-expire').modal('hide');
$('#session-finished').modal(); $('#session-finished').modal();
} }
@ -130,7 +130,7 @@
} }
setSessionTimeout(initializeSessionCountdown, oneSecondTimeout); setSessionTimeout(initializeSessionCountdown, oneSecondTimeout);
} else if (expireOn && !event.originalEvent.newValue) { } else if (expireOn && !event.originalEvent.newValue) {
toogleDocumentTitle(); toggleDocumentTitle();
} }
expireOn = event.originalEvent.newValue; expireOn = event.originalEvent.newValue;