diff options
Diffstat (limited to 'framework/Web/UI/ActiveControls')
13 files changed, 461 insertions, 82 deletions
| 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().'-->'; | 
