diff options
author | wei <> | 2006-06-17 01:55:05 +0000 |
---|---|---|
committer | wei <> | 2006-06-17 01:55:05 +0000 |
commit | b3ceed048bb533a00bbea542f7c12b49c8c83d9b (patch) | |
tree | 97962fc3cb6746ae404c4f1d0095834bbb0e1ac7 /framework/Web | |
parent | 6c0154fb4e292ad22667e618f598a37cc5f9d524 (diff) |
Update changes to active controls, add FT tests for active controls, add comments.
Diffstat (limited to 'framework/Web')
22 files changed, 600 insertions, 141 deletions
diff --git a/framework/Web/Javascripts/js/ajax.js b/framework/Web/Javascripts/js/ajax.js index 6e6d0afb..bfc080e9 100644 --- a/framework/Web/Javascripts/js/ajax.js +++ b/framework/Web/Javascripts/js/ajax.js @@ -33,20 +33,16 @@ this.transport.onreadystatechange=Prototype.emptyFunction;},getHeaderData:functi {var json=this.header(name);return eval('('+json+')');} 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',FIELD_POSTBACK_TARGET:'PRADO_POSTBACK_TARGET',FIELD_POSTBACK_PARAMETER:'PRADO_POSTBACK_PARAMETER',PostDataLoaders:[],DATA_HEADER:'X-PRADO-DATA',ACTION_HEADER:'X-PRADO-ACTIONS',ERROR_HEADER:'X-PRADO-ERROR',PAGESTATE_HEADER:'X-PRADO-PAGESTATE',requestInProgress:null,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',FIELD_POSTBACK_TARGET:'PRADO_POSTBACK_TARGET',FIELD_POSTBACK_PARAMETER:'PRADO_POSTBACK_PARAMETER',PostDataLoaders:[],DATA_HEADER:'X-PRADO-DATA',ACTION_HEADER:'X-PRADO-ACTIONS',ERROR_HEADER:'X-PRADO-ERROR',PAGESTATE_HEADER:'X-PRADO-PAGESTATE',requestInProgress:null,addPostLoaders:function(ids) +{this.PostDataLoaders=this.PostDataLoaders.concat(ids);},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) {try {method.toFunction().apply(this,command[method].concat(transport));} catch(e) {if(typeof(Logger)!="undefined") -Prado.CallbackRequest.Exception.onException(null,e);}} -else if(typeof(Logger)!="undefined") -{Logger.error("Error in executing callback response:","Unable to find HTML element with ID '"+id+"' before executing "+method+"().");}}}},Exception:{"on500":function(request,transport,data) +Prado.CallbackRequest.Exception.onException(null,e);}}},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";data=request.getHeaderData(Prado.CallbackRequest.ACTION_HEADER);if(data&&data.length>0) @@ -63,19 +59,17 @@ msg+=e.version+" "+e.time+"\n";return msg;}},encode:function(data) {if(typeof(data)=="string"&&data.trim().length>0) return Prado.JSON.parse(data);else return null;},dispatchPriorityRequest:function(callback) -{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)},dispatchNormalRequest:function(callback) -{Logger.info("dispatching normal request");new Ajax.Request(callback.url,callback.options);},abortRequestInProgress:function() -{inProgress=Prado.CallbackRequest.requestInProgress;Logger.info("aborting ... "+inProgress);if(inProgress) -{Logger.warn("aborted "+inProgress.id) -inProgress.request.transport.abort();clearTimeout(inProgress.timeout);Prado.CallbackRequest.requestInProgress=null;return true;} +{this.abortRequestInProgress();callback.request=new Ajax.Request(callback.url,callback.options);callback.timeout=setTimeout(function() +{Prado.CallbackRequest.abortRequestInProgress();},callback.options.RequestTimeOut);this.requestInProgress=callback;},dispatchNormalRequest:function(callback) +{new Ajax.Request(callback.url,callback.options);},abortRequestInProgress:function() +{inProgress=Prado.CallbackRequest.requestInProgress;if(inProgress) +{inProgress.request.transport.abort();clearTimeout(inProgress.timeout);Prado.CallbackRequest.requestInProgress=null;return true;} return false;},updatePageState:function(request,transport) {pagestate=$(this.FIELD_CALLBACK_PAGESTATE);if(request.options.EnablePageStateUpdate&&request.options.HasPriority&&pagestate) {data=request.header(this.PAGESTATE_HEADER);if(typeof(data)=="string"&&data.length>0) -{Logger.warn("updating page state");pagestate.value=data;} -else -{Logger.debug("Bad page state:"+data);}}}}) +pagestate.value=data;else +{if(typeof(Logger)!="undefined") +Logger.debug("Bad page state:"+data);}}}}) Ajax.Responders.register({onComplete:function(request) {if(request.options.HasPriority) Prado.CallbackRequest.abortRequestInProgress();}});Event.OnLoad(function() @@ -199,4 +193,7 @@ this.editField=this.cached_selectTag;if(this.options.loadTextURL)this.loadExtern {this.options=options;this.baseInitialize(options.ID,options.ResultPanel,options);Object.extend(this.options,{onSuccess:this.onComplete.bind(this)});},getUpdatedChoices:function() {Prado.Callback(this.options.EventTarget,this.getToken(),null,this.options);},onComplete:function(request,boundary) {result=Prado.Element.extractContent(request.responseText,boundary);if(typeof(result)=="string"&&result.length>0) -this.updateChoices(result);}});
\ No newline at end of file +this.updateChoices(result);}});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);}});
\ No newline at end of file diff --git a/framework/Web/Javascripts/js/prado.js b/framework/Web/Javascripts/js/prado.js index 65ffd1b8..d0744649 100644 --- a/framework/Web/Javascripts/js/prado.js +++ b/framework/Web/Javascripts/js/prado.js @@ -267,10 +267,15 @@ setTimeout(function(){obj.focus();},100);return false;},replace:function(element {if(boundary) {result=Prado.Element.extractContent(transport.responseText,boundary);if(result!=null) content=result;} -method.toFunction().apply(this,[element,content]);},extractContent:function(text,boundary) +if(typeof(element)=="string") +{if($(element)) +method.toFunction().apply(this,[element,content]);} +else +{method.toFunction().apply(this,[content]);}},extractContent:function(text,boundary) {f=RegExp('(<!--'+boundary+'-->)([\\s\\S\\w\\W]*)(<!--//'+boundary+'-->)',"m");result=text.match(f);if(result&&result.length>=2) return result[2];else -return null;}} +return null;},evaluateScript:function(content) +{content.evalScripts();}} Prado.Element.Selection={inputValue:function(el,value) {switch(el.type.toLowerCase()) {case'checkbox':case'radio':return el.checked=value;}},selectValue:function(el,value) diff --git a/framework/Web/Javascripts/prado/activecontrols3.js b/framework/Web/Javascripts/prado/activecontrols3.js index 4be2779a..6fbde405 100644 --- a/framework/Web/Javascripts/prado/activecontrols3.js +++ b/framework/Web/Javascripts/prado/activecontrols3.js @@ -42,3 +42,19 @@ Prado.WebUI.TAutoComplete = Class.extend(Autocompleter.Base, this.updateChoices(result);
}
});
+
+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);
+ }
+});
diff --git a/framework/Web/Javascripts/prado/ajax3.js b/framework/Web/Javascripts/prado/ajax3.js index 1e832889..adf8534a 100644 --- a/framework/Web/Javascripts/prado/ajax3.js +++ b/framework/Web/Javascripts/prado/ajax3.js @@ -19,7 +19,7 @@ Object.extend(Ajax.Request.prototype, Prado.CallbackRequest.updatePageState(this,transport);
Ajax.Responders.dispatch('on' + transport.status, this, transport, json);
Prado.CallbackRequest.dispatchActions(transport,this.getHeaderData(Prado.CallbackRequest.ACTION_HEADER));
-
+
(this.options['on' + this.transport.status]
|| this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
|| Prototype.emptyFunction)(transport, json);
@@ -57,10 +57,7 @@ Object.extend(Ajax.Request.prototype, catch (e)
{
if(typeof(json) == "string")
- {
- Logger.info("using json")
return Prado.CallbackRequest.decode(json);
- }
}
}
});
@@ -118,6 +115,14 @@ Object.extend(Prado.CallbackRequest, requestInProgress : null,
/**
+ * Add ids of inputs element to post in the request.
+ */
+ addPostLoaders : function(ids)
+ {
+ this.PostDataLoaders = this.PostDataLoaders.concat(ids);
+ },
+
+ /**
* Dispatch callback response actions.
*/
dispatchActions : function(transport,actions)
@@ -133,26 +138,14 @@ Object.extend(Prado.CallbackRequest, {
for(var method in command)
{
- if(command[method][0])
+ try
{
- var id = command[method][0];
- if($(id) || id.indexOf("[]") > -1)
- {
- try
- {
- method.toFunction().apply(this,command[method].concat(transport));
- }
- catch(e)
- {
- if(typeof(Logger) != "undefined")
- Prado.CallbackRequest.Exception.onException(null,e);
- }
- }
- else if(typeof(Logger) != "undefined")
- {
- Logger.error("Error in executing callback response:",
- "Unable to find HTML element with ID '"+id+"' before executing "+method+"().");
- }
+ method.toFunction().apply(this,command[method].concat(transport));
+ }
+ catch(e)
+ {
+ if(typeof(Logger) != "undefined")
+ Prado.CallbackRequest.Exception.onException(null,e);
}
}
},
@@ -251,18 +244,18 @@ Object.extend(Prado.CallbackRequest, */
dispatchPriorityRequest : function(callback)
{
- Logger.info("priority request "+callback.id)
+ //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");
+ // Logger.warn("priority timeout");
Prado.CallbackRequest.abortRequestInProgress();
},callback.options.RequestTimeOut);
this.requestInProgress = callback;
- Logger.info("dispatched "+this.requestInProgress)
+ //Logger.info("dispatched "+this.requestInProgress)
},
/**
@@ -270,7 +263,7 @@ Object.extend(Prado.CallbackRequest, */
dispatchNormalRequest : function(callback)
{
- Logger.info("dispatching normal request");
+ // Logger.info("dispatching normal request");
new Ajax.Request(callback.url, callback.options);
},
@@ -280,10 +273,10 @@ Object.extend(Prado.CallbackRequest, abortRequestInProgress : function()
{
inProgress = Prado.CallbackRequest.requestInProgress;
- Logger.info("aborting ... "+inProgress);
+ //Logger.info("aborting ... "+inProgress);
if(inProgress)
{
- Logger.warn("aborted "+inProgress.id)
+ // Logger.warn("aborted "+inProgress.id)
inProgress.request.transport.abort();
clearTimeout(inProgress.timeout);
Prado.CallbackRequest.requestInProgress = null;
@@ -303,13 +296,11 @@ Object.extend(Prado.CallbackRequest, {
data = request.header(this.PAGESTATE_HEADER);
if(typeof(data) == "string" && data.length > 0)
- {
- Logger.warn("updating page state");
pagestate.value = data;
- }
else
{
- Logger.debug("Bad page state:"+data);
+ if(typeof(Logger) != "undefined")
+ Logger.debug("Bad page state:"+data);
}
}
}
diff --git a/framework/Web/Javascripts/prado/element.js b/framework/Web/Javascripts/prado/element.js index 0ff0e8fa..5c76d4e6 100644 --- a/framework/Web/Javascripts/prado/element.js +++ b/framework/Web/Javascripts/prado/element.js @@ -71,7 +71,15 @@ Prado.Element = if(result != null)
content = result;
}
- method.toFunction().apply(this,[element,content]);
+ if(typeof(element) == "string")
+ {
+ if($(element))
+ method.toFunction().apply(this,[element,content]);
+ }
+ else
+ {
+ method.toFunction().apply(this,[content]);
+ }
},
extractContent : function(text, boundary)
@@ -82,6 +90,11 @@ Prado.Element = return result[2];
else
return null;
+ },
+
+ evaluateScript : function(content)
+ {
+ content.evalScripts();
}
}
diff --git a/framework/Web/UI/ActiveControls/TActiveButton.php b/framework/Web/UI/ActiveControls/TActiveButton.php index f4bfc678..81744057 100644 --- a/framework/Web/UI/ActiveControls/TActiveButton.php +++ b/framework/Web/UI/ActiveControls/TActiveButton.php @@ -7,9 +7,11 @@ * @copyright Copyright © 2006 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Revision: $ $Date: $
- * @package System.Web.UI.WebControls
+ * @package System.Web.UI.ActiveControls
*/
+Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
+
/**
* TActiveButton is the active control counter part to TButton.
*
@@ -17,7 +19,7 @@ * callback request is initiated.
*
* The {@link onCallback OnCallback} event is raised during a callback request
- * and it is raise before the {@link onClick OnClick} event.
+ * and it is raise <b>after</b> the {@link onClick OnClick} event.
*
* When the {@link TBaseActiveCallbackControl::setEnableUpdate ActiveControl.EnableUpdate}
* property is true, changing the {@link setText Text} property during callback request
@@ -28,7 +30,7 @@ * @package System.Web.UI.ActiveControls
* @since 3.0
*/
-class TActiveButton extends TButton implements ICallbackEventHandler
+class TActiveButton extends TButton implements ICallbackEventHandler, IActiveControl
{
/**
* Creates a new callback control, sets the adapter to
@@ -53,15 +55,15 @@ class TActiveButton extends TButton implements ICallbackEventHandler * Raises the callback event. This method is required by {@link
* ICallbackEventHandler} interface. If {@link getCausesValidation
* CausesValidation} is true, it will invoke the page's {@link TPage::
- * validate validate} method first. It will raise {@link onCallback
- * OnCallback} event first and then the {@link onClick OnClick} event.
+ * validate validate} method first. It will raise {@link onClick
+ * OnClick} event first and then the {@link onCallback OnCallback} event.
* This method is mainly used by framework and control developers.
* @param TCallbackEventParameter the event parameter
*/
public function raiseCallbackEvent($param)
{
- $this->onCallback($param);
$this->raisePostBackEvent($param);
+ $this->onCallback($param);
}
/**
@@ -115,16 +117,6 @@ class TActiveButton extends TButton implements ICallbackEventHandler {
return 'Prado.WebUI.TActiveButton';
}
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TActiveButton';
- }
}
?>
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php index ab842976..de6310a6 100644 --- a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php +++ b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php @@ -1,26 +1,68 @@ <?php
+/**
+ * TActiveControlAdapter and TCallbackPageStateTracker class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright © 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ : $
+ * @package System.Web.UI.ActiveControls
+ */
+
/*
- * Created on 29/04/2006
+ * Load common active control options.
*/
Prado::using('System.Web.UI.ActiveControls.TBaseActiveControl');
+/**
+ * TActiveControlAdapter class.
+ *
+ * Customize the parent TControl class for active control classes.
+ * TActiveControlAdapter instantiates a common base active control class
+ * throught the {@link getBaseActiveControl BaseActiveControl} property.
+ * The type of BaseActiveControl can be provided in the second parameter in the
+ * constructor. Default is TBaseActiveControl or TBaseActiveCallbackControl if
+ * the control adapted implements ICallbackEventHandler.
+ *
+ * TActiveControlAdapter will tracking viewstate changes to update the
+ * corresponding client-side properties.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ Sun Jun 18 20:35:34 EST 2006 $
+ * @package System.Web.UI.ActiveControls
+ * @since 3.0
+ */
class TActiveControlAdapter extends TControlAdapter
{
- private static $_renderedPosts = false;
-
+ /**
+ * @var string base active control class name.
+ */
private $_activeControlType;
-
+ /**
+ * @var TBaseActiveControl base active control instance.
+ */
private $_baseActiveControl;
-
+ /**
+ * @var TCallbackPageStateTracker view state tracker.
+ */
private $_stateTracker;
- public function __construct($control, $baseCallbackClass=null)
+ /**
+ * Constructor.
+ * @param IActiveControl active control to adapt.
+ * @param string Base active control class name.
+ */
+ public function __construct(IActiveControl $control, $baseCallbackClass=null)
{
parent::__construct($control);
- $this->setBaseControlType($baseCallbackClass);
+ $this->setBaseControlClass($baseCallbackClass);
}
- private function setBaseControlType($type)
+ /**
+ * @param string base active control instance
+ */
+ protected function setBaseControlClass($type)
{
if(is_null($type))
{
@@ -30,22 +72,21 @@ class TActiveControlAdapter extends TControlAdapter $this->_activeControlType = 'TBaseActiveControl';
}
else
- {
$this->_activeControlType = $type;
- }
}
/**
- * Render the callback request post data loaders once only.
+ * Renders the callback client scripts.
*/
public function render($writer)
{
$this->renderCallbackClientScripts();
parent::render($writer);
- if($this->getPage()->getIsCallback())
- $this->getPage()->getCallbackClient()->replace($this->getControl(), $writer);
}
+ /**
+ * Register the callback clientscripts and sets the post loader IDs.
+ */
protected function renderCallbackClientScripts()
{
$cs = $this->getPage()->getClientScript();
@@ -54,11 +95,14 @@ class TActiveControlAdapter extends TControlAdapter {
$cs->registerPradoScript('ajax');
$options = TJavascript::encode($this->getPage()->getPostDataLoaders(),false);
- $script = "Prado.CallbackRequest.PostDataLoaders = {$options};";
+ $script = "Prado.CallbackRequest.addPostLoaders({$options});";
$cs->registerEndScript($key, $script);
}
}
+ /**
+ * @return TBaseActiveControl Common active control options.
+ */
public function getBaseActiveControl()
{
if(is_null($this->_baseActiveControl))
@@ -69,6 +113,9 @@ class TActiveControlAdapter extends TControlAdapter return $this->_baseActiveControl;
}
+ /**
+ * @return boolean true if the viewstate needs to be tracked.
+ */
protected function getIsTrackingPageState()
{
if($this->getPage()->getIsCallback())
@@ -83,6 +130,10 @@ class TActiveControlAdapter extends TControlAdapter return false;
}
+ /**
+ * Loads additional persistent control state. Starts viewstate tracking
+ * if necessary.
+ */
public function loadState()
{
if($this->getIsTrackingPageState())
@@ -93,6 +144,10 @@ class TActiveControlAdapter extends TControlAdapter parent::loadState();
}
+ /**
+ * Saves additional persistent control state. Respond to viewstate changes
+ * if necessary.
+ */
public function saveState()
{
if(!is_null($this->_stateTracker)
@@ -104,6 +159,18 @@ class TActiveControlAdapter extends TControlAdapter }
}
+/**
+ * TCallbackPageStateTracker class.
+ *
+ * Tracking changes to the page state during callback.
+ *
+ * @todo Complete this class! (Wei)
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ Sun Jun 18 20:51:25 EST 2006 $
+ * @package System
+ * @since 3.0
+ */
class TCallbackPageStateTracker
{
private $_states = array('Visible', 'Enabled', 'Attributes', 'Style', 'TabIndex', 'ToolTip', 'AccessKey');
diff --git a/framework/Web/UI/ActiveControls/TActiveLabel.php b/framework/Web/UI/ActiveControls/TActiveLabel.php index c1cb1fba..f54e0b98 100644 --- a/framework/Web/UI/ActiveControls/TActiveLabel.php +++ b/framework/Web/UI/ActiveControls/TActiveLabel.php @@ -25,7 +25,7 @@ * @package System.Web.UI.ActiveControls
* @since 3.0
*/
-class TActiveLabel extends TLabel
+class TActiveLabel extends TLabel implements IActiveControl
{
/**
* Creates a new callback control, sets the adapter to
diff --git a/framework/Web/UI/ActiveControls/TActivePageAdapter.php b/framework/Web/UI/ActiveControls/TActivePageAdapter.php index 77d8a7fe..90c64820 100644 --- a/framework/Web/UI/ActiveControls/TActivePageAdapter.php +++ b/framework/Web/UI/ActiveControls/TActivePageAdapter.php @@ -1,6 +1,6 @@ <?php
/**
- * TActivePageAdapter class file.
+ * TActivePageAdapter, TCallbackEventParameter, TCallbackErrorHandler and TInvalidCallbackException class file.
*
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
* @link http://www.pradosoft.com/
@@ -9,11 +9,16 @@ * @version $Revision: $ $Date: $
* @package System.Web.UI.ActiveControls
*/
-
+
+/**
+ * Load callback response adapter class.
+ */
+Prado::using('System.Web.UI.ActiveControls.TCallbackResponseAdapter');
+
/**
* TActivePageAdapter class.
*
- * Callback request page handler.
+ * Callback request handler.
*
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
* @version $Revision: $ $Date: $
@@ -22,9 +27,21 @@ */
class TActivePageAdapter extends TControlAdapter
{
+ /**
+ * Callback response data header name.
+ */
const CALLBACK_DATA_HEADER = 'X-PRADO-DATA';
+ /**
+ * Callback response client-side action header name.
+ */
const CALLBACK_ACTION_HEADER = 'X-PRADO-ACTIONS';
+ /**
+ * Callback error header name.
+ */
const CALLBACK_ERROR_HEADER = 'X-PRADO-ERROR';
+ /**
+ * Callback page state header name.
+ */
const CALLBACK_PAGESTATE_HEADER = 'X-PRADO-PAGESTATE';
/**
@@ -57,6 +74,7 @@ class TActivePageAdapter extends TControlAdapter /**
* Process the callback request.
+ * @param THtmlWriter html content writer.
*/
public function processCallbackEvent($writer)
{
@@ -64,6 +82,9 @@ class TActivePageAdapter extends TControlAdapter $this->raiseCallbackEvent();
}
+ /**
+ * Trap errors and exceptions to be handled by TCallbackErrorHandler.
+ */
protected function trapCallbackErrorsExceptions()
{
$this->getApplication()->setErrorHandler(new TCallbackErrorHandler);
@@ -71,6 +92,7 @@ class TActivePageAdapter extends TControlAdapter /**
* Render the callback response.
+ * @param THtmlWriter html content writer.
*/
public function renderCallbackResponse($writer)
{
@@ -81,14 +103,12 @@ class TActivePageAdapter extends TControlAdapter /**
* Renders the callback response by adding additional callback data and
* javascript actions in the header and page state if required.
+ * @param THtmlWriter html content writer.
*/
protected function renderResponse($writer)
{
$response = $this->getResponse();
- $executeJavascript = $this->getCallbackClientHandler()->getClientFunctionsToExecute()->toArray();
- $actions = TJavascript::jsonEncode($executeJavascript);
- $response->appendHeader(self::CALLBACK_ACTION_HEADER.': '.$actions);
-
+
//send response data in header
if($response->getHasAdapter())
{
@@ -109,12 +129,29 @@ class TActivePageAdapter extends TControlAdapter $response->appendHeader(self::CALLBACK_PAGESTATE_HEADER.': '.$pagestate);
}
}
+
+ //safari must receive at least 1 byte of data.
+ $writer->write(" ");
+
+ //output the end javascript
+ if($this->getPage()->getClientScript()->hasEndScripts())
+ {
+ $writer = $response->createHtmlWriter();
+ $this->getPage()->getClientScript()->renderEndScripts($writer);
+ $this->getPage()->getCallbackClient()->evaluateScript($writer);
+ }
+
+ //output the actions
+ $executeJavascript = $this->getCallbackClientHandler()->getClientFunctionsToExecute()->toArray();
+ $actions = TJavascript::jsonEncode($executeJavascript);
+ $response->appendHeader(self::CALLBACK_ACTION_HEADER.': '.$actions);
+
}
/**
* Trys to find the callback event handler and raise its callback event.
- * @throws TInvalidCallbackRequestException if call back target is not found.
- * @throws TInvalidCallbackHandlerException if the requested target does not
+ * @throws TInvalidCallbackException if call back target is not found.
+ * @throws TInvalidCallbackException if the requested target does not
* implement ICallbackEventHandler.
*/
private function raiseCallbackEvent()
@@ -129,13 +166,14 @@ class TActivePageAdapter extends TControlAdapter }
else
{
- throw new TInvalidCallbackHandlerException($callbackHandler->getUniqueID());
+ throw new TInvalidCallbackException(
+ 'callback_invalid_handler', $callbackHandler->getUniqueID());
}
}
else
{
$target = $this->getRequest()->itemAt(TPage::FIELD_CALLBACK_TARGET);
- throw new TInvalidCallbackRequestException($target);
+ throw new TInvalidCallbackException('callback_invalid_target', $target);
}
}
@@ -164,7 +202,7 @@ class TActivePageAdapter extends TControlAdapter }
/**
- * Callback parameter is decoded assuming JSON encoding.
+ * Gets callback parameter. JSON encoding is assumed.
* @return string postback event parameter
*/
public function getCallbackEventParameter()
@@ -187,7 +225,7 @@ class TActivePageAdapter extends TControlAdapter }
/**
- * Gets the callback client script handler that allows javascript functions
+ * Gets the callback client script handler. It handlers the javascript functions
* to be executed during the callback response.
* @return TCallbackClientScript callback client handler.
*/
@@ -267,16 +305,34 @@ class TCallbackEventParameter extends TEventParameter }
}
+/**
+ * TCallbackErrorHandler class.
+ *
+ * Captures errors and exceptions and send them back during callback response.
+ * When the application is in debug mode, the error and exception stack trace
+ * are shown. A TJavascriptLogger must be present on the client-side to view
+ * the error stack trace.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ Sun Jun 18 19:11:47 EST 2006 $
+ * @package System.Web.UI.ActiveControls
+ * @since 3.0
+ */
class TCallbackErrorHandler extends TErrorHandler
{
+ /**
+ * Displays the exceptions to the client-side TJavascriptLogger.
+ * A HTTP 500 status code is sent and the stack trace is sent as JSON encoded.
+ * @param Exception exception details.
+ */
protected function displayException($exception)
{
if($this->getApplication()->getMode()===TApplication::STATE_DEBUG)
{
$response = $this->getApplication()->getResponse();
- $data = TJavascript::jsonEncode($this->getExceptionData($exception));
+ $trace = TJavascript::jsonEncode($this->getExceptionStackTrace($exception));
$response->appendHeader('HTTP/1.0 500 Internal Error');
- $response->appendHeader(TActivePageAdapter::CALLBACK_ERROR_HEADER.': '.$data);
+ $response->appendHeader(TActivePageAdapter::CALLBACK_ERROR_HEADER.': '.$trace);
}
else
{
@@ -286,9 +342,13 @@ class TCallbackErrorHandler extends TErrorHandler $this->getApplication()->getResponse()->flush();
}
- private function getExceptionData($exception)
+ /**
+ * @param Exception exception details.
+ * @return array exception stack trace details.
+ */
+ private function getExceptionStackTrace($exception)
{
- $data['code']=$exception->getCode() > 0 ? $exception->getCode() : 505;
+ $data['code']=$exception->getCode() > 0 ? $exception->getCode() : 500;
$data['file']=$exception->getFile();
$data['line']=$exception->getLine();
$data['trace']=$exception->getTrace();
@@ -310,13 +370,16 @@ class TCallbackErrorHandler extends TErrorHandler }
}
-class TInvalidCallbackHandlerException extends TException
+/**
+ * TInvalidCallbackException class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ Sun Jun 18 19:17:13 EST 2006 $
+ * @package System.Web.UI.ActiveControls
+ * @since 3.0
+ */
+class TInvalidCallbackException extends TException
{
-
}
-class TInvalidCallbackRequestException extends TException
-{
-}
-
?>
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActivePanel.php b/framework/Web/UI/ActiveControls/TActivePanel.php index db1d8a7d..787b65d3 100644 --- a/framework/Web/UI/ActiveControls/TActivePanel.php +++ b/framework/Web/UI/ActiveControls/TActivePanel.php @@ -1,9 +1,37 @@ <?php
-/*
- * Created on 5/05/2006
+/**
+ * TActivePanel file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright © 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version : :
+ * @package System.Web.UI.ActiveControls
*/
-class TActivePanel extends TPanel
+/**
+ * TActivePanel is the TPanel active control counterpart.
+ *
+ * TActivePanel allows the client-side panel contents to be updated during a
+ * callback response using the {@link flush} method.
+ *
+ * Example: Assume $param is an instance of TCallbackEventParameter attached to
+ * the OnCallback event a TCallback with ID "callback1", and
+ * "panel1" is the ID of a TActivePanel.
+ * <code>
+ * function callback1_requested($sender, $param)
+ * {
+ * $this->panel1->flush($param->getOutput());
+ * }
+ * </code>
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ Sun Jun 18 01:23:54 EST 2006 $
+ * @package System.Web.UI.ActiveControls
+ * @since 3.0
+ */
+class TActivePanel extends TPanel implements IActiveControl
{
/**
* Creates a new callback control, sets the adapter to
@@ -16,10 +44,26 @@ class TActivePanel extends TPanel $this->setAdapter(new TActiveControlAdapter($this));
}
+ /**
+ * @return TBaseActiveControl standard active control options.
+ */
public function getActiveControl()
{
return $this->getAdapter()->getBaseActiveControl();
}
+
+ /**
+ * Renders and replaces the panel's content on the client-side.
+ * @param THtmlWriter html writer
+ */
+ public function flush($writer)
+ {
+ if($this->getActiveControl()->canUpdateClientSide())
+ {
+ $this->render($writer);
+ $this->getPage()->getCallbackClient()->replaceContent($this,$writer);
+ }
+ }
}
?>
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveTextBox.php b/framework/Web/UI/ActiveControls/TActiveTextBox.php index ece08e11..2e207f92 100644 --- a/framework/Web/UI/ActiveControls/TActiveTextBox.php +++ b/framework/Web/UI/ActiveControls/TActiveTextBox.php @@ -1,9 +1,30 @@ <?php
-/*
- * Created on 6/05/2006
+/**
+ * TActiveTextBox class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright © 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ : $
+ * @package System.Web.UI.ActiveControls
*/
-class TActiveTextBox extends TTextBox
+/**
+ * TActiveTextBox class.
+ *
+ * TActiveTextBox allows the {@link setText Text} property of the textbox to
+ * be changed during callback. When {@link setAutoPostBack AutoPostBack} property
+ * is true, changes to the textbox contents will perform a callback request causing
+ * {@link onTextChanged OnTextChange} to be fired first followed by {@link onCallback OnCallback}
+ * event.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ Sun Jun 18 20:05:16 EST 2006 $
+ * @package System.Web.UI.ActiveControls
+ * @since 3.0
+ */
+class TActiveTextBox extends TTextBox implements ICallbackEventHandler, IActiveControl
{
/**
* Creates a new callback control, sets the adapter to
@@ -15,7 +36,10 @@ class TActiveTextBox extends TTextBox parent::__construct();
$this->setAdapter(new TActiveControlAdapter($this));
}
-
+
+ /**
+ * @return TBaseActiveCallbackControl standard callback control options.
+ */
public function getActiveControl()
{
return $this->getAdapter()->getBaseActiveControl();
@@ -31,6 +55,43 @@ class TActiveTextBox extends TTextBox if($this->getActiveControl()->canUpdateClientSide() && $this->getHasLoadedPostData())
$this->getPage()->getCallbackClient()->setValue($this, $value);
}
+
+ /**
+ * Raises the callback event. This method is required by {@link
+ * ICallbackEventHandler} interface. If {@link getCausesValidation
+ * CausesValidation} is true, it will invoke the page's {@link TPage::
+ * validate validate} method first. It will raise {@link onTextChanged
+ * onTextChanged} event first and then the {@link onCallback OnCallback} event.
+ * This method is mainly used by framework and control developers.
+ * @param TCallbackEventParameter the event parameter
+ */
+ public function raiseCallbackEvent($param)
+ {
+ $this->raisePostDataChangedEvent($param);
+ $this->onCallback($param);
+ }
+
+ /**
+ * This method is invoked when a callback is requested. The method raises
+ * 'OnCallback' event to fire up the event handlers. If you override this
+ * method, be sure to call the parent implementation so that the event
+ * handler can be invoked.
+ * @param TCallbackEventParameter event parameter to be passed to the event handlers
+ */
+ public function onCallback($param)
+ {
+ $this->raiseEvent('OnCallback', $this, $param);
+ }
+
+ /**
+ * Renders the javascript for textbox.
+ */
+ protected function renderClientControlScript($writer)
+ {
+ $writer->addAttribute('id',$this->getClientID());
+ $this->getActiveControl()->registerCallbackClientScript(
+ $this->getClientClassName(), $this->getPostBackOptions());
+ }
/**
* Gets the name of the javascript class responsible for performing postback for this control.
diff --git a/framework/Web/UI/ActiveControls/TAutoComplete.php b/framework/Web/UI/ActiveControls/TAutoComplete.php index 63b1d089..601894ff 100644 --- a/framework/Web/UI/ActiveControls/TAutoComplete.php +++ b/framework/Web/UI/ActiveControls/TAutoComplete.php @@ -3,7 +3,7 @@ * Created on 7/05/2006
*/
-class TAutoComplete extends TActiveTextBox implements ICallbackEventHandler, INamingContainer
+class TAutoComplete extends TActiveTextBox implements INamingContainer
{
/**
* @var ITemplate template for repeater items
diff --git a/framework/Web/UI/ActiveControls/TBaseActiveControl.php b/framework/Web/UI/ActiveControls/TBaseActiveControl.php index 13d953c8..71d50a67 100644 --- a/framework/Web/UI/ActiveControls/TBaseActiveControl.php +++ b/framework/Web/UI/ActiveControls/TBaseActiveControl.php @@ -10,6 +10,8 @@ * @package System.Web.UI.ActiveControls
*/
+Prado::using('System.Web.UI.ActiveControls.TCallbackClientSideOptions');
+
/**
* TBaseActiveControl class provided additional basic property for every
* active control. An instance of TBaseActiveControl or its decendent
@@ -163,42 +165,66 @@ class TBaseActiveCallbackControl extends TBaseActiveControl }
return $client;
}
+
+ /**
+ * Sets the client side options. Can only be set when client side is null.
+ * @param TCallbackClientSideOptions client side options.
+ */
+ public function setClientSide($client)
+ {
+ if(is_null($this->getOption('ClientSide')))
+ $this->setOption('ClientSide', $client);
+ else
+ throw new TConfigurationException(
+ 'active_controls_client_side_exists', $this->getControl()->getID());
+ }
/**
* @return TCallbackClientSideOptions callback client-side options.
*/
protected function createClientSideOptions()
{
- if(($id=$this->getCallbackOptionID())!==''
- && ($control=$this->getControl()->findControl($id))!==null)
- {
- if($control instanceof TCallbackOptions)
- return $control->getClientSide();
- }
return new TCallbackClientSideOptions;
}
/**
- * Sets the ID of a TCallbackOptions component to duplicate the client-side
+ * Sets default callback options. Takes the ID of a TCallbackOptions
+ * component to duplicate the client-side
* options for this control. The {@link getClientSide ClientSide}
* subproperties has precendent over the CallbackOptions property.
* @param string ID of a TCallbackOptions control from which ClientSide
* options are cloned.
*/
- public function setCallbackOptionID($value)
+ public function setCallbackOptions($value)
{
$this->setOption('CallbackOptions', $value, '');
}
/**
* @return string ID of a TCallbackOptions control from which ClientSide
- * options are cloned.
+ * options are duplicated.
*/
- public function getCallbackOptionID()
+ public function getCallbackOptions()
{
return $this->getOption('CallbackOptions', '');
}
+ /**
+ * Returns an array of default callback client-side options. The default options
+ * are obtained from the client-side options of a TCallbackOptions control with
+ * ID specified by {@link setCallbackOptionsID CallbackOptionsID}.
+ * @return array list of default callback client-side options.
+ */
+ protected function getDefaultClientSideOptions()
+ {
+ if(($id=$this->getCallbackOptions())!==''
+ && ($control=$this->getControl()->findControl($id))!==null
+ && $control instanceof TCallbackOptions)
+ return $control->getClientSide()->getOptions()->toArray();
+ else
+ return array();
+ }
+
/**
* @return boolean whether callback event trigger by this button will cause
* input validation, default is true
@@ -255,7 +281,8 @@ class TBaseActiveCallbackControl extends TBaseActiveControl */
protected function getClientSideOptions()
{
- $options = $this->getClientSide()->getOptions()->toArray();
+ $default = $this->getDefaultClientSideOptions();
+ $options = array_merge($default,$this->getClientSide()->getOptions()->toArray());
$validate = $this->getCausesValidation();
$options['CausesValidation']= $validate ? '' : false;
$options['ValidationGroup']=$this->getValidationGroup();
diff --git a/framework/Web/UI/ActiveControls/TCallback.php b/framework/Web/UI/ActiveControls/TCallback.php index c42b2cd7..3c7d70c5 100644 --- a/framework/Web/UI/ActiveControls/TCallback.php +++ b/framework/Web/UI/ActiveControls/TCallback.php @@ -35,7 +35,7 @@ * @package System.Web.UI.ActiveControls
* @since 3.0
*/
-class TCallback extends TControl implements ICallbackEventHandler
+class TCallback extends TControl implements ICallbackEventHandler, IActiveControl
{
/**
* Creates a new callback control, sets the adapter to
diff --git a/framework/Web/UI/ActiveControls/TCallbackClientScript.php b/framework/Web/UI/ActiveControls/TCallbackClientScript.php index 5d317c8a..d83bf90a 100644 --- a/framework/Web/UI/ActiveControls/TCallbackClientScript.php +++ b/framework/Web/UI/ActiveControls/TCallbackClientScript.php @@ -313,7 +313,7 @@ class TCallbackClientScript extends TApplicationComponent * @see insertBefore
* @see insertAfter
*/
- public function replace($element, $content, $method="Element.replace", $boundary=null)
+ protected function replace($element, $content, $method="Element.replace", $boundary=null)
{
if($content instanceof TControl)
{
@@ -325,12 +325,31 @@ class TCallbackClientScript extends TApplicationComponent $boundary = $this->getResponseContentBoundary($content);
$content = null;
}
-
+
$this->callClientFunction('Prado.Element.replace',
array($element, $method, $content, $boundary));
}
/**
+ * Replace the content of an element with new content contained in writer.
+ * @param TControl|string control element or HTML element id.
+ * @param THtmlWriter writer for the content.
+ */
+ public function replaceContent($element,$writer)
+ {
+ $this->replace($element, $writer);
+ }
+
+ /**
+ * Evaluate a block of javascript enclosed in a boundary.
+ * @param THtmlWriter writer for the content.
+ */
+ public function evaluateScript($writer)
+ {
+ $this->replace(null, $writer, 'Prado.Element.evaluateScript');
+ }
+
+ /**
* Renders the control and return the content boundary from
* TCallbackResponseWriter. This method should only be used by framework
* component developers.
diff --git a/framework/Web/UI/ActiveControls/TCallbackClientSideOptions.php b/framework/Web/UI/ActiveControls/TCallbackClientSideOptions.php index 3f54e013..e8c2dc26 100644 --- a/framework/Web/UI/ActiveControls/TCallbackClientSideOptions.php +++ b/framework/Web/UI/ActiveControls/TCallbackClientSideOptions.php @@ -266,11 +266,17 @@ class TCallbackClientSideOptions extends TClientSideOptions return is_null($option) ? true : $option;
}
+ /**
+ * @return string post back target ID
+ */
public function getPostBackTarget()
{
return $this->getOption('EventTarget');
}
+ /**
+ * @param string post back target ID
+ */
public function setPostBackTarget($value)
{
if($value instanceof TControl)
@@ -278,17 +284,21 @@ class TCallbackClientSideOptions extends TClientSideOptions $this->setOption('EventTarget', $value);
}
+ /**
+ * @return string post back event parameter.
+ */
public function getPostBackParameter()
{
return $this->getOption('EventParameter');
}
+ /**
+ * @param string post back event parameter.
+ */
public function setPostBackParameter($value)
{
$this->setOption('EventParameter', $value);
}
-
-
}
?>
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TCallbackOptions.php b/framework/Web/UI/ActiveControls/TCallbackOptions.php index fc0becb5..588cbf8a 100644 --- a/framework/Web/UI/ActiveControls/TCallbackOptions.php +++ b/framework/Web/UI/ActiveControls/TCallbackOptions.php @@ -1,10 +1,31 @@ <?php
-/*
- * Created on 12/05/2006
+/**
+ * TCallbackOptions component class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright © 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ : $
+ * @package System.Web.UI.ActiveControls
*/
+/**
+ * TCallbackOptions class.
+ *
+ * TCallbackOptions allows common set of callback client-side options
+ * to be attached to other active controls.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ Sun Jun 18 08:10:50 EST 2006 $
+ * @package System.Web.UI.ActiveControls
+ * @since 3.0
+ */
class TCallbackOptions extends TControl
{
+ /**
+ * @var TCallbackClientSideOptions client side callback options.
+ */
private $_clientSide;
/**
@@ -28,7 +49,6 @@ class TCallbackOptions extends TControl {
return new TCallbackClientSideOptions;
}
-
}
?>
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TCallbackResponseAdapter.php b/framework/Web/UI/ActiveControls/TCallbackResponseAdapter.php index d1ec67ad..1f11f973 100755 --- a/framework/Web/UI/ActiveControls/TCallbackResponseAdapter.php +++ b/framework/Web/UI/ActiveControls/TCallbackResponseAdapter.php @@ -1,14 +1,48 @@ <?php +/** + * TCallbackResponseAdapter and TCallbackResponseWriter class file. + * + * @author Wei Zhuo <weizhuo[at]gamil[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version 3.0 + * @package System.Web.UI.ActiveControls + */ /** + * TCallbackResponseAdapter alters the THttpResponse's outputs. * + * A TCallbackResponseWriter is used instead of the TTextWrite when + * createHtmlWriter is called. Each call to createHtmlWriter will create + * a new TCallbackResponseWriter. When flushContent() is called each + * instance of TCallbackResponseWriter's content is flushed. + * + * The callback response data can be set using the {@link setResponseData ResponseData} + * property. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @version $Revision: $ Sun Jun 18 07:52:14 EST 2006 $ + * @package System.Web.UI.ActiveControls + * @since 3.0 */ class TCallbackResponseAdapter extends THttpResponseAdapter { + /** + * @TCallbackResponseWriter[] list of writers. + */ private $_writers=array(); - + /** + * @mixed callback response data. + */ private $_data; + /** + * Returns a new instance of THtmlWriter. + * An instance of TCallbackResponseWriter is created to hold the content. + * @param string writer class name. + * @param THttpResponse http response handler. + */ public function createNewHtmlWriter($type,$response) { $writer = new TCallbackResponseWriter(); @@ -16,6 +50,9 @@ class TCallbackResponseAdapter extends THttpResponseAdapter return parent::createNewHtmlWriter($type,$writer); } + /** + * Flushes the contents in the writers. + */ public function flushContent() { foreach($this->_writers as $writer) @@ -23,36 +60,75 @@ class TCallbackResponseAdapter extends THttpResponseAdapter parent::flushContent(); } + /** + * @param mixed callback response data. + */ public function setResponseData($data) { $this->_data = $data; } + /** + * @return mixed callback response data. + */ public function getResponseData() { return $this->_data; } } +/** + * TCallbackResponseWriter class. + * + * TCallbackResponseWriter class enclosed a chunck of content within a + * html comment boundary. This allows multiple chuncks of content to return + * in the callback response and update multiple HTML elements. + * + * The {@link setBoundary Boundary} property sets boundary identifier in the + * HTML comment that forms the boundary. By default, the boundary identifier + * is generated from the object instance ID. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @version $Revision: $ Sun Jun 18 08:02:21 EST 2006 $ + * @package System.Web.UI.ActiveControls + * @since 3.0 + */ class TCallbackResponseWriter extends TTextWriter { + /** + * @var string boundary ID + */ private $_boundary; + /** + * Constructor. Generates boundary ID using object instance ID. + */ public function __construct() { $this->_boundary = sprintf('%x',crc32((string)$this)); } + /** + * @return string boundary identifier. + */ public function getBoundary() { return $this->_boundary; } + /** + * @param string boundary identifier. + */ public function setBoundary($value) { $this->_boundary = $value; } + /** + * Returns the text content wrapped within a HTML comment with boundary + * identifier as its comment content. + * @return string text content chunck. + */ public function flush() { $content = '<!--'.$this->getBoundary().'-->'; diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index eb5e445a..8f43fbab 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -429,6 +429,22 @@ class TClientScriptManager extends TApplicationComponent { return isset($this->_endScripts[$key]); } + + /** + * @return boolean true if any end scripts are registered. + */ + public function hasEndScripts() + { + return count($this->_endScripts) > 0; + } + + /** + * @return boolean true if any begin scripts are registered. + */ + public function hasBeginScripts() + { + return count($this->_beginScripts) > 0; + } /** * @param string a unique key diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php index a1d64765..838d0342 100644 --- a/framework/Web/UI/TPage.php +++ b/framework/Web/UI/TPage.php @@ -269,6 +269,8 @@ class TPage extends TTemplateControl */
protected function processCallbackRequest($writer)
{
+ Prado::using('System.Web.UI.ActiveControls.TActivePageAdapter');
+
$this->setAdapter(new TActivePageAdapter($this));
Prado::trace("Page onPreInit()",'System.Web.UI.TPage');
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php index 1194089e..a0801d4c 100644 --- a/framework/Web/UI/WebControls/TBaseValidator.php +++ b/framework/Web/UI/WebControls/TBaseValidator.php @@ -124,7 +124,8 @@ abstract class TBaseValidator extends TLabel implements IValidator } /** - * Adds attributes to renderer. + * Adds attributes to renderer. Calls parent implementation and renders the + * client control scripts. * @param THtmlWriter the renderer */ protected function addAttributesToRender($writer) @@ -137,6 +138,7 @@ abstract class TBaseValidator extends TLabel implements IValidator $writer->addStyleAttribute('visibility','hidden'); $writer->addAttribute('id',$this->getClientID()); parent::addAttributesToRender($writer); + $this->renderClientControlScript($writer); } /** @@ -217,11 +219,10 @@ abstract class TBaseValidator extends TLabel implements IValidator * Renders the javascript code to the end script. * If you override this method, be sure to call the parent implementation * so that the event handlers can be invoked. - * @param TEventParameter event parameter to be passed to the event handlers + * @param THtmlWriter the renderer */ - public function onPreRender($param) + public function renderClientControlScript($writer) { - parent::onPreRender($param); $scripts = $this->getPage()->getClientScript(); $formID=$this->getPage()->getForm()->getClientID(); $scriptKey = "TBaseValidator:$formID"; @@ -236,7 +237,7 @@ abstract class TBaseValidator extends TLabel implements IValidator $this->registerClientScriptValidator(); $this->updateControlCssClass(); } - + /** * Update the ControlToValidate component's css class depending * if the ControlCssClass property is set, and whether this is valid. diff --git a/framework/Web/UI/WebControls/TClientScript.php b/framework/Web/UI/WebControls/TClientScript.php index 23aa1425..020b44b8 100644 --- a/framework/Web/UI/WebControls/TClientScript.php +++ b/framework/Web/UI/WebControls/TClientScript.php @@ -22,6 +22,11 @@ * <com:TClientScript UsingPradoScripts="effects, rico" />
* </code>
*
+ * The {@link setPreRenderControlTypes PreRenderControlTypes} property can
+ * be used to specify that controls type/class names that should pre-render itself
+ * even though they may not be rendered on the page. This is useful to publish
+ * controls that require assets and is only visible after a callback response.
+ *
* @TODO May be use it to include stylesheets as well.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
@@ -54,6 +59,23 @@ class TClientScript extends TControl }
/**
+ * @param string comma delimited list of controls that wish to be prerendered
+ * so as to publish its assets.
+ */
+ public function setPreRenderControlTypes($value)
+ {
+ $this->setViewState('PreRenderControls', $value);
+ }
+
+ /**
+ * @return string comma delimited list of controls types that require prerendering.
+ */
+ public function getPreRenderControlTypes()
+ {
+ return $this->getViewState('PreRenderControls', '');
+ }
+
+ /**
* Calls the client script manager to add each of the requested client
* script libraries.
* @param mixed event parameter
@@ -69,6 +91,23 @@ class TClientScript extends TControl if(strlen($script) > 0)
$cs->registerPradoScript($script);
}
+ $this->preRenderControls($param);
+ }
+
+ /**
+ * PreRender other controls to allow them to publish their assets. Useful
+ * when callback response components that require assets to be present on the page.
+ * @param mixed event paramater
+ */
+ protected function preRenderControls($param)
+ {
+ $types = preg_split('/,|\s+/', $this->getPreRenderControlTypes());
+ foreach($types as $type)
+ {
+ $control = Prado::createComponent($type);
+ $control->setPage($this->getPage());
+ $control->onPreRender($param);
+ }
}
}
|