]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/ActiveControls/TActiveLinkButton.php
7c2159a7de9ecb7eaf92067c14045b1080c09f20
[bacula/bacula] / gui / baculum / framework / Web / UI / ActiveControls / TActiveLinkButton.php
1 <?php
2 /**
3  * TActiveLinkButton class file.
4  *
5  * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
6  * @link https://github.com/pradosoft/prado
7  * @copyright Copyright &copy; 2005-2016 The PRADO Group
8  * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9  * @package System.Web.UI.ActiveControls
10  */
11
12 /**
13  * Load active control adapter.
14  */
15 Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
16
17 /**
18  * TActiveLinkButton is the active control counter part to TLinkButton.
19  *
20  * When a TActiveLinkButton is clicked, rather than a normal post back request a
21  * callback request is initiated.
22  *
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.
25  *
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.
29  *
30  * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
31  * @package System.Web.UI.ActiveControls
32  * @since 3.1
33  */
34 class TActiveLinkButton extends TLinkButton implements IActiveControl, ICallbackEventHandler
35 {
36         /**
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.
40          */
41         public function __construct()
42         {
43                 parent::__construct();
44                 $this->setAdapter(new TActiveControlAdapter($this));
45         }
46
47         /**
48          * @return TBaseActiveCallbackControl standard callback control options.
49          */
50         public function getActiveControl()
51         {
52                 return $this->getAdapter()->getBaseActiveControl();
53         }
54
55         /**
56          * @return TCallbackClientSide client side request options.
57          */
58         public function getClientSide()
59         {
60                 return $this->getAdapter()->getBaseActiveControl()->getClientSide();
61         }
62
63         /**
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}
69          * event.
70          * This method is mainly used by framework and control developers.
71          * @param TCallbackEventParameter the event parameter
72          */
73         public function raiseCallbackEvent($param)
74         {
75                 $this->raisePostBackEvent($param);
76                 $this->onCallback($param);
77         }
78
79         /**
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
85          */
86         public function onCallback($param)
87         {
88                 $this->raiseEvent('OnCallback', $this, $param);
89         }
90
91         /**
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
95          */
96         public function setText($value)
97         {
98                 if(parent::getText() === $value)
99                         return;
100
101                 parent::setText($value);
102                 if($this->getActiveControl()->canUpdateClientSide())
103                         $this->getPage()->getCallbackClient()->update($this, $value);
104         }
105
106         /**
107          * Override parent implementation, no javascript is rendered here instead
108          * the javascript required for active control is registered in {@link addAttributesToRender}.
109          */
110         protected function renderClientControlScript($writer)
111         {
112         }
113
114         /**
115          * Ensure that the ID attribute is rendered and registers the javascript code
116          * for initializing the active control.
117          */
118         protected function addAttributesToRender($writer)
119         {
120                 parent::addAttributesToRender($writer);
121                 $writer->addAttribute('id',$this->getClientID());
122
123                 if($this->getEnabled(true))
124                 {
125                         $this->getActiveControl()->registerCallbackClientScript(
126                                 $this->getClientClassName(), $this->getPostBackOptions());
127                 }
128         }
129
130         /**
131          * Ensures that the anchor is rendered correctly when its Enabled property
132          * changes in a callback
133          * @param bool enabled
134          */
135         public function setEnabled($value)
136         {
137                 if(parent::getEnabled() === $value)
138                         return;
139
140                 parent::setEnabled($value);
141                 if($this->getActiveControl()->canUpdateClientSide())
142                 {
143                         if($this->getEnabled(true))
144                         {
145                                 $nop = "javascript:;//".$this->getClientID();
146                                 $this->getPage()->getCallbackClient()->setAttribute($this, 'href', $nop);
147
148                                 $this->getActiveControl()->registerCallbackClientScript(
149                                         $this->getClientClassName(), $this->getPostBackOptions());
150
151                         } else {
152                                 $this->getPage()->getCallbackClient()->setAttribute($this, 'href', false);
153                         }
154                 }
155         }
156
157         /**
158          * @return string corresponding javascript class name for this TActiveLinkButton.
159          */
160         protected function getClientClassName()
161         {
162                 return 'Prado.WebUI.TActiveLinkButton';
163         }
164 }
165