PHP Classes

File: js/Locking.js

Recommend this page to a friend!
  Classes of Fabio Ambrosanio   AJAX Locking   js/Locking.js   Download  
File: js/Locking.js
Role: Auxiliary data
Content type: text/plain
Description: Javascript library to handle AJAX calls
Class: AJAX Locking
Lock server side resources from AJAX requests
Author: By
Last change: Addedd two new methods: setCallbacks to set callbacks and setParams to set user, type and id
Now the constructor accept 0, 1 or 4 arguments: with 1 argument you can set callbacks without parameters (user, type and id), with 4 arguments you can set all the stuff
Date: 16 years ago
Size: 1,617 bytes
 

Contents

Class file image Download
// 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; } } }