diff options
author | wei <> | 2006-08-12 05:34:54 +0000 |
---|---|---|
committer | wei <> | 2006-08-12 05:34:54 +0000 |
commit | 54d4919e3f1b00b644fa3c107acdf20159a1b154 (patch) | |
tree | 1c3e9cc679d4e08cc4beb06eee6f79838a34cb31 /framework/Web/UI/ActiveControls | |
parent | 6dd529fdc25404da07cf9256d92f2a94985c65fc (diff) |
Update active controls.
Diffstat (limited to 'framework/Web/UI/ActiveControls')
6 files changed, 408 insertions, 6 deletions
diff --git a/framework/Web/UI/ActiveControls/TActiveLinkButton.php b/framework/Web/UI/ActiveControls/TActiveLinkButton.php index 40b69391..16c02519 100644 --- a/framework/Web/UI/ActiveControls/TActiveLinkButton.php +++ b/framework/Web/UI/ActiveControls/TActiveLinkButton.php @@ -11,7 +11,17 @@ */ /** - * TActiveLinkButton class. + * TActiveLinkButton is the active control counter part to TLinkButton. + * + * When a TActiveLinkButton is clicked, rather than a normal post back request a + * callback request is initiated. + * + * The {@link onCallback OnCallback} event is raised during a callback request + * 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 + * will update the link text upon callback response completion. * * @author Wei Zhuo <weizhuo[at]gmail[dot]com> * @version : $ Mon Jun 26 00:49:25 EST 2006 $ @@ -20,6 +30,92 @@ */ class TActiveLinkButton extends TLinkButton implements IActiveControl, ICallbackEventHandler { + /** + * Creates a new callback control, sets the adapter to + * TActiveControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. + */ + public function __construct() + { + parent::__construct(); + $this->setAdapter(new TActiveControlAdapter($this)); + } + + /** + * @return TBaseActiveCallbackControl standard callback control options. + */ + public function getActiveControl() + { + return $this->getAdapter()->getBaseActiveControl(); + } + + /** + * 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 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->raisePostBackEvent($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); + } + + /** + * Updates the link text on the client-side if the + * {@link setEnableUpdate EnableUpdate} property is set to true. + * @param string caption of the button + */ + public function setText($value) + { + parent::setText($value); + if($this->getActiveControl()->canUpdateClientSide()) + $this->getPage()->getCallbackClient()->setAttribute($this, 'value', $value); + } + + /** + * Override parent implementation, no javascript is rendered here instead + * the javascript required for active control is registered in {@link addAttributesToRender}. + */ + protected function renderClientControlScript($writer) + { + } + + /** + * Ensure that the ID attribute is rendered and registers the javascript code + * for initializing the active control. + */ + protected function addAttributesToRender($writer) + { + parent::addAttributesToRender($writer); + $writer->addAttribute('id',$this->getClientID()); + $this->renderLinkButtonHref($writer); + $this->getActiveControl()->registerCallbackClientScript( + $this->getClientClassName(), $this->getPostBackOptions()); + } + + /** + * @return string corresponding javascript class name for this TActiveLinkButton. + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TActiveLinkButton'; + } } ?>
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveListBox.php b/framework/Web/UI/ActiveControls/TActiveListBox.php index 37db5e27..77ca615a 100644 --- a/framework/Web/UI/ActiveControls/TActiveListBox.php +++ b/framework/Web/UI/ActiveControls/TActiveListBox.php @@ -20,7 +20,97 @@ */ class TActiveListBox extends TListBox implements IActiveControl, ICallbackEventHandler { - + /** + * Creates a new callback control, sets the adapter to + * TActiveListControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. + */ + public function __construct() + { + parent::__construct(); + $this->setAdapter(new TActiveListControlAdapter($this)); + $this->setAutoPostBack(true); + } + + /** + * @return TBaseActiveCallbackControl standard callback control options. + */ + public function getActiveControl() + { + return $this->getAdapter()->getBaseActiveControl(); + } + + /** + * Javascript client class for this control. + * This method overrides the parent implementation. + * @return null no javascript class name. + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TActiveListBox'; + } + + /** + * Loads user input data. Disables the client-side update during loading + * and restore the EnableUpdate of ActiveControl after loading. + * @param string the key that can be used to retrieve data from the input data collection + * @param array the input data collection + * @return boolean whether the data of the component has been changed + */ + public function loadPostData($key,$values) + { + $enabled = $this->getActiveControl()->getEnableUpdate(); + $this->getActiveControl()->setEnableUpdate(false); + $result = parent::loadPostData($key, $values); + $this->getActiveControl()->setEnableUpdate($enabled); + return $result; + } + + /** + * Sets the selection mode of the list control (Single, Multiple) + * on the client-side if the {@link setEnableUpdate EnableUpdate} + * property is set to true. + * @param string the selection mode + */ + public function setSelectionMode($value) + { + parent::setSelectionMode($value); + $multiple = $this->getIsMultiSelect(); + $id = $this->getUniqueID(); $multi_id = $id.'[]'; + if($multiple) + $this->getPage()->registerPostDataLoader($multi_id); + if($this->getActiveControl()->canUpdateClientSide()) + { + $client = $this->getPage()->getCallbackClient(); + $client->setAttribute($this, 'multiple', $multiple ? 'multiple' : false); + $client->setAttribute($this, 'name', $multiple ? $multi_id : $id); + if($multiple) + $client->addPostDataLoader($multi_id); + } + } + + /** + * Raises the callback event. This method is required by {@link + * ICallbackEventHandler} interface. + * This method is mainly used by framework and control developers. + * @param TCallbackEventParameter the event parameter + */ + public function raiseCallbackEvent($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); + } } ?>
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveRadioButton.php b/framework/Web/UI/ActiveControls/TActiveRadioButton.php index b9497051..334de3a1 100644 --- a/framework/Web/UI/ActiveControls/TActiveRadioButton.php +++ b/framework/Web/UI/ActiveControls/TActiveRadioButton.php @@ -14,6 +14,17 @@ /** * TActiveRadioButton class. * + * The active control counter part to radio button. The {@link setAutoPostBack AutoPostBack} + * property is set to true by default. Thus, when the radio button is clicked a + * {@link onCallback OnCallback} event is raise after {@link OnCheckedChanged} event. + * + * The {@link setText Text} and {@link setChecked Checked} properties can be + * changed during a callback. + * + * The {@link setGroupName GroupName} property may <b>NOT</b> be changed + * during callback because the client-side <tt>name</tt> attribute is read-only + * and can not be changed using javascript. + * * @author Wei Zhuo <weizhuo[at]gmail[dot]com> * @version $Revision: $ Mon Jun 26 00:47:14 EST 2006 $ * @package System.Web.UI.ActiveControls @@ -21,7 +32,137 @@ */ class TActiveRadioButton extends TRadioButton implements IActiveControl, ICallbackEventHandler { - + /** + * Creates a new callback control, sets the adapter to + * TActiveControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. + */ + public function __construct() + { + parent::__construct(); + $this->setAdapter(new TActiveControlAdapter($this)); + $this->setAutoPostBack(true); + } + + /** + * @return TBaseActiveCallbackControl standard callback control options. + */ + public function getActiveControl() + { + return $this->getAdapter()->getBaseActiveControl(); + } + + /** + * Raises the callback event. This method is required by {@link + * ICallbackEventHandler} interface. + * This method is mainly used by framework and control developers. + * @param TCallbackEventParameter the event parameter + */ + public function raiseCallbackEvent($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); + } + + /** + * Updates the button text on the client-side if the + * {@link setEnableUpdate EnableUpdate} property is set to true. + * @param string caption of the button + */ + public function setText($value) + { + parent::setText($value); + if($this->getActiveControl()->canUpdateClientSide()) + $this->getPage()->getCallbackClient()->update( + $this->getDefaultLabelID(), $value); + } + + /** + * Checks the radio button. + * Updates radio button checked state on the client-side if the + * {@link setEnableUpdate EnableUpdate} property is set to true. + * @param boolean whether the radio button is to be checked or not. + */ + public function setChecked($value) + { + $value = TPropertyValue::ensureBoolean($value); + parent::setChecked($value); + if($value && $this->getActiveControl()->canUpdateClientSide()) + $this->getPage()->getCallbackClient()->check($this, $value); + } + + /** + * Add the group name as post data loader if group name is set. + */ + protected function addToPostDataLoader() + { + parent::addToPostDataLoader(); + $group = $this->getGroupName(); + if(!empty($group)) + $this->getPage()->registerPostDataLoader($group); + } + + /** + * Registers the javascript code for initializing the active control. + */ + protected function renderClientControlScript($writer) + { + $this->getActiveControl()->registerCallbackClientScript( + $this->getClientClassName(), $this->getPostBackOptions()); + } + + /** + * @return string corresponding javascript class name for this TActiveRadioButton. + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TActiveRadioButton'; + } + + /** + * Overrides parent implementation to ensure label has ID. + * @return TMap list of attributes to be rendered for label beside the radio button + */ + public function getLabelAttributes() + { + $attributes = parent::getLabelAttributes(); + $attributes['id'] = $this->getDefaultLabelID(); + return $attributes; + } + + /** + * Renders a label beside the radio button. + * @param THtmlWriter the writer for the rendering purpose + * @param string radio button id + * @param string label text + */ + protected function renderLabel($writer,$clientID,$text) + { + $writer->addAttribute('id', $this->getDefaultLabelID()); + parent::renderLabel($writer, $clientID, $text); + } + + /** + * @return string radio button label ID; + */ + protected function getDefaultLabelID() + { + if($attributes=$this->getViewState('LabelAttributes',null)) + return $this->getLabelAttributes()->itemAt('id'); + else + return $this->getClientID().'_label'; + } } ?>
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php b/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php index 665a8542..daaaf9aa 100644 --- a/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php +++ b/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php @@ -13,6 +13,15 @@ /** * TActiveRadioButtonList class. * + * The active control counter part to radio button list control. + * The {@link setAutoPostBack AutoPostBack} property is set to true by default. + * Thus, when a radio button is clicked a {@link onCallback OnCallback} event is + * raised after {@link OnSelectedIndexChanged} event. + * + * With {@link TBaseActiveControl::setEnableUpdate() ActiveControl.EnabledUpdate} + * set to true (default is true), changes to the selection will be updated + * on the client side. + * * @author Wei Zhuo <weizhuo[at]gmail[dot]com> * @version : $ Mon Jun 26 00:48:08 EST 2006 $ * @package System.Web.UI.ActiveControls @@ -20,6 +29,67 @@ */ class TActiveRadioButtonList extends TRadioButtonList implements IActiveControl, ICallbackEventHandler { + /** + * Creates a new callback control, sets the adapter to + * TActiveListControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. + */ + public function __construct() + { + parent::__construct(); + $this->setAdapter(new TActiveListControlAdapter($this)); + $this->setAutoPostBack(true); + } + + /** + * @return TBaseActiveCallbackControl standard callback control options. + */ + public function getActiveControl() + { + return $this->getAdapter()->getBaseActiveControl(); + } + + /** + * No client class for this control. + * This method overrides the parent implementation. + * @return null no javascript class name. + */ + protected function getClientClassName() + { + return null; + } + + /** + * Creates a control used for repetition (used as a template). + * @return TControl the control to be repeated + */ + protected function createRepeatedControl() + { + return new TActiveRadioButton; + } + + /** + * Raises the callback event. This method is required by {@link + * ICallbackEventHandler} interface. + * This method is mainly used by framework and control developers. + * @param TCallbackEventParameter the event parameter + */ + public function raiseCallbackEvent($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); + } } ?>
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TCallbackClientScript.php b/framework/Web/UI/ActiveControls/TCallbackClientScript.php index 6a025802..dbfa935f 100644 --- a/framework/Web/UI/ActiveControls/TCallbackClientScript.php +++ b/framework/Web/UI/ActiveControls/TCallbackClientScript.php @@ -205,6 +205,11 @@ class TCallbackClientScript extends TApplicationComponent $this->callClientFunction('Element.remove', $element);
}
+ public function addPostDataLoader($name)
+ {
+ $this->callClientFunction('Prado.CallbackRequest.addPostLoaders', $name);
+ }
+
/**
* Update the element's innerHTML with new content.
* @param TControl|string control element or element id
diff --git a/framework/Web/UI/ActiveControls/TCallbackResponseAdapter.php b/framework/Web/UI/ActiveControls/TCallbackResponseAdapter.php index f4ad222a..8f456b86 100755 --- a/framework/Web/UI/ActiveControls/TCallbackResponseAdapter.php +++ b/framework/Web/UI/ActiveControls/TCallbackResponseAdapter.php @@ -86,7 +86,7 @@ class TCallbackResponseAdapter extends THttpResponseAdapter * * 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. + * is generated using microtime. * * @author Wei Zhuo <weizhuo[at]gmail[dot]com> * @version $Revision: $ Sun Jun 18 08:02:21 EST 2006 $ @@ -101,11 +101,11 @@ class TCallbackResponseWriter extends TTextWriter private $_boundary; /** - * Constructor. Generates boundary ID using object instance ID. + * Constructor. Generates unique boundary ID using microtime. */ public function __construct() { - $this->_boundary = sprintf('%x',crc32(time())); + $this->_boundary = sprintf('%x',crc32(microtime())); } /** |