diff options
author | wei <> | 2006-05-05 00:45:35 +0000 |
---|---|---|
committer | wei <> | 2006-05-05 00:45:35 +0000 |
commit | f21d3433721308f5d0693f44bbfed56f7b2ecc2d (patch) | |
tree | 96f10eb302f0a156ebc237d9ab0949986c4f469e /framework/Web/Javascripts | |
parent | 42df6f47862c2f1495ded49f758dbc46f9d9e930 (diff) |
Adding TActiveLabel
Diffstat (limited to 'framework/Web/Javascripts')
-rw-r--r-- | framework/Web/Javascripts/js/ajax.js | 29 | ||||
-rw-r--r-- | framework/Web/Javascripts/js/prado.js | 2 | ||||
-rw-r--r-- | framework/Web/Javascripts/prado/ajax3.js | 84 | ||||
-rw-r--r-- | framework/Web/Javascripts/prado/element.js | 2 |
4 files changed, 98 insertions, 19 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];} diff --git a/framework/Web/Javascripts/prado/ajax3.js b/framework/Web/Javascripts/prado/ajax3.js index 63add490..8ea76e10 100644 --- a/framework/Web/Javascripts/prado/ajax3.js +++ b/framework/Web/Javascripts/prado/ajax3.js @@ -103,6 +103,14 @@ Object.extend(Prado.CallbackRequest, * Response errors/exceptions header name.
*/
ERROR_HEADER : 'X-PRADO-ERROR',
+ /**
+ * Callback request queque.
+ */
+ Queque : [],
+ /**
+ * Requests In progress.
+ */
+ InProgress : [],
/**
* Dispatch callback response actions.
@@ -140,9 +148,9 @@ Object.extend(Prado.CallbackRequest, Exception :
{
/**
- * Server returns 505 exception. Just log it.
+ * Server returns 500 exception. Just log it.
*/
- "on505" : function(request, transport, data)
+ "on500" : function(request, transport, data)
{
var e = request.getHeaderData(Prado.CallbackRequest.ERROR_HEADER);
Logger.error("Callback Server Error "+e.code, this.formatException(e));
@@ -163,7 +171,6 @@ Object.extend(Prado.CallbackRequest, {
msg += inspect(action)+"\n";
})
-
Logger.warn(msg);
}
},
@@ -209,10 +216,61 @@ Object.extend(Prado.CallbackRequest, */
decode : function(data)
{
- return Prado.JSON.parse(data);
+ if(typeof(data) == "string" && data.trim().length > 0)
+ return Prado.JSON.parse(data);
+ else
+ return null;
+ },
+
+ /**
+ * Dispatch quequed requests, and set a timeout.
+ */
+ 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);
+ }
+ },
+
+ /**
+ * Remove a request currently in progress and call dispatchQuequedRequest.
+ */
+ 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});
+
//Add HTTP exception respones when logger is enabled.
Event.OnLoad(function()
{
@@ -233,7 +291,10 @@ Prado.CallbackRequest.prototype = /**
* Callback options, including onXXX events.
*/
- options : {},
+ options :
+ {
+ TimeOut : 30000 // 30 second timeout.
+ },
/**
* Callback target ID. E.g. $control->getUniqueID();
@@ -243,14 +304,15 @@ Prado.CallbackRequest.prototype = /**
* Current callback request.
*/
- request : null,
+ callback : null,
/**
* Prepare and inititate a callback request.
*/
initialize : function(id, options)
{
- this.options = options || {};
+ Object.extend(this.options, options || {});
+
this.id = id;
var request =
@@ -258,14 +320,18 @@ Prado.CallbackRequest.prototype = postBody : this._getPostData(),
parameters : ''
}
- Object.extend(this.options || {},request);
+
+ 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);
+
+ Prado.CallbackRequest.Queque.push(this);
+ Prado.CallbackRequest.dispatchQuequedRequest();
},
/**
diff --git a/framework/Web/Javascripts/prado/element.js b/framework/Web/Javascripts/prado/element.js index 88fb9ec5..cf02095b 100644 --- a/framework/Web/Javascripts/prado/element.js +++ b/framework/Web/Javascripts/prado/element.js @@ -76,7 +76,7 @@ Prado.Element = return false;
},
- replaceContent : function(element, method, content, boundary, transport)
+ replace : function(element, method, content, boundary, transport)
{
if(boundary)
{
|