3 * TActiveLinkButton class file.
5 * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
6 * @link https://github.com/pradosoft/prado
7 * @copyright Copyright © 2005-2016 The PRADO Group
8 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9 * @package System.Web.UI.ActiveControls
13 * Load active control adapter.
15 Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
18 * TActiveLinkButton is the active control counter part to TLinkButton.
20 * When a TActiveLinkButton is clicked, rather than a normal post back request a
21 * callback request is initiated.
23 * The {@link onCallback OnCallback} event is raised during a callback request
24 * and it is raise <b>after</b> the {@link onClick OnClick} event.
26 * When the {@link TBaseActiveCallbackControl::setEnableUpdate ActiveControl.EnableUpdate}
27 * property is true, changing the {@link setText Text} property during callback request
28 * will update the link text upon callback response completion.
30 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
31 * @package System.Web.UI.ActiveControls
34 class TActiveLinkButton extends TLinkButton implements IActiveControl, ICallbackEventHandler
37 * Creates a new callback control, sets the adapter to
38 * TActiveControlAdapter. If you override this class, be sure to set the
39 * adapter appropriately by, for example, by calling this constructor.
41 public function __construct()
43 parent::__construct();
44 $this->setAdapter(new TActiveControlAdapter($this));
48 * @return TBaseActiveCallbackControl standard callback control options.
50 public function getActiveControl()
52 return $this->getAdapter()->getBaseActiveControl();
56 * @return TCallbackClientSide client side request options.
58 public function getClientSide()
60 return $this->getAdapter()->getBaseActiveControl()->getClientSide();
64 * Raises the callback event. This method is required by
65 * {@link ICallbackEventHandlerICallbackEventHandler} interface. If
66 * {@link getCausesValidation CausesValidation} is true, it will
67 * invoke the page's {@link TPage::validate validate} method first. It will raise
68 * {@link onClick OnClick} event first and then the {@link onCallback OnCallback}
70 * This method is mainly used by framework and control developers.
71 * @param TCallbackEventParameter the event parameter
73 public function raiseCallbackEvent($param)
75 $this->raisePostBackEvent($param);
76 $this->onCallback($param);
80 * This method is invoked when a callback is requested. The method raises
81 * 'OnCallback' event to fire up the event handlers. If you override this
82 * method, be sure to call the parent implementation so that the event
83 * handler can be invoked.
84 * @param TCallbackEventParameter event parameter to be passed to the event handlers
86 public function onCallback($param)
88 $this->raiseEvent('OnCallback', $this, $param);
92 * Updates the link text on the client-side if the
93 * {@link setEnableUpdate EnableUpdate} property is set to true.
94 * @param string caption of the button
96 public function setText($value)
98 if(parent::getText() === $value)
101 parent::setText($value);
102 if($this->getActiveControl()->canUpdateClientSide())
103 $this->getPage()->getCallbackClient()->update($this, $value);
107 * Override parent implementation, no javascript is rendered here instead
108 * the javascript required for active control is registered in {@link addAttributesToRender}.
110 protected function renderClientControlScript($writer)
115 * Ensure that the ID attribute is rendered and registers the javascript code
116 * for initializing the active control.
118 protected function addAttributesToRender($writer)
120 parent::addAttributesToRender($writer);
121 $writer->addAttribute('id',$this->getClientID());
123 if($this->getEnabled(true))
125 $this->getActiveControl()->registerCallbackClientScript(
126 $this->getClientClassName(), $this->getPostBackOptions());
131 * Ensures that the anchor is rendered correctly when its Enabled property
132 * changes in a callback
133 * @param bool enabled
135 public function setEnabled($value)
137 if(parent::getEnabled() === $value)
140 parent::setEnabled($value);
141 if($this->getActiveControl()->canUpdateClientSide())
143 if($this->getEnabled(true))
145 $nop = "javascript:;//".$this->getClientID();
146 $this->getPage()->getCallbackClient()->setAttribute($this, 'href', $nop);
148 $this->getActiveControl()->registerCallbackClientScript(
149 $this->getClientClassName(), $this->getPostBackOptions());
152 $this->getPage()->getCallbackClient()->setAttribute($this, 'href', false);
158 * @return string corresponding javascript class name for this TActiveLinkButton.
160 protected function getClientClassName()
162 return 'Prado.WebUI.TActiveLinkButton';