/// <reference name="MicrosoftAjax.js"/>
Type.registerNamespace("SessionTimeoutTool");
SessionTimeoutTool.TimeoutWatcherBehavior = function(element) {
SessionTimeoutTool.TimeoutWatcherBehavior.initializeBase(this, [element]);
this._interval = 1000;
this._message = null;
this._timeoutMode = null;
this._timer = null;
this._redirectPage = null;
this._customHandlerJScript = null;
this._fromExtender = false;
this._popupBehavior = null;
}
SessionTimeoutTool.TimeoutWatcherBehavior.prototype = {
initialize: function() {
SessionTimeoutTool.TimeoutWatcherBehavior.callBaseMethod(this, 'initialize');
//create timer
this._timer = new Sys.Timer();
//create timer handler
tickHandlerDelegate = Function.createDelegate(this, this.tickHandler);
this._timer.add_tick(tickHandlerDelegate);
//create onload handler
setTime = Function.createDelegate(this,this.setTimer);
Sys.Application.add_load(setTime);
if(this._timeoutMode == SessionTimeoutTool.Mode.PopupMessage && this._fromExtender == true)
{
//create popup behavior
this._popupBehavior = $create(AjaxControlToolkit.PopupBehavior
, {"id":this.get_id()+'PopupBehavior'}
, null
, null
, this.get_element());
}
},
setTimer:function()
{
if(this._timer)
{
this._timer.set_enabled(false);
if(this._timeoutMode == SessionTimeoutTool.Mode.ExtendTime)
this._timer.set_interval(this.get_interval()- 45000);
else
this._timer.set_interval(this.get_interval());
this._timer.set_enabled(true);
}
},
tickHandler: function(){
if(this._timeoutMode == SessionTimeoutTool.Mode.PageRedirect)
{
this.pageRedirect();
return;
}
if(this._timeoutMode == SessionTimeoutTool.Mode.PopupMessage)
{
this.popup();
return;
}
if(this._timeoutMode == SessionTimeoutTool.Mode.ExtendTime)
{
this.extendTime();
return;
}
if(this._timeoutMode == SessionTimeoutTool.Mode.CustomHandler)
{
this.customHandler();
return;
}
},
pageRedirect: function(){
window.location = this._redirectPage;
},
popup: function(){
this._timer._stopTimer();
if(this._fromExtender == true)
{
this._popupBehavior.show();
return;
}
if(this._message == null)
{
alert("The session has expired.");
}
else
{
alert(this._message);
}
},
extendTime: function(){
this.callWebService();
},
callWebService: function()
{
var webRequest = Sys.Net.WebServiceProxy.invoke(
"SessionTimeoutTool.asmx" //path
, "ExtendSessionTimeout" //methodName
, false //useHttpGet
, null //parameters
, this.succeededCallback
, this.failedCallback
, "User Context");//userContext
},
succeededCallback: function(result, eventArgs)
{
if(result !== null)
alert(result);
},
failedCallback: function(error)
{
alert(error);
},
customHandler: function(){
this._timer._stopTimer();
eval(this.get_customHandlerJScript());
},
get_interval: function() {
return this._interval;
},
set_interval: function(value) {
this._interval = value;
},
get_message: function()
{
return this._message;
},
set_message: function(value)
{
this._message = value;
},
get_timeoutMode: function()
{
return this._timeoutMode;
},
set_timeoutMode: function(value)
{
this._timeoutMode = value;
},
get_redirectPage: function()
{
return this._redirectPage;
},
set_redirectPage: function(value)
{
this._redirectPage = value;
},
get_customHandlerJScript:function()
{
return this._customHandlerJScript;
},
set_customHandlerJScript:function(value)
{
this._customHandlerJScript = value;
},
get_fromExtender: function()
{
return this._fromExtender;
},
set_fromExtender: function(value)
{
this._fromExtender = value;
},
dispose: function() {
SessionTimeoutTool.TimeoutWatcherBehavior.callBaseMethod(this
, 'dispose');
if (this._timer) {
this._timer.dispose();
this._timer = null;
}
$clearHandlers;
}
}
SessionTimeoutTool.TimeoutWatcherBehavior.registerClass('SessionTimeoutTool.TimeoutWatcherBehavior', Sys.UI.Control);
SessionTimeoutTool.Mode = function(){};
SessionTimeoutTool.Mode.prototype =
{
PageRedirect: 0,
PopupMessage: 1,
ExtendTime: 2,
CustomHandler: 3
}
SessionTimeoutTool.Mode.registerEnum("SessionTimeoutTool.Mode");
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();