2007-11-11 23:59:29 +08:00
|
|
|
/*
|
|
|
|
* MooTools Extension script to support custom extensions to mootools
|
|
|
|
*/
|
2009-10-15 01:38:13 +08:00
|
|
|
var zmMooToolsVersion = '1.2.3';
|
2007-11-11 23:59:29 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Firstly, lets check that mootools has been included and thus is present
|
|
|
|
*/
|
|
|
|
if ( typeof(MooTools) == "undefined" )
|
|
|
|
{
|
|
|
|
alert( "MooTools not found! Please download from\nhttp://mootools.net and install in ZoneMinder web root." );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//console.log( "Got MooTools version "+MooTools.version );
|
|
|
|
|
|
|
|
/* Version check */
|
|
|
|
if ( MooTools.version < zmMooToolsVersion )
|
|
|
|
{
|
|
|
|
alert( "MooTools version "+MooTools.version+" found.\nVersion "+zmMooToolsVersion+" required, please upgrade." );
|
|
|
|
}
|
|
|
|
|
2009-10-17 01:11:29 +08:00
|
|
|
var requestTimeoutCount = 0;
|
|
|
|
var debugRequestTimeouts = false;
|
2007-11-11 23:59:29 +08:00
|
|
|
/*
|
2009-10-15 01:38:13 +08:00
|
|
|
* Ajax class extention to allow for request timeouts
|
2007-11-11 23:59:29 +08:00
|
|
|
*/
|
2009-10-15 01:38:13 +08:00
|
|
|
Request = Class.refactor(Request, {
|
|
|
|
|
|
|
|
options: { /*
|
|
|
|
onTimeout: $empty, */
|
|
|
|
timeout: 0,
|
|
|
|
},
|
|
|
|
|
2009-04-05 05:59:52 +08:00
|
|
|
send: function( data )
|
2007-11-11 23:59:29 +08:00
|
|
|
{
|
|
|
|
if ( this.options.timeout )
|
|
|
|
{
|
|
|
|
if ( this.timeoutTimer )
|
|
|
|
this.removeTimer();
|
2009-10-15 01:38:13 +08:00
|
|
|
this.timeoutTimer = this.onTimeout.delay( this.options.timeout, this );
|
2009-10-17 01:11:29 +08:00
|
|
|
if ( debugRequestTimeouts )
|
|
|
|
console.log( "Setting timer "+this.timeoutTimer+", "+data+", "+requestTimeoutCount+" running" );
|
|
|
|
requestTimeoutCount++;
|
2007-11-11 23:59:29 +08:00
|
|
|
this.addEvent( 'onComplete', this.removeTimer );
|
|
|
|
}
|
2009-10-15 01:38:13 +08:00
|
|
|
this.previous( data );
|
2009-04-03 20:07:45 +08:00
|
|
|
return( this );
|
2007-11-11 23:59:29 +08:00
|
|
|
},
|
2009-10-15 01:38:13 +08:00
|
|
|
|
2009-10-17 01:11:29 +08:00
|
|
|
cancel: function()
|
|
|
|
{
|
|
|
|
if ( debugRequestTimeouts )
|
|
|
|
console.log( "Cancelling timer "+this.timeoutTimer );
|
|
|
|
if ( debugRequestTimeouts )
|
|
|
|
console.log( "Running "+this.running );
|
|
|
|
this.previous();
|
|
|
|
this.removeTimer();
|
|
|
|
return( this );
|
|
|
|
},
|
|
|
|
|
2009-10-15 01:38:13 +08:00
|
|
|
timeout: function()
|
|
|
|
{
|
|
|
|
this.onTimeout();
|
2009-10-17 01:11:29 +08:00
|
|
|
return( this );
|
2009-10-15 01:38:13 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
onTimeout: function ()
|
2007-11-11 23:59:29 +08:00
|
|
|
{
|
2009-10-17 01:11:29 +08:00
|
|
|
if ( debugRequestTimeouts )
|
|
|
|
console.log( "Timer "+this.timeoutTimer+" timed out" );
|
2009-04-05 05:35:42 +08:00
|
|
|
this.cancel();
|
2009-10-15 01:38:13 +08:00
|
|
|
this.fireEvent('complete').fireEvent('failure').fireEvent('timeout');
|
2009-10-17 01:11:29 +08:00
|
|
|
return( this );
|
2007-11-11 23:59:29 +08:00
|
|
|
},
|
2009-10-15 01:38:13 +08:00
|
|
|
|
2009-04-05 05:59:52 +08:00
|
|
|
removeTimer: function()
|
2007-11-11 23:59:29 +08:00
|
|
|
{
|
2009-10-17 01:11:29 +08:00
|
|
|
if ( this.timeoutTimer )
|
|
|
|
{
|
|
|
|
requestTimeoutCount--;
|
|
|
|
if ( debugRequestTimeouts )
|
|
|
|
console.log( "Clearing timer "+this.timeoutTimer+", "+requestTimeoutCount+" running" );
|
|
|
|
$clear( this.timeoutTimer );
|
|
|
|
this.timeoutTimer = null;
|
|
|
|
}
|
2009-04-05 05:59:52 +08:00
|
|
|
return( this );
|
2007-11-11 23:59:29 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|