|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TActiveLabel class file. |
|
5
|
|
|
* |
|
6
|
|
|
* @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
7
|
|
|
* @link https://github.com/pradosoft/prado |
|
8
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/LICENSE |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Prado\Web\UI\ActiveControls; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Load active control adapter. |
|
15
|
|
|
*/ |
|
16
|
|
|
use Prado\Prado; |
|
17
|
|
|
use Prado\Web\UI\WebControls\TLabel; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* TActiveLabel class |
|
21
|
|
|
* |
|
22
|
|
|
* The active control counterpart of TLabel component. When |
|
23
|
|
|
* {@see \Prado\Web\UI\ActiveControls\TBaseActiveControl::setEnableUpdate ActiveControl.EnableUpdate} |
|
24
|
|
|
* property is true the during a callback request, setting {@see setText Text} |
|
25
|
|
|
* property will also set the text of the label on the client upon callback |
|
26
|
|
|
* completion. Similarly, setting {@see setForControl ForControl} will also set |
|
27
|
|
|
* the client-side "for" attribute on the label. |
|
28
|
|
|
* |
|
29
|
|
|
* @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
30
|
|
|
* @since 3.1 |
|
31
|
|
|
* @method TActiveControlAdapter getAdapter() |
|
32
|
|
|
*/ |
|
33
|
|
|
class TActiveLabel extends TLabel implements IActiveControl |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* Creates a new callback control, sets the adapter to |
|
37
|
|
|
* TActiveControlAdapter. If you override this class, be sure to set the |
|
38
|
|
|
* adapter appropriately by, for example, by calling this constructor. |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct() |
|
41
|
|
|
{ |
|
42
|
|
|
parent::__construct(); |
|
43
|
|
|
$this->setAdapter(new TActiveControlAdapter($this)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return TBaseActiveControl basic active control options. |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getActiveControl() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->getAdapter()->getBaseActiveControl(); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* On callback response, the inner HTML of the label is updated. |
|
56
|
|
|
* @param string $value the text value of the label |
|
57
|
|
|
*/ |
|
58
|
|
|
public function setText($value) |
|
59
|
|
|
{ |
|
60
|
|
|
if (parent::getText() === $value) { |
|
61
|
|
|
return; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
parent::setText($value); |
|
65
|
|
|
if ($this->getActiveControl()->canUpdateClientSide()) { |
|
66
|
|
|
$this->getPage()->getCallbackClient()->update($this, $value); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Sets the ID of the control that the label is associated with. |
|
72
|
|
|
* The control must be locatable via {@see \Prado\Web\UI\TControl::findControl} using the ID. |
|
73
|
|
|
* On callback response, the For attribute of the label is updated. |
|
74
|
|
|
* @param string $value the associated control ID |
|
75
|
|
|
*/ |
|
76
|
|
|
public function setForControl($value) |
|
77
|
|
|
{ |
|
78
|
|
|
if (parent::getForControl() === $value) { |
|
79
|
|
|
return; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
parent::setForControl($value); |
|
83
|
|
|
if ($this->getActiveControl()->canUpdateClientSide()) { |
|
84
|
|
|
$id = $this->findControl($value)->getClientID(); |
|
85
|
|
|
$this->getPage()->getCallbackClient()->setAttribute($this, 'for', $id); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Adds attribute id to the renderer. |
|
91
|
|
|
* @param \Prado\Web\UI\THtmlWriter $writer the writer used for the rendering purpose |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function addAttributesToRender($writer) |
|
94
|
|
|
{ |
|
95
|
|
|
$writer->addAttribute('id', $this->getClientID()); |
|
96
|
|
|
parent::addAttributesToRender($writer); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|