summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorwei <>2006-08-11 06:55:09 +0000
committerwei <>2006-08-11 06:55:09 +0000
commit6dd529fdc25404da07cf9256d92f2a94985c65fc (patch)
tree71626b8d6190b377fcd72261e60edbbab59c320b /framework/Web
parentb687748278d29510bb28875627c98b5da0a96cc5 (diff)
Update callback request client-side API.
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/Javascripts/js/ajax.js26
-rw-r--r--framework/Web/Javascripts/prado/activecontrols.js196
-rw-r--r--framework/Web/Javascripts/prado/activecontrols3.js72
-rw-r--r--framework/Web/Javascripts/prado/ajax3.js176
-rw-r--r--framework/Web/UI/ActiveControls/TBaseActiveControl.php15
5 files changed, 193 insertions, 292 deletions
diff --git a/framework/Web/Javascripts/js/ajax.js b/framework/Web/Javascripts/js/ajax.js
index 40a27f00..fd1b7a76 100644
--- a/framework/Web/Javascripts/js/ajax.js
+++ b/framework/Web/Javascripts/js/ajax.js
@@ -75,8 +75,16 @@ Ajax.Responders.register({onComplete:function(request)
Prado.CallbackRequest.abortRequestInProgress();}});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.id=id;this.options={RequestTimeOut:30000,EnablePageStateUpdate:true,HasPriority:true,CausesValidation:true,ValidationGroup:null,PostInputs:true}
-Object.extend(this.options,options||{});Object.extend(this.options,{postBody:this._getPostData(),parameters:''});if(this.options.CausesValidation&&typeof(Prado.Validation)!="undefined")
+{this.id=id;this.options=Object.extend({RequestTimeOut:30000,EnablePageStateUpdate:true,HasPriority:true,CausesValidation:true,ValidationGroup:null,PostInputs:true},options||{});},setParameter:function(value)
+{this.options['params']=value;},getParameter:function()
+{return this.options['params'];},setRequestTimeOut:function(timeout)
+{this.options['RequestTimeOut']=timeout;},getRequestTimeOut:function()
+{return this.options['RequestTimeOut'];},setCausesValidation:function(validate)
+{this.options['CausesValidation']=validate;},getCausesValidation:function()
+{return this.options['CausesValidation'];},setValidationGroup:function(group)
+{this.options['ValidationGroup']=group;},getValidationGroup:function()
+{return this.options['ValidationGroup'];},dispatch:function()
+{Object.extend(this.options,{postBody:this._getPostData(),parameters:''});if(this.options.CausesValidation&&typeof(Prado.Validation)!="undefined")
{var form=this.options.Form||Prado.Validation.getForm();if(Prado.Validation.validate(form,this.options.ValidationGroup,this)==false)
return;}
if(this.options.HasPriority)
@@ -93,7 +101,7 @@ data[callback.FIELD_CALLBACK_PAGESTATE]=pageState;data[callback.FIELD_CALLBACK_T
data[callback.FIELD_POSTBACK_TARGET]=this.options.EventTarget;if(this.options.EventParameter)
data[callback.FIELD_POSTBACK_PARAMETER]=this.options.EventParameter;return $H(data).toQueryString();}}
Prado.Callback=function(UniqueID,parameter,onSuccess,options)
-{var callback={'params':parameter||'','onSuccess':onSuccess||Prototype.emptyFunction};Object.extend(callback,options||{});new Prado.CallbackRequest(UniqueID,callback);return false;}
+{var callback={'params':parameter||'','onSuccess':onSuccess||Prototype.emptyFunction};Object.extend(callback,options||{});request=new Prado.CallbackRequest(UniqueID,callback);request.dispatch();return false;}
Array.prototype.______array='______array';Prado.JSON={org:'http://www.JSON.org',copyright:'(c)2005 JSON.org',license:'http://www.crockford.com/JSON/license.html',stringify:function(arg){var c,i,l,s='',v;switch(typeof arg){case'object':if(arg){if(arg.______array=='______array'){for(i=0;i<arg.length;++i){v=this.stringify(arg[i]);if(s){s+=',';}
s+=v;}
return'['+s+']';}else if(typeof arg.toString!='undefined'){for(i in arg){v=arg[i];if(typeof v!='undefined'&&typeof v!='function'){v=this.stringify(v);if(s){s+=',';}
@@ -189,15 +197,15 @@ if(this.saving)return;this.effect=new Effect.Highlight(this.element,{startcolor:
this.editing=false;this.saving=false;this.oldInnerHTML=null;this.onLeaveEditMode();},onComplete:function(transport){this.leaveEditMode();this.options.onComplete.bind(this)(transport,this.element);},onEnterEditMode:function(){},onLeaveEditMode:function(){},dispose:function(){if(this.oldInnerHTML){this.element.innerHTML=this.oldInnerHTML;}
this.leaveEditMode();Event.stopObserving(this.element,'click',this.onclickListener);Event.stopObserving(this.element,'mouseover',this.mouseoverListener);Event.stopObserving(this.element,'mouseout',this.mouseoutListener);if(this.options.externalControl){Event.stopObserving(this.options.externalControl,'click',this.onclickListener);Event.stopObserving(this.options.externalControl,'mouseover',this.mouseoverListener);Event.stopObserving(this.options.externalControl,'mouseout',this.mouseoutListener);}}};Ajax.InPlaceCollectionEditor=Class.create();Object.extend(Ajax.InPlaceCollectionEditor.prototype,Ajax.InPlaceEditor.prototype);Object.extend(Ajax.InPlaceCollectionEditor.prototype,{createEditField:function(){if(!this.cached_selectTag){var selectTag=document.createElement("select");var collection=this.options.collection||[];var optionTag;collection.each(function(e,i){optionTag=document.createElement("option");optionTag.value=(e instanceof Array)?e[0]:e;if(this.options.value==optionTag.value)optionTag.selected=true;optionTag.appendChild(document.createTextNode((e instanceof Array)?e[1]:e));selectTag.appendChild(optionTag);}.bind(this));this.cached_selectTag=selectTag;}
this.editField=this.cached_selectTag;if(this.options.loadTextURL)this.loadExternalText();this.form.appendChild(this.editField);this.options.callback=function(form,value){return"value="+encodeURIComponent(value);}}});Form.Element.DelayedObserver=Class.create();Form.Element.DelayedObserver.prototype={initialize:function(element,delay,callback){this.delay=delay||0.5;this.element=$(element);this.callback=callback;this.timer=null;this.lastValue=$F(this.element);Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this));},delayedListener:function(event){if(this.lastValue==$F(this.element))return;if(this.timer)clearTimeout(this.timer);this.timer=setTimeout(this.onTimerEvent.bind(this),this.delay*1000);this.lastValue=$F(this.element);},onTimerEvent:function(){this.timer=null;this.callback(this.element,$F(this.element));}};Prado.WebUI.CallbackControl=Class.extend(Prado.WebUI.PostBackControl,{onPostBack:function(event,options)
-{new Prado.CallbackRequest(options.EventTarget,options);Event.stop(event);}});Prado.WebUI.TActiveButton=Class.extend(Prado.WebUI.CallbackControl);Prado.WebUI.TActiveCheckBox=Class.extend(Prado.WebUI.CallbackControl,{onPostBack:function(event,options)
-{new Prado.CallbackRequest(options.EventTarget,options);}});Prado.WebUI.TActiveTextBox=Class.extend(Prado.WebUI.TTextBox,{onInit:function(options)
+{request=new Prado.CallbackRequest(options.EventTarget,options);request.dispatch();Event.stop(event);}});Prado.WebUI.TActiveButton=Class.extend(Prado.WebUI.CallbackControl);Prado.WebUI.TActiveCheckBox=Class.extend(Prado.WebUI.CallbackControl,{onPostBack:function(event,options)
+{request=new Prado.CallbackRequest(options.EventTarget,options);request.dispatch();}});Prado.WebUI.TActiveTextBox=Class.extend(Prado.WebUI.TTextBox,{onInit:function(options)
{if(options['TextMode']!='MultiLine')
Event.observe(this.element,"keydown",this.handleReturnKey.bind(this));Event.observe(this.element,"change",this.doCallback.bindEvent(this,options));},doCallback:function(event,options)
-{new Prado.CallbackRequest(options.EventTarget,options);Event.stop(event);}});Prado.WebUI.TAutoComplete=Class.extend(Autocompleter.Base,Prado.WebUI.TActiveTextBox.prototype);Prado.WebUI.TAutoComplete=Class.extend(Prado.WebUI.TAutoComplete,{initialize:function(options)
+{request=new Prado.CallbackRequest(options.EventTarget,options);request.dispatch();Event.stop(event);}});Prado.WebUI.TAutoComplete=Class.extend(Autocompleter.Base,Prado.WebUI.TActiveTextBox.prototype);Prado.WebUI.TAutoComplete=Class.extend(Prado.WebUI.TAutoComplete,{initialize:function(options)
{this.options=options;this.baseInitialize(options.ID,options.ResultPanel,options);Object.extend(this.options,{onSuccess:this.onComplete.bind(this)});if(options.AutoPostBack)
this.onInit(options);},doCallback:function(event,options)
{if(!this.active)
-{new Prado.CallbackRequest(options.EventTarget,options);Event.stop(event);}},onClick:function(event)
+{request=new Prado.CallbackRequest(options.EventTarget,options);request.dispatch();Event.stop(event);}},onClick:function(event)
{var element=Event.findElement(event,'LI');this.index=element.autocompleteIndex;this.selectEntry();this.hide();Event.fireEvent(this.element,"change");},getUpdatedChoices:function()
{options=new Array(this.getToken(),"__TAutoComplete_onSuggest__");Prado.Callback(this.options.EventTarget,options,null,this.options);},onComplete:function(request,boundary)
{result=Prado.Element.extractContent(request.responseText,boundary);if(typeof(result)=="string"&&result.length>0)
@@ -206,7 +214,7 @@ this.updateChoices(result);}});Prado.WebUI.TCallbackTimer=Base.extend({count:0,t
this.onComplete=this.options.onComplete;Prado.WebUI.TCallbackTimer.register(this);},startTimer:function()
{this.options.onComplete=this.onRequestComplete.bind(this);setTimeout(this.onTimerEvent.bind(this),200);},stopTimer:function()
{(this.onComplete||Prototype.emptyFunction).apply(this,arguments);this.options.onComplete=undefined;clearTimeout(this.timer);this.timer=undefined;this.count=0;},onTimerEvent:function()
-{this.options.params=this.timeout/1000;new Prado.CallbackRequest(this.options.ID,this.options);},onRequestComplete:function()
+{this.options.params=this.timeout/1000;request=new Prado.CallbackRequest(this.options.ID,this.options);request.dispatch();},onRequestComplete:function()
{(this.onComplete||Prototype.emptyFunction).apply(this,arguments);this.timer=setTimeout(this.onTimerEvent.bind(this),this.getNewTimeout())},getNewTimeout:function()
{switch(this.options.DecayType)
{case'Exponential':t=(Math.exp(this.options.DecayRate*this.count*this.options.Interval))-1;break;case'Linear':t=this.options.DecayRate*this.count*this.options.Interval;break;case'Quadratic':t=this.options.DecayRate*this.count*this.count*this.options.Interval;break;case'Cubic':t=this.options.DecayRate*this.count*this.count*this.count*this.options.Interval;break;default:t=0;}
@@ -217,4 +225,4 @@ this.timers[id].startTimer();},stop:function(id)
{if(this.timers[id])
this.timers[id].stopTimer();}});Prado.WebUI.ActiveListControl=Base.extend({constructor:function(options)
{this.element=$(options.ID);this.options=options;Event.observe(this.element,"change",this.doCallback.bind(this));},doCallback:function(event)
-{new Prado.CallbackRequest(this.options.EventTarget,this.options);Event.stop(event);}});Prado.WebUI.TActiveDropDownList=Prado.WebUI.ActiveListControl; \ No newline at end of file
+{request=new Prado.CallbackRequest(this.options.EventTarget,this.options);request.dispatch();Event.stop(event);}});Prado.WebUI.TActiveDropDownList=Prado.WebUI.ActiveListControl; \ No newline at end of file
diff --git a/framework/Web/Javascripts/prado/activecontrols.js b/framework/Web/Javascripts/prado/activecontrols.js
deleted file mode 100644
index 72f97511..00000000
--- a/framework/Web/Javascripts/prado/activecontrols.js
+++ /dev/null
@@ -1,196 +0,0 @@
-/**
- * Auto complete textbox via AJAX.
- */
-Prado.AutoCompleter = Class.create();
-
-
-/**
- * Overrides parent implementation of updateElement by trimming the value.
- */
-Prado.AutoCompleter.Base = function(){};
-Prado.AutoCompleter.Base.prototype = Object.extend(Autocompleter.Base.prototype,
-{
- updateElement: function(selectedElement)
- {
- if (this.options.updateElement) {
- this.options.updateElement(selectedElement);
- return;
- }
-
- var value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
- var lastTokenPos = this.findLastToken();
- if (lastTokenPos != -1) {
- var newValue = this.element.value.substr(0, lastTokenPos + 1);
- var whitespace = this.element.value.substr(lastTokenPos + 1).match(/^\s+/);
- if (whitespace)
- newValue += whitespace[0];
- this.element.value = (newValue + value).trim();
- } else {
- this.element.value = value.trim();
- }
- this.element.focus();
-
- if (this.options.afterUpdateElement)
- this.options.afterUpdateElement(this.element, selectedElement);
- }
-});
-
-/**
- * Based on the Prototype Autocompleter class.
- * This client-side component should be instantiated from a Prado component.
- * Usage: <t>new Prado.AutoCompleter('textboxID', 'updateDivID', {callbackID : '...'});
- */
-Prado.AutoCompleter.prototype = Object.extend(new Autocompleter.Base(),
-{
- /**
- * This component is initialized by
- * <code>new Prado.AutoCompleter(...)</code>
- * @param string the ID of the textbox element to observe
- * @param string the ID of the div to display the auto-complete options
- * @param array a hash of options, e.g. auto-completion token separator.
- */
- initialize : function(element, update, options)
- {
- this.baseInitialize(element, update, options);
- },
-
- /**
- * The callback function, i.e., function called on successful AJAX return.
- * Calls update choices in the Autocompleter.
- * @param string new auto-complete options for display
- */
- onUpdateReturn : function(result)
- {
- if(isString(result) && result.length > 0)
- this.updateChoices(result);
- },
-
- /**
- * Requesting new choices using Prado's client-side callback scheme.
- */
- getUpdatedChoices : function()
- {
- Prado.Callback(this.element.id, this.getToken(), this.onUpdateReturn.bind(this));
- }
-});
-
-/**
- * Prado TActivePanel client javascript. Usage
- * <code>
- * Prado.ActivePanel.register("id", options);
- * Prado.ActivePanel.update("id", "hello");
- * </code>
- */
-Prado.ActivePanel =
-{
- callbacks : {},
-
- register : function(id, options)
- {
- Prado.ActivePanel.callbacks[id] = options;
- },
-
- update : function(id, param)
- {
- var request = new Prado.ActivePanel.Request(id,
- Prado.ActivePanel.callbacks[id]);
- request.callback(param);
- }
-}
-
-/**
- * Client-script for TActivePanel. Uses Callback to notify the server
- * for updates, if update option is set, the innerHTML of the update ID
- * is set to the returned output.
- */
-Prado.ActivePanel.Request = Class.create();
-Prado.ActivePanel.Request.prototype =
-{
- initialize : function(element, options)
- {
- this.element = element;
- this.setOptions(options);
- },
-
- /**
- * Set some options.
- */
- setOptions : function(options)
- {
- this.options =
- {
- onSuccess : this.onSuccess.bind(this)
- }
- Object.extend(this.options, options || {});
- },
-
- /**
- * Make the callback request
- */
- callback : function(param)
- {
- this.options.params = [param];
- new Prado.AJAX.Callback(this.element, this.options);
- },
-
- /**
- * Callback onSuccess handler, update the element innerHTML if necessary
- */
- onSuccess : function(result, output)
- {
- if(this.options.update)
- {
- if (!this.options.evalScripts)
- output = output.stripScripts();
- Element.update(this.options.update, output);
- }
- }
-}
-
-/**
- * Drop container to accept draggable component drops.
- */
-Prado.DropContainer = Class.create();
-Prado.DropContainer.prototype = Object.extend(new Prado.ActivePanel.Request(),
-{
- initialize : function(element, options)
- {
- this.element = element;
- this.setOptions(options);
- Object.extend(this.options,
- {
- onDrop : this.onDrop.bind(this),
- evalScripts : true,
- onSuccess : options.onSuccess || this.onSuccess.bind(this)
- });
- Droppables.add(element, this.options);
- },
-
- onDrop : function(draggable, droppable)
- {
- this.callback(draggable.id)
- }
-});
-
-Prado.ActiveImageButton = Class.create();
-Prado.ActiveImageButton.prototype =
-{
- initialize : function(element, options)
- {
- this.element = $(element);
- this.options = options;
- Event.observe(this.element, "click", this.click.bind(this));
- },
-
- click : function(e)
- {
- var el = $('{$this->ClientID}');
- var imagePos = Position.cumulativeOffset(this.element);
- var clickedPos = [e.clientX, e.clientY];
- var param = (clickedPos[0]-imagePos[0]+1)+","+(clickedPos[1]-imagePos[1]+1);
- Prado.Callback(this.element, param, null, this.options);
- Event.stop(e);
- }
-}
-
-
diff --git a/framework/Web/Javascripts/prado/activecontrols3.js b/framework/Web/Javascripts/prado/activecontrols3.js
index fc3af2a8..71719f35 100644
--- a/framework/Web/Javascripts/prado/activecontrols3.js
+++ b/framework/Web/Javascripts/prado/activecontrols3.js
@@ -5,9 +5,10 @@ Prado.WebUI.CallbackControl = Class.extend(Prado.WebUI.PostBackControl,
{
onPostBack : function(event, options)
{
- new Prado.CallbackRequest(options.EventTarget, options);
+ request = new Prado.CallbackRequest(options.EventTarget, options);
+ request.dispatch();
Event.stop(event);
- }
+ }
});
/**
@@ -15,15 +16,16 @@ Prado.WebUI.CallbackControl = Class.extend(Prado.WebUI.PostBackControl,
*/
Prado.WebUI.TActiveButton = Class.extend(Prado.WebUI.CallbackControl);
-/**
+/**
* Active check box.
*/
Prado.WebUI.TActiveCheckBox = Class.extend(Prado.WebUI.CallbackControl,
{
onPostBack : function(event, options)
{
- new Prado.CallbackRequest(options.EventTarget, options);
- }
+ request = new Prado.CallbackRequest(options.EventTarget, options);
+ request.dispatch();
+ }
});
/**
@@ -37,10 +39,11 @@ Prado.WebUI.TActiveTextBox = Class.extend(Prado.WebUI.TTextBox,
Event.observe(this.element, "keydown", this.handleReturnKey.bind(this));
Event.observe(this.element, "change", this.doCallback.bindEvent(this,options));
},
-
+
doCallback : function(event, options)
{
- new Prado.CallbackRequest(options.EventTarget, options);
+ request = new Prado.CallbackRequest(options.EventTarget, options);
+ request.dispatch();
Event.stop(event);
}
});
@@ -55,11 +58,11 @@ Prado.WebUI.TAutoComplete = Class.extend(Prado.WebUI.TAutoComplete,
{
this.options = options;
this.baseInitialize(options.ID, options.ResultPanel, options);
- Object.extend(this.options,
+ Object.extend(this.options,
{
onSuccess : this.onComplete.bind(this)
});
-
+
if(options.AutoPostBack)
this.onInit(options);
},
@@ -68,13 +71,14 @@ Prado.WebUI.TAutoComplete = Class.extend(Prado.WebUI.TAutoComplete,
{
if(!this.active)
{
- new Prado.CallbackRequest(options.EventTarget, options);
+ request = new Prado.CallbackRequest(options.EventTarget, options);
+ request.dispatch();
Event.stop(event);
}
},
-
+
//Overrides parent implementation, fires onchange event.
- onClick: function(event)
+ onClick: function(event)
{
var element = Event.findElement(event, 'LI');
this.index = element.autocompleteIndex;
@@ -82,29 +86,29 @@ Prado.WebUI.TAutoComplete = Class.extend(Prado.WebUI.TAutoComplete,
this.hide();
Event.fireEvent(this.element, "change");
},
-
+
getUpdatedChoices : function()
{
options = new Array(this.getToken(),"__TAutoComplete_onSuggest__");
Prado.Callback(this.options.EventTarget, options, null, this.options);
},
-
- onComplete : function(request, boundary)
+
+ onComplete : function(request, boundary)
{
result = Prado.Element.extractContent(request.responseText, boundary);
if(typeof(result) == "string" && result.length > 0)
this.updateChoices(result);
- }
+ }
});
-/**
- * Callback Timer class.
+/**
+ * Callback Timer class.
*/
Prado.WebUI.TCallbackTimer = Base.extend(
{
count : 0,
timeout : 0,
-
+
constructor : function(options)
{
this.options = Object.extend(
@@ -112,17 +116,17 @@ Prado.WebUI.TCallbackTimer = Base.extend(
Interval : 1,
DecayRate : 0
}, options || {})
-
+
this.onComplete = this.options.onComplete;
Prado.WebUI.TCallbackTimer.register(this);
},
-
+
startTimer : function()
{
this.options.onComplete = this.onRequestComplete.bind(this);
setTimeout(this.onTimerEvent.bind(this), 200);
},
-
+
stopTimer : function()
{
(this.onComplete || Prototype.emptyFunction).apply(this, arguments);
@@ -131,19 +135,20 @@ Prado.WebUI.TCallbackTimer = Base.extend(
this.timer = undefined;
this.count = 0;
},
-
+
onTimerEvent : function()
{
this.options.params = this.timeout/1000;
- new Prado.CallbackRequest(this.options.ID, this.options);
+ request = new Prado.CallbackRequest(this.options.ID, this.options);
+ request.dispatch();
},
-
+
onRequestComplete : function()
{
(this.onComplete || Prototype.emptyFunction).apply(this, arguments);
this.timer = setTimeout(this.onTimerEvent.bind(this), this.getNewTimeout())
},
-
+
getNewTimeout : function()
{
switch(this.options.DecayType)
@@ -170,18 +175,18 @@ Prado.WebUI.TCallbackTimer = Base.extend(
//class methods
{
timers : {},
-
+
register : function(timer)
{
this.timers[timer.options.ID] = timer;
},
-
+
start : function(id)
{
if(this.timers[id])
this.timers[id].startTimer();
- },
-
+ },
+
stop : function(id)
{
if(this.timers[id])
@@ -195,12 +200,13 @@ Prado.WebUI.ActiveListControl = Base.extend(
{
this.element = $(options.ID);
this.options = options;
- Event.observe(this.element, "change", this.doCallback.bind(this));
+ Event.observe(this.element, "change", this.doCallback.bind(this));
},
-
+
doCallback : function(event)
{
- new Prado.CallbackRequest(this.options.EventTarget, this.options);
+ request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
+ request.dispatch();
Event.stop(event);
}
});
diff --git a/framework/Web/Javascripts/prado/ajax3.js b/framework/Web/Javascripts/prado/ajax3.js
index bae60d89..8de0b0fe 100644
--- a/framework/Web/Javascripts/prado/ajax3.js
+++ b/framework/Web/Javascripts/prado/ajax3.js
@@ -7,14 +7,14 @@ Object.extend(Ajax.Request.prototype,
* Customize the response, dispatch onXXX response code events, and
* tries to execute response actions (javascript statements).
*/
- respondToReadyState : function(readyState)
+ respondToReadyState : function(readyState)
{
var event = Ajax.Request.Events[readyState];
var transport = this.transport, json = this.getHeaderData(Prado.CallbackRequest.DATA_HEADER);
- if (event == 'Complete')
- {
- try
+ if (event == 'Complete')
+ {
+ try
{
Prado.CallbackRequest.updatePageState(this,transport);
Ajax.Responders.dispatch('on' + transport.status, this, transport, json);
@@ -29,19 +29,19 @@ Object.extend(Ajax.Request.prototype,
if ((this.header('Content-type') || '').match(/^text\/javascript/i))
this.evalResponse();
}
-
+
try {
(this.options['on' + event] || Prototype.emptyFunction)(transport, json);
Ajax.Responders.dispatch('on' + event, this, transport, json);
} catch (e) {
this.dispatchException(e);
}
-
+
/* Avoid memory leak in MSIE: clean up the oncomplete event handler */
if (event == 'Complete')
this.transport.onreadystatechange = Prototype.emptyFunction;
},
-
+
/**
* Gets header data assuming JSON encoding.
* @param string header name
@@ -49,12 +49,12 @@ Object.extend(Ajax.Request.prototype,
*/
getHeaderData : function(name)
{
- try
+ try
{
var json = this.header(name);
return eval('(' + json + ')');
- }
- catch (e)
+ }
+ catch (e)
{
if(typeof(json) == "string")
return Prado.CallbackRequest.decode(json);
@@ -84,9 +84,9 @@ Object.extend(Prado.CallbackRequest,
* Callback request page state field name,
*/
FIELD_CALLBACK_PAGESTATE : 'PRADO_PAGESTATE',
-
+
FIELD_POSTBACK_TARGET : 'PRADO_POSTBACK_TARGET',
-
+
FIELD_POSTBACK_PARAMETER : 'PRADO_POSTBACK_PARAMETER',
/**
@@ -113,7 +113,7 @@ Object.extend(Prado.CallbackRequest,
* Current requests in progress.
*/
requestInProgress : null,
-
+
/**
* Add ids of inputs element to post in the request.
*/
@@ -121,7 +121,7 @@ Object.extend(Prado.CallbackRequest,
{
this.PostDataLoaders = this.PostDataLoaders.concat(ids);
},
-
+
/**
* Dispatch callback response actions.
*/
@@ -130,7 +130,7 @@ Object.extend(Prado.CallbackRequest,
if(actions && actions.length > 0)
actions.each(this.__run.bind(this,transport));
},
-
+
/**
* Prase and evaluate a Callback clien-side action
*/
@@ -143,13 +143,13 @@ Object.extend(Prado.CallbackRequest,
method.toFunction().apply(this,command[method].concat(transport));
}
catch(e)
- {
+ {
if(typeof(Logger) != "undefined")
Prado.CallbackRequest.Exception.onException(null,e);
}
}
},
-
+
/**
* Respond to Prado Callback request exceptions.
*/
@@ -159,11 +159,11 @@ Object.extend(Prado.CallbackRequest,
* Server returns 500 exception. Just log it.
*/
"on500" : function(request, transport, data)
- {
+ {
var e = request.getHeaderData(Prado.CallbackRequest.ERROR_HEADER);
Logger.error("Callback Server Error "+e.code, this.formatException(e));
},
-
+
/**
* Callback OnComplete event,logs reponse and data to console.
*/
@@ -186,7 +186,7 @@ Object.extend(Prado.CallbackRequest,
Logger.warn(msg);
}
},
-
+
/**
* Uncaught exceptions during callback response.
*/
@@ -196,10 +196,10 @@ Object.extend(Prado.CallbackRequest,
$H(e).each(function(item)
{
msg += item.key+": "+item.value+"\n";
- })
+ })
Logger.error('Uncaught Callback Client Exception:', msg);
},
-
+
/**
* Formats the exception message for display in console.
*/
@@ -219,7 +219,7 @@ Object.extend(Prado.CallbackRequest,
return msg;
}
},
-
+
/**
* @return string JSON encoded data.
*/
@@ -227,7 +227,7 @@ Object.extend(Prado.CallbackRequest,
{
return Prado.JSON.stringify(data);
},
-
+
/**
* @return mixed javascript data decoded from string using JSON decoding.
*/
@@ -238,7 +238,7 @@ Object.extend(Prado.CallbackRequest,
else
return null;
},
-
+
/**
* Dispatch a priority request, it will call abortRequestInProgress first.
*/
@@ -246,18 +246,18 @@ Object.extend(Prado.CallbackRequest,
{
//Logger.info("priority request "+callback.id)
this.abortRequestInProgress();
-
+
callback.request = new Ajax.Request(callback.url, callback.options);
callback.timeout = setTimeout(function()
{
// Logger.warn("priority timeout");
Prado.CallbackRequest.abortRequestInProgress();
},callback.options.RequestTimeOut);
-
+
this.requestInProgress = callback;
//Logger.info("dispatched "+this.requestInProgress)
},
-
+
/**
* Dispatch a normal request, no timeouts or aborting of requests.
*/
@@ -266,7 +266,7 @@ Object.extend(Prado.CallbackRequest,
// Logger.info("dispatching normal request");
new Ajax.Request(callback.url, callback.options);
},
-
+
/**
* Abort the current priority request in progress.
*/
@@ -284,7 +284,7 @@ Object.extend(Prado.CallbackRequest,
}
return false;
},
-
+
/**
* Updates the page state. It will update only if EnablePageStateUpdate and
* HasPriority options are both true.
@@ -317,44 +317,48 @@ Ajax.Responders.register({onComplete : function(request)
//Add HTTP exception respones when logger is enabled.
Event.OnLoad(function()
-{
- if(typeof Logger != "undefined")
+{
+ if(typeof Logger != "undefined")
Ajax.Responders.register(Prado.CallbackRequest.Exception);
});
/**
* Create and prepare a new callback request.
+ * Call the dispatch() method to start the callback request.
+ * <code>
+ * request = new Prado.CallbackRequest(UniqueID, callback);
+ * request.dispatch();
+ * </code>
*/
-Prado.CallbackRequest.prototype =
+Prado.CallbackRequest.prototype =
{
/**
* Callback URL, same url as the current page.
*/
url : window.location.href,
-
+
/**
* Callback options, including onXXX events.
*/
options : { },
-
+
/**
* Callback target ID. E.g. $control->getUniqueID();
*/
id : null,
-
+
/**
* Current callback request.
*/
request : null,
-
+
/**
* Prepare and inititate a callback request.
*/
initialize : function(id, options)
{
this.id = id;
-
- this.options =
+ this.options = Object.extend(
{
RequestTimeOut : 30000, // 30 second timeout.
EnablePageStateUpdate : true,
@@ -362,14 +366,87 @@ Prado.CallbackRequest.prototype =
CausesValidation : true,
ValidationGroup : null,
PostInputs : true
- }
- Object.extend(this.options, options || {});
-
+ }, options || {});
+ },
+
+ /**
+ * Sets the request parameter
+ * @param {Object} parameter value
+ */
+ setParameter : function(value)
+ {
+ this.options['params'] = value;
+ },
+
+ /**
+ * @return {Object} request paramater value.
+ */
+ getParameter : function()
+ {
+ return this.options['params'];
+ },
+
+ /**
+ * Sets the callback request timeout.
+ * @param {integer} timeout in milliseconds
+ */
+ setRequestTimeOut : function(timeout)
+ {
+ this.options['RequestTimeOut'] = timeout;
+ },
+
+ /**
+ * @return {integer} request timeout in milliseconds
+ */
+ getRequestTimeOut : function()
+ {
+ return this.options['RequestTimeOut'];
+ },
+
+ /**
+ * Set true to enable validation on callback dispatch.
+ * @param {boolean} true to validate
+ */
+ setCausesValidation : function(validate)
+ {
+ this.options['CausesValidation'] = validate;
+ },
+
+ /**
+ * @return {boolean} validate on request dispatch
+ */
+ getCausesValidation : function()
+ {
+ return this.options['CausesValidation'];
+ },
+
+ /**
+ * Sets the validation group to validate during request dispatch.
+ * @param {string} validation group name
+ */
+ setValidationGroup : function(group)
+ {
+ this.options['ValidationGroup'] = group;
+ },
+
+ /**
+ * @return {string} validation group name.
+ */
+ getValidationGroup : function()
+ {
+ return this.options['ValidationGroup'];
+ },
+
+ /**
+ * Dispatch the callback request.
+ */
+ dispatch : function()
+ {
//override parameter and postBody options.
- Object.extend(this.options,
+ Object.extend(this.options,
{
postBody : this._getPostData(),
- parameters : ''
+ parameters : ''
});
if(this.options.CausesValidation && typeof(Prado.Validation) != "undefined")
@@ -378,7 +455,7 @@ Prado.CallbackRequest.prototype =
if(Prado.Validation.validate(form,this.options.ValidationGroup,this) == false)
return;
}
-
+
if(this.options.HasPriority)
Prado.CallbackRequest.dispatchPriorityRequest(this);
else
@@ -386,7 +463,7 @@ Prado.CallbackRequest.prototype =
},
/**
- * Collects the form inputs, encode the parameters, and sets the callback
+ * Collects the form inputs, encode the parameters, and sets the callback
* target id. The resulting string is the request content body.
* @return string request body content containing post data.
*/
@@ -430,14 +507,15 @@ Prado.CallbackRequest.prototype =
*/
Prado.Callback = function(UniqueID, parameter, onSuccess, options)
{
- var callback =
+ var callback =
{
'params' : parameter || '',
'onSuccess' : onSuccess || Prototype.emptyFunction
};
Object.extend(callback, options || {});
-
- new Prado.CallbackRequest(UniqueID, callback);
+
+ request = new Prado.CallbackRequest(UniqueID, callback);
+ request.dispatch();
return false;
}
diff --git a/framework/Web/UI/ActiveControls/TBaseActiveControl.php b/framework/Web/UI/ActiveControls/TBaseActiveControl.php
index 0c95a6a5..cb944253 100644
--- a/framework/Web/UI/ActiveControls/TBaseActiveControl.php
+++ b/framework/Web/UI/ActiveControls/TBaseActiveControl.php
@@ -334,11 +334,16 @@ class TBaseActiveCallbackControl extends TBaseActiveControl
}
/**
- * Returns the javascript statement to invoke a callback request for this
- * control. Additional options for callback can be set via subproperties of
- * {@link getClientSide ClientSide} property. E.g. ClientSide.
- * OnSuccess="..."
- * @return string javascript statement to invoke a callback.
+ * Returns the javascript callback request instance. To invoke a callback
+ * request for this control call the <tt>dispatch()</tt> method on the
+ * request instance. Example code in javascript
+ * <code>
+ * request = <%= $this->mycallback->ActiveControl->Javascript %>;
+ * request.setParameter('hello');
+ * request.dispatch(); //make the callback request.
+ * </code>
+ * @return string javascript client-side callback request object (javascript
+ * code)
*/
public function getJavascript()
{