diff options
Diffstat (limited to 'framework/Web/Javascripts/js/ajax.js')
-rw-r--r-- | framework/Web/Javascripts/js/ajax.js | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/framework/Web/Javascripts/js/ajax.js b/framework/Web/Javascripts/js/ajax.js index 375d90e9..6ab3d18d 100644 --- a/framework/Web/Javascripts/js/ajax.js +++ b/framework/Web/Javascripts/js/ajax.js @@ -34,14 +34,14 @@ this.transport.onreadystatechange=Prototype.emptyFunction;},getHeaderData:functi catch(e) {if(typeof(json)=="string") {Logger.info("using json") -return Prado.CallbackRequest.decode(json);}}}});Prado.CallbackRequest=Class.create();Object.extend(Prado.CallbackRequest,{FIELD_CALLBACK_TARGET:'PRADO_CALLBACK_TARGET',FIELD_CALLBACK_PARAMETER:'PRADO_CALLBACK_PARAMETER',FIELD_CALLBACK_PAGESTATE:'PRADO_PAGESTATE',PostDataLoaders:[],DATA_HEADER:'X-PRADO-DATA',ACTION_HEADER:'X-PRADO-ACTIONS',ERROR_HEADER:'X-PRADO-ERROR',dispatchActions:function(transport,actions) +return Prado.CallbackRequest.decode(json);}}}});Prado.CallbackRequest=Class.create();Object.extend(Prado.CallbackRequest,{FIELD_CALLBACK_TARGET:'PRADO_CALLBACK_TARGET',FIELD_CALLBACK_PARAMETER:'PRADO_CALLBACK_PARAMETER',FIELD_CALLBACK_PAGESTATE:'PRADO_PAGESTATE',PostDataLoaders:[],DATA_HEADER:'X-PRADO-DATA',ACTION_HEADER:'X-PRADO-ACTIONS',ERROR_HEADER:'X-PRADO-ERROR',Queque:[],InProgress:[],dispatchActions:function(transport,actions) {if(actions&&actions.length>0) actions.each(this.__run.bind(this,transport));},__run:function(transport,command) {for(var method in command) {if(command[method][0]) {var id=command[method][0];if($(id)||id.indexOf("[]")>-1) method.toFunction().apply(this,command[method].concat(transport));else if(typeof(Logger)!="undefined") -{Logger.error("Error in executing callback response:","Unable to find HTML element with ID '"+id+"' before executing "+method+"().");}}}},Exception:{"on505":function(request,transport,data) +{Logger.error("Error in executing callback response:","Unable to find HTML element with ID '"+id+"' before executing "+method+"().");}}}},Exception:{"on500":function(request,transport,data) {var e=request.getHeaderData(Prado.CallbackRequest.ERROR_HEADER);Logger.error("Callback Server Error "+e.code,this.formatException(e));},'on200':function(request,transport,data) {if(transport.status<500) {var msg='HTTP '+transport.status+" with response : \n";msg+=transport.responseText+"\n";msg+="Data : \n"+inspect(data)+"\n";msg+="Actions : \n";request.getHeaderData(Prado.CallbackRequest.ACTION_HEADER).each(function(action) @@ -52,15 +52,28 @@ Logger.warn(msg);}},onException:function(e) {msg+=" #"+i+" "+trace[i].file;msg+="("+trace[i].line+"): ";msg+=trace[i]["class"]+"->"+trace[i]["function"]+"()"+"\n";} msg+=e.version+" "+e.time+"\n";return msg;}},encode:function(data) {return Prado.JSON.stringify(data);},decode:function(data) -{return Prado.JSON.parse(data);}}) -Event.OnLoad(function() +{if(typeof(data)=="string"&&data.trim().length>0) +return Prado.JSON.parse(data);else +return null;},dispatchQuequedRequest:function() +{requests=Prado.CallbackRequest;if(requests.InProgress.length==0&&requests.Queque.length>0) +{var item=requests.Queque.pop();item.callback=new Ajax.Request(item.url,item.options);item.callback.callbackID=item.id;item.timeout=setTimeout(function() +{requests.removeInProgress(item.callback);},item.options.TimeOut);requests.InProgress.push(item);}},removeInProgress:function(request) +{if(request&&request.callbackID) +{var stillInProgress=[];requests=Prado.CallbackRequest;requests.InProgress.each(function(item) +{if(item.callback.callbackID==request.callbackID) +{item.callback.transport.abort();request.transport.abort();clearTimeout(item.timeout);} +else +{stillInProgress.push(item);}}) +requests.InProgress=stillInProgress;} +requests.dispatchQuequedRequest();}}) +Ajax.Responders.register({onComplete:Prado.CallbackRequest.removeInProgress});Event.OnLoad(function() {if(typeof Logger!="undefined") -Ajax.Responders.register(Prado.CallbackRequest.Exception);});Prado.CallbackRequest.prototype={url:window.location.href,options:{},id:null,request:null,initialize:function(id,options) -{this.options=options||{};this.id=id;var request={postBody:this._getPostData(),parameters:''} -Object.extend(this.options||{},request);if(this.options.CausesValidation!=false&&typeof(Prado.Validation)!="undefined") +Ajax.Responders.register(Prado.CallbackRequest.Exception);});Prado.CallbackRequest.prototype={url:window.location.href,options:{TimeOut:30000},id:null,callback:null,initialize:function(id,options) +{Object.extend(this.options,options||{});this.id=id;var request={postBody:this._getPostData(),parameters:''} +Object.extend(this.options,request);if(this.options.CausesValidation!=false&&typeof(Prado.Validation)!="undefined") {var form=this.options.Form||Prado.Validation.getForm();if(Prado.Validation.validate(form,this.options.ValidationGroup,this)==false) return;} -this.request=new Ajax.Request(this.url,this.options);},_getPostData:function() +Prado.CallbackRequest.Queque.push(this);Prado.CallbackRequest.dispatchQuequedRequest();},_getPostData:function() {var data={};var callback=Prado.CallbackRequest;if(this.options.PostState!=false) {callback.PostDataLoaders.each(function(name) {$A(document.getElementsByName(name)).each(function(element) |