// timeoutFrame.js // Uses a to show user a timeout warning. // It allows the user to click a button to refresh. // $Id: timeoutFrame.js,v 1.8 2008/09/29 21:01:55 bnash Exp $ // -------------------------------------------------------------------------------- // Timeout functions // -------------------------------------------------------------------------------- //default to 60 min var sessionTime = 60; var minuteTime = 1; //minutes to ping the server var pingTime = (minuteTime * 60000); // in milliseconds if(typeof JS_SESSION_TIMEOUT != 'undefined'){ sessionTime = JS_SESSION_TIMEOUT - 5; // session warning to 5 minutes less than server side } var logOutTime = 5;// logout time set to 5 minutes from session timeout warning var sessionTimeout = null; var logoffTimeout = null; /* * Bind to a global on success event for ajax calls. */ $(document).bind("ajaxSuccess", function() { if (sessionTimeout) { clearTimeout(sessionTimeout); } else { setSessionTimeout(); } }); // Call by default setSessionTimeout(); function setSessionTimeout() { sessionTimeout = setInterval("showTimeoutWarning()", sessionTime * 60000); } /* * Called when the timeout has reached its limit. */ function showTimeoutWarning() { logoffTimeout = setInterval("doLogOff()", logOutTime * 60000);// 4*60*1000 $('#timeOutModal').modal({ backdrop : 'static', }); $('#continueSessionButton').click(function() { pingSession(); }); } /* *Called when the time has expired on the user to keep their session alive. */ function doLogOff() { $('#timeOutModal').modal('hide'); $('#logOutModal').modal({ backdrop : 'static', }); setTimeout('window.location = "/Login/logout";', 5000); } $(function(){ var lastUpdate = 0; setInterval(function(){ if(new Date().getTime() - lastUpdate < pingTime){ pingSession(); } }, pingTime); $(document).keydown(function(){ lastUpdate = new Date().getTime(); }); }); //document.onkeypress = function (e) { //each keypress will keep the session going. // e = e || window.event; // pingSession(); //}; /* * Pings a controller to keep the session alive. */ function pingSession() { $.ajax({ type : 'GET', url : 'pingController', data : ({ "pingParam" : "Session Pinged" }), success : function(data) { clearTimeout(logoffTimeout); setSessionTimeout(); }, failure : function() { alert("ajax call failed"); } }); }