diff options
author | Fabio Bas <ctrlaltca@gmail.com> | 2014-01-06 23:10:22 +0100 |
---|---|---|
committer | Fabio Bas <ctrlaltca@gmail.com> | 2014-01-06 23:10:22 +0100 |
commit | ac4eaa30cc19cddec0aae5621d136a5a5fe7777c (patch) | |
tree | 1771c92532b0accf82642b5a9c384a2dd33c880a /framework/Web/Javascripts | |
parent | 498a2ca334c38f3f1e51081acb9e8492810fb42c (diff) |
Implemented ajax queue (based on https://github.com/gnarf37/jquery-ajaxQueue)
Diffstat (limited to 'framework/Web/Javascripts')
-rw-r--r-- | framework/Web/Javascripts/source/prado/activecontrols/ajax3.js | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js b/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js index 597187bb..e6616176 100644 --- a/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js +++ b/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js @@ -66,6 +66,55 @@ Prado.CallbackRequestManager = } msg += e.version+" "+e.time+"\n"; return msg; + }, + + /*! jQuery Ajax Queue - v0.1.2pre - 2013-03-19 + * https://github.com/gnarf37/jquery-ajaxQueue + * Copyright (c) 2013 Corey Frang; Licensed MIT + * Slightly adapted for use within prado by Fabio Bas <ctrlaltca@gmail.com> + */ + + // jQuery on an empty object, we are going to use this as our Queue + ajaxQueue : jQuery({}), + + ajax : function( ajaxOpts ) { + var jqXHR, + dfd = jQuery.Deferred(), + promise = dfd.promise(); + + // run the actual query + function doRequest( next ) { + jqXHR = jQuery.ajax( ajaxOpts ); + jqXHR.done( dfd.resolve ) + .fail( dfd.reject ) + .then( next, next ); + } + + // queue our ajax request + Prado.CallbackRequestManager.ajaxQueue.queue( doRequest ); + + // add the abort method + promise.abort = function( statusText ) { + + // proxy abort to the jqXHR if it is active + if ( jqXHR ) { + return jqXHR.abort( statusText ); + } + + // if there wasn't already a jqXHR we need to remove from queue + var queue = Prado.CallbackRequestManager.ajaxQueue.queue(), + index = jQuery.inArray( doRequest, queue ); + + if ( index > -1 ) { + queue.splice( index, 1 ); + } + + // and then reject the deferred + dfd.rejectWith( ajaxOpts.context || ajaxOpts, [ promise, statusText, "" ] ); + return promise; + }; + + return promise; } }; @@ -215,7 +264,7 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, this.options.data = this.getParameters(); this.options.url = this.getCallbackUrl(); - this.request = jQuery.ajax(this.options); + this.request = Prado.CallbackRequestManager.ajax(this.options); }, abort : function() @@ -239,7 +288,7 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, if(this.options.EventTarget) data[Prado.CallbackRequestManager.FIELD_CALLBACK_TARGET] = this.options.EventTarget; - if(this.options.PostInputs != false) + if(this.options.PostInputs != false) return jQuery(form).serialize() + '&' + jQuery.param(data); else return jQuery.param(data); |