// locking.js
function AJAX_Locking_Handler()
{
this.timer_id = 0;
switch(arguments.length) {
case 0: // no argument
break;
case 1: // only callbacks
this.ajax = new AjaxLocking(arguments[0]);
break;
case 4: // complete signature
this.ajax = new AjaxLocking(arguments[0]);
this.user = arguments[1];
this.type = arguments[2];
this.id = arguments[3];
break;
default:
alert("AJAX_Locking_Handler constructor error: bad arguments list");
return null;
}
}
AJAX_Locking_Handler.prototype =
{
delay: 2000,
setCallbacks:function(callbacks)
{
this.ajax = new AjaxLocking(lockingCallbacks);
},
setParams:function(user, type, id)
{
this.user = user;
this.type = type;
this.id = id;
},
lock:function()
{
if (this.ajax && this.user && this.type && this.id)
this.ajax.lock(this.user, this.type, this.id);
},
unlock:function()
{
if (this.ajax && this.user && this.type && this.id)
this.ajax.unlock(this.user, this.type, this.id);
},
status:function()
{
if (this.ajax && this.user && this.type && this.id)
this.ajax.status(this.user, this.type, this.id);
},
spawnTimer:function()
{
var myself = this;
this.stop();
this.timer_id = window.setInterval( function() { myself.status(); }, myself.delay);
},
start:function()
{
this.status();
this.spawnTimer();
},
stop:function()
{
if (this.timer_id) {
clearInterval(this.timer_id);
this.timer_id = 0;
}
}
} |