diff --git a/app/assets/javascripts/timeoutPopup.js b/app/assets/javascripts/timeoutPopup.js index 0807a0f3a..30f179031 100644 --- a/app/assets/javascripts/timeoutPopup.js +++ b/app/assets/javascripts/timeoutPopup.js @@ -1,15 +1,47 @@ -(function(global ) { +(function(global) { "use strict"; + hideTimerButtons(); - var cookie = window.GOVUK.getCookie('notify_admin_session'); + 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); - if (cookie) { - window.alert("Session will expire: Cookie Value" + cookie); - } else { - window.alert('Session has expired'); + document.getElementById("timerWarning").innerHTML = "Your session will " + + "expire in " + minutes + "m " + seconds + "s "; + showTimerButtons(); + document.getElementById("logOutTimer").addEventListener("click", logoutByUser); + document.getElementById("extendSessionTimer").addEventListener("click", extendSession); + if (difference === 0) { + clearInterval(x); + redirectToSignin(); + } + }, 1000); + }, 25 * 60 * 1000); + + function redirectToSignin() { + window.location.href = '/sign-in'; } - console.log(cookie); + function logoutByUser() { + window.location.href = '/sign-out'; + } + + function extendSession() { + window.location.reload(); + } + + function hideTimerButtons() { + document.getElementById("logOutTimer").style.display = 'none'; + document.getElementById("extendSessionTimer").style.display = 'none'; + } + + function showTimerButtons() { + document.getElementById("logOutTimer").style.display = 'block'; + document.getElementById("extendSessionTimer").style.display = 'block'; + } })(window); - diff --git a/app/templates/admin_template.html b/app/templates/admin_template.html index c6436380e..a3e4e7fe1 100644 --- a/app/templates/admin_template.html +++ b/app/templates/admin_template.html @@ -11,6 +11,13 @@ {% endblock %} {% block head %} + {% block sessionUserWarning %} +