I just wanted to chime in and post my solution using jQuery and jQuery UI.
It basically sets a call for the showDialog javascript function to run after the `time` variable runs out (1.74 million ms is 29 minutes). When the showDialog() function is called it creates a jquery ui dialog that displays nicely. A second timer starts as a countdown for 60 seconds and replaces the text in the #timeout-countdown span every second. If the user click `Yes, Keep Working` then an ajax callback to `keepWorking.a5w` is called. The contents of that file are insignificant, we really just need to ping the WAS to prevent session timeout. After the callback the dialog is closed, and all the timers are reset. If the user clicks `No, Logoff` then the user is forwarded to `logout.a5w` which includes session deletion and the xbasic logout function (also some sql logging stuff). This also happens when the #timeout-countdown time reaches 0.
FYI, the WAS session timeout needs to be GREATER than this timeout so that when a user clicks `Yes` or `No` the session is actually still alive. One single second should suffice, but I think my WAS timeout is like 5 minutes longer than the javascript timeout. My thinking for this is that the WAS should NEVER timeout a session itself. I ALWAYS want my logoff.a5w page to be called so I can terminate a session properly and cleanly. I've had quite a few complaints that they come back to the application, type up a bunch of stuff, click save only to find out their session had timed out and they lost all they typed.
ALSO, I've already set jQuery to be in no conflict mode with this code
Code:
var $j = jQuery.noConflict(true);
Code:
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/redmond/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<!-- Timeout Dialog -->
<div id="timeout" style="display:none;" title="Your session is about to expire!">
<p>You will be logged off in <span id="timeout-countdown">60</span> seconds.</p>
<p>Would you like to keep working?</p>
</div>
<script type="text/javascript">
//Timeout dialog
// time = timeout time in milliseconds. 1.74m is 29 minutes
var time = 1740000;
// countdown = time in seconds for the session timeout dialog to show before action is taken.
var timeout = 60;
// logout = the inital set of the showDialog function to show the jquery ui dialog.
var logout = setInterval( function(){showDialog()} , time );
function showDialog(){
$j('#timeout').dialog({
autoOpen:true,
width: 500,
modal:true,
closeOnEscape:false,
draggable:false,
resizable:false,
buttons: {
'Yes, Keep Working': function(){
// resume once clicked
$j.ajax({
url: "keepAlive.a5w",
cache: false,
success: function(){
//clear and reset the timers
$j('#timeout').dialog('close');
$j('#timeout-countdown').text(timeout);
clearInterval(logout);
clearInterval(timer);
logout = setInterval( function(){showDialog()} , time );
}
});
},
'No, Logoff': function(){
window.location = "logout.a5w";
}
}
});
// this will countdown starting from the number written in the #timeout-countdown span.
var timer = setInterval(function() {
var countdown = $j('#timeout-countdown').text() || 0;
$j('#timeout-countdown').text(--countdown);
if (countdown == 0){
//timeout! timer hit zero, log the user out.
window.location = "logout.a5w";
clearInterval(timer);
}
}, 1000);
}
</script>
The positive of using this code instead of Carol's code above is that we don't have to change pages to keep our session active.
Bookmarks