summaryrefslogtreecommitdiff
path: root/framework/Web/UI/ActiveControls/TActiveLabel.php
blob: 13a88b4f5e684abca86ad4576ee632b189a7e4b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
 * TActiveLabel class file.
 *
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
 * @link http://www.pradosoft.com/
 * @copyright Copyright &copy; 2005 PradoSoft
 * @license http://www.pradosoft.com/license/
 * @version $Revision: $  $Date: $
 * @package System.Web.UI.ActiveControls
 */

/**
 * TActiveLabel class
 *
 * The active control counterpart of TLabel component. During a callback
 * request, setting {@link setText Text} property will also set the text of the
 * label on the client upon callback completion. Similarly, setting {@link
 * setForControl ForControl} will set the client-side for attribute on the
 * label.
 *
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
 * @version $Revision: $  $Date: $
 * @package System.Web.UI.ActiveControls
 * @since 3.0
 */
class TActiveLabel extends TLabel
{
	/**
	 * 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));
	}
	
	/**
	 * @param boolean true to allow fine grain callback updates.
	 */
	public function setAllowCallbackUpdate($value)
	{
		$this->setViewState('CallbackUpdate', TPropertyValue::ensureBoolean($value), true);
	}

	/**
	 * @return true to allow fine grain callback updates.
	 */
	public function getAllowCallbackUpdate()
	{
		return $this->getViewState('CallbackUpdate', true);
	}

	/**
	 * @return true if can update changes on the client-side during callback.
	 */
	protected function canUpdateClientSide()
	{
		return 	$this->getIsInitialized() 
				&& $this->getPage()->getIsCallback() 
				&& $this->getAllowCallbackUpdate();
	}

	/**
	 * On callback response, the inner HTMl of the label is updated.
	 * @param string the text value of the label
	 */
	public function setText($value)
	{
		parent::setText($value);
		if($this->canUpdateClientSide())
			$this->getPage()->getCallbackClient()->update($this, $value);
	}
	
	/**
	 * Sets the ID of the control that the label is associated with.
	 * The control must be locatable via {@link TControl::findControl} using the ID.
	 * On callback response, the For attribute of the label is updated.
	 * @param string the associated control ID
	 */
	public function setForControl($value)
	{
		parent::setForControl($value);
		if($this->canUpdateClientSide())
		{
			$id=$this->findControl($value)->getClientID();
			$this->getPage()->getCallbackClient()->setAttribute($this, 'for', $id);
		}
	}
} 

?>