summaryrefslogtreecommitdiffstats
path: root/usr/local/www/javascript/global.js
diff options
context:
space:
mode:
authorScott Ullrich <sullrich@pfsense.org>2009-03-14 14:16:34 -0400
committerScott Ullrich <sullrich@pfsense.org>2009-03-14 14:16:34 -0400
commit2687a6fa517d2a21b8f981198f9f4136a510dc55 (patch)
tree9c5bc4c6f56b6465713dcd8e69da640694ad33c4 /usr/local/www/javascript/global.js
parentbae568ccb5fb418a2d1260a73870e40c3d78d494 (diff)
downloadpfsense-2687a6fa517d2a21b8f981198f9f4136a510dc55.zip
pfsense-2687a6fa517d2a21b8f981198f9f4136a510dc55.tar.gz
Adding Ajax queue system.
Example usage: AjaxQueue.setBatchSize(1); AjaxQueue.push("http://www.testingqueue.com/process/",{onSucess: funcSuccess, onfailure: funcFailure}); AjaxQueue.push("http://www.testingqueue.com/process1/",{onSucess: funcSuccess1, onfailure: funcFailure1}, "myDiv"); AjaxQueue.push("http://www.testingqueue.com/process2/",{onSucess: funcSuccess2, onfailure: funcFailure2}); AjaxQueue.push("http://www.testingqueue.com/process3/",{onSucess: funcSuccess3, onfailure: funcFailure3}); AjaxQueue.push("http://www.testingqueue.com/process4/",{onSucess: funcSuccess4, onfailure: funcFailure4}); AjaxQueue.push("http://www.testingqueue.com/process5/",{onSucess: funcSuccess5, onfailure: funcFailure5});
Diffstat (limited to 'usr/local/www/javascript/global.js')
-rw-r--r--usr/local/www/javascript/global.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/usr/local/www/javascript/global.js b/usr/local/www/javascript/global.js
new file mode 100644
index 0000000..418f7ef
--- /dev/null
+++ b/usr/local/www/javascript/global.js
@@ -0,0 +1,40 @@
+var AjaxQueue = {
+ batchSize: 1, //No.of simultaneous AJAX requests allowed, Default : 1
+ urlQueue: [], //Request URLs will be pushed into this array
+ elementsQueue: [], //Element IDs of elements to be updated on completion of a request ( as in Ajax.Updater )
+ optionsQueue: [], //Request options will be pushed into this array
+ setBatchSize: function(bSize){ //Method to set a different batch size. Recommended: Set batchSize before making requests
+ this.batchSize = bSize;
+ },
+ push: function(url, options, elementID){ //Push the request in the queue. elementID is optional and required only for Ajax.Updater calls
+ this.urlQueue.push(url);
+ this.optionsQueue.push(options);
+ if(elementID!=null){
+ this.elementsQueue.push(elementID);
+ } else {
+ this.elementsQueue.push("NOTSPECIFIED");
+ }
+
+ this._processNext();
+ },
+ _processNext: function() { // Method for processing the requests in the queue. Private method. Don't call it explicitly
+ if(Ajax.activeRequestCount < AjaxQueue.batchSize) // Check if the currently processing request count is less than batch size
+ {
+ if(AjaxQueue.elementsQueue.first()=="NOTSPECIFIED") { //Check if an elementID was specified
+ // Call Ajax.Request if no ElementID specified
+ //Call Ajax.Request on the first item in the queue and remove it from the queue
+ new Ajax.Request(AjaxQueue.urlQueue.shift(), AjaxQueue.optionsQueue.shift());
+
+ var junk = AjaxQueue.elementsQueue.shift();
+ } else {
+ // Call Ajax.Updater if an ElementID was specified.
+ //Call Ajax.Updater on the first item in the queue and remove it from the queue
+ new Ajax.Updater(AjaxQueue.elementsQueue.shift(), AjaxQueue.urlQueue.shift(), AjaxQueue.optionsQueue.shift());
+ }
+ }
+ }
+};
+Ajax.Responders.register({
+ //Call AjaxQueue._processNext on completion ( success / failure) of any AJAX call.
+ onComplete: AjaxQueue._processNext
+});
OpenPOWER on IntegriCloud