summaryrefslogtreecommitdiffstats
path: root/usr/local/www/javascript/global.js
diff options
context:
space:
mode:
authorVinicius Coque <vcoque@gmail.com>2011-12-11 20:52:50 -0200
committerVinicius Coque <vcoque@gmail.com>2011-12-11 20:52:50 -0200
commit1c3351bd08c6b3fd3c808e339ac5d20d7b9f18fc (patch)
tree3e5982b0025144fdc0fbb3b8f7038a4401cc6baa /usr/local/www/javascript/global.js
parent7dcf1cc77f4f7e061418b324a2632804634aa0fe (diff)
downloadpfsense-1c3351bd08c6b3fd3c808e339ac5d20d7b9f18fc.zip
pfsense-1c3351bd08c6b3fd3c808e339ac5d20d7b9f18fc.tar.gz
Adapted the AjaxQueue code to work with jQuery
Diffstat (limited to 'usr/local/www/javascript/global.js')
-rw-r--r--usr/local/www/javascript/global.js36
1 files changed, 19 insertions, 17 deletions
diff --git a/usr/local/www/javascript/global.js b/usr/local/www/javascript/global.js
index 418f7ef..d703658 100644
--- a/usr/local/www/javascript/global.js
+++ b/usr/local/www/javascript/global.js
@@ -1,12 +1,13 @@
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 )
+ elementsQueue: [], //Element IDs of elements to be updated on completion of a request
optionsQueue: [], //Request options will be pushed into this array
+ currentRequest: null,
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
+ push: function(url, options, elementID){ //Push the request in the queue. elementID is optional and required only for Ajax requests that updates the element
this.urlQueue.push(url);
this.optionsQueue.push(options);
if(elementID!=null){
@@ -18,23 +19,24 @@ var AjaxQueue = {
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());
-
+ if(this.currentRequest == null && this.urlQueue.length > 0) // Check if the currently processing request count is less than batch size
+ {
+ // Call jQuery.ajax on the first item in the queue and remove it from the queue
+ AjaxQueue.currentRequest = jQuery.ajax(AjaxQueue.urlQueue.shift(), AjaxQueue.optionsQueue.shift());
+ AjaxQueue.currentRequest.complete( function() {
+ //Call AjaxQueue._processNext on completion ( success / failure) of this AJAX request.
+ AjaxQueue.currentRequest = null;
+ AjaxQueue._processNext();
+ });
+ if(this.elementsQueue[0]=="NOTSPECIFIED") { //Check if an elementID was specified
+ // If no ElementID was specified remove the first item from the queue
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());
- }
+ // If ElementID was specified update the first item in the queue and remove it from the queue
+ AjaxQueue.currentRequest.success( function(data) {
+ jQuery(AjaxQueue.elementsQueue.shift()).html(data);
+ });
+ }
}
}
};
-Ajax.Responders.register({
- //Call AjaxQueue._processNext on completion ( success / failure) of any AJAX call.
- onComplete: AjaxQueue._processNext
-});
OpenPOWER on IntegriCloud