]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/ActiveControls/TActiveLabel.php
0a20e2b06fa4792155a8c8efdcd03906db86a191
[bacula/bacula] / gui / baculum / framework / Web / UI / ActiveControls / TActiveLabel.php
1 <?php
2 /**
3  * TActiveLabel class file.
4  *
5  * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6  * @link http://www.pradosoft.com/
7  * @copyright Copyright &copy; 2005-2014 PradoSoft
8  * @license http://www.pradosoft.com/license/
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  * TActiveLabel class
19  *
20  * The active control counterpart of TLabel component. When
21  * {@link TBaseActiveControl::setEnableUpdate ActiveControl.EnableUpdate}
22  * property is true the during a callback request, setting {@link setText Text}
23  * property will also set the text of the label on the client upon callback
24  * completion. Similarly, setting {@link setForControl ForControl} will also set
25  * the client-side "for" attribute on the label.
26  *
27  * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
28  * @package System.Web.UI.ActiveControls
29  * @since 3.1
30  */
31 class TActiveLabel extends TLabel implements IActiveControl
32 {
33         /**
34          * Creates a new callback control, sets the adapter to
35          * TActiveControlAdapter. If you override this class, be sure to set the
36          * adapter appropriately by, for example, by calling this constructor.
37          */
38         public function __construct()
39         {
40                 parent::__construct();
41                 $this->setAdapter(new TActiveControlAdapter($this));
42         }
43
44         /**
45          * @return TBaseActiveControl basic active control options.
46          */
47         public function getActiveControl()
48         {
49                 return $this->getAdapter()->getBaseActiveControl();
50         }
51
52         /**
53          * On callback response, the inner HTML of the label is updated.
54          * @param string the text value of the label
55          */
56         public function setText($value)
57         {
58                 parent::setText($value);
59                 if($this->getActiveControl()->canUpdateClientSide())
60                         $this->getPage()->getCallbackClient()->update($this, $value);
61         }
62
63         /**
64          * Sets the ID of the control that the label is associated with.
65          * The control must be locatable via {@link TControl::findControl} using the ID.
66          * On callback response, the For attribute of the label is updated.
67          * @param string the associated control ID
68          */
69         public function setForControl($value)
70         {
71                 parent::setForControl($value);
72                 if($this->getActiveControl()->canUpdateClientSide())
73                 {
74                         $id=$this->findControl($value)->getClientID();
75                         $this->getPage()->getCallbackClient()->setAttribute($this, 'for', $id);
76                 }
77         }
78
79         /**
80          * Adds attribute id to the renderer.
81          * @param THtmlWriter the writer used for the rendering purpose
82          */
83         protected function addAttributesToRender($writer) {
84             $writer->addAttribute('id',$this->getClientID());
85             parent::addAttributesToRender($writer);
86         }
87 }
88