Index: portal-charon/charon/src/webapp/scripts/portalscripts.js =================================================================== --- portal-charon/charon/src/webapp/scripts/portalscripts.js (revision 49962) +++ portal-charon/charon/src/webapp/scripts/portalscripts.js (working copy) @@ -64,4 +64,77 @@ * * Version 2.1.1 */ -(function($){$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&/6.0/.test(navigator.userAgent)){s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n;},html='';return this.each(function(){if($('> iframe.bgiframe',this).length==0)this.insertBefore(document.createElement(html),this.firstChild);});}return this;};})(jQuery); \ No newline at end of file +(function($){$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&/6.0/.test(navigator.userAgent)){s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n;},html='';return this.each(function(){if($('> iframe.bgiframe',this).length==0)this.insertBefore(document.createElement(html),this.firstChild);});}return this;};})(jQuery); + + +//For SAK-13987 +var sessionId = document.cookie.replace(/^[^=]*=/, '').replace(/\..*$/, ''); +var sessionTimeOut; +jQuery(document).ready(function(){ + //TODO - find a better method for detecting logged in + // note a session exists whether the user is logged in or no + if (jQuery('div#siteNav').get(0)) { //if Logged in + poll_session_data(); + } +}); + +var poll_session_data = function() { + jQuery.ajax({ + url: "/direct/session/" + sessionId + ".json?auto=true", //auto=true makes it not refresh the session lastaccessedtime + cache: false, + dataType: "json", + success: function(data){ + //get the maxInactiveInterval in the same ms + data.session.maxInactiveInterval = data.session.maxInactiveInterval * 1000; + if(data.session.active && data.session.lastAccessedTime + data.session.maxInactiveInterval + > data.session.rightNow) { + //User is logged in, so now determine how much time is left + var remaining = data.session.lastAccessedTime + data.session.maxInactiveInterval - data.session.rightNow; + //If time remaining is less than 5 minutes, show/update dialog box + //TODO - make the 5 minutes a sakai.properties to determine customized timeout interval + if (remaining < 5 * 60 * 1000){ + //we are within 5 min now - show popup + min = Math.round(remaining / (1000 * 60)); + show_timeout_alert(min); + clearTimeout(sessionTimeOut); + sessionTimeOut = setTimeout("poll_session_data()", 1000 * 60); + } else { + //more than 5 min away + clearTimeout(sessionTimeOut); + sessionTimeOut = setTimeout("poll_session_data()", (remaining - 5*60*1000)); + } + + } else { + //the timeout length has occurred, but there is a slight delay, do this until you get a 404 + sessionTimeOut = setTimeout("poll_session_data()", 1000 * 10); + } + }, + error: function(XMLHttpRequest, status, error){ + if (XMLHttpRequest.status == 404){ + //user is not logged in + location.href="/portal/"; + } + } + }); +} + +function keep_session_alive(){ + removeDHTMLMask(); + jQuery("#timeout_alert_body").remove(); + jQuery.get("/portal/"); +} + +function show_timeout_alert(min) { + if (!jQuery("#portalMask").get(0)){ + createDHTMLMask(); + jQuery("#portalMask").css("z-index", 10000); + } + if (jQuery("#timeout_alert_body").get(0)) { + //its there, just update the min + jQuery("#timeout_alert_body span").html(min); + } else { + //build up markup... this is an example + //TODO - make this internationalizable + jQuery("body").append("
Your session will time out in: " + min + " minute" + (min > 1 ? "s" : "") + "
"); + } +}