diff options
Diffstat (limited to 'framework/Web/Javascripts/js')
-rw-r--r-- | framework/Web/Javascripts/js/ajax.js | 29 | ||||
-rw-r--r-- | framework/Web/Javascripts/js/prado.js | 2 |
2 files changed, 22 insertions, 9 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) diff --git a/framework/Web/Javascripts/js/prado.js b/framework/Web/Javascripts/js/prado.js index f6c52983..f545ee74 100644 --- a/framework/Web/Javascripts/js/prado.js +++ b/framework/Web/Javascripts/js/prado.js @@ -266,7 +266,7 @@ el.setAttribute(attribute,value);},setOptions:function(element,options) el.remove(0);for(var i=0;i<options.length;i++) el.options[el.options.length]=new Option(options[i][0],options[i][1]);}},focus:function(element) {var obj=$(element);if(typeof(obj)!="undefined"&&typeof(obj.focus)!="undefined") -setTimeout(function(){obj.focus();},100);return false;},replaceContent:function(element,method,content,boundary,transport) +setTimeout(function(){obj.focus();},100);return false;},replace:function(element,method,content,boundary,transport) {if(boundary) {var f=RegExp('(<!--'+boundary+'-->)([\\s\\S\\w\\W]*)(<!--//'+boundary+'-->)',"m");var result=transport.responseText.match(f);if(result&&result.length>=2) content=result[2];} |