Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TActiveCheckBox class file.
4
 *
5
 * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
6
 * @link http://www.pradosoft.com/
7
 * @copyright Copyright &copy; 2005-2008 PradoSoft
8
 * @license http://www.pradosoft.com/license/
9
 * @version $Id: TActiveCheckBox.php 2600 2009-01-07 12:58:53Z christophe.boulain $
10
 * @package System.Web.UI.ActiveControls
11
 */
12
 
13
/**
14
 * Load active control adapter.
15
 */
16
Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
17
 
18
/**
19
 * TActiveCheckBox class.
20
 *
21
 * The active control counter part to checkbox. The {@link setAutoPostBack AutoPostBack}
22
 * property is set to true by default. Thus, when the checkbox is clicked a
23
 * {@link onCallback OnCallback} event is raise after {@link OnCheckedChanged} event.
24
 *
25
 * The {@link setText Text} and {@link setChecked Checked} properties can be
26
 * changed during a callback.
27
 *
28
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
29
 * @version $Id: TActiveCheckBox.php 2600 2009-01-07 12:58:53Z christophe.boulain $
30
 * @package System.Web.UI.ActiveControls
31
 * @since 3.1
32
 */
33
class TActiveCheckBox extends TCheckBox implements ICallbackEventHandler, 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
		$this->setAutoPostBack(true);
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 {@link
65
	 * ICallbackEventHandler} interface.
66
	 * This method is mainly used by framework and control developers.
67
	 * @param TCallbackEventParameter the event parameter
68
	 */
69
 	public function raiseCallbackEvent($param)
70
	{
71
		$this->onCallback($param);
72
	}
73
 
74
	/**
75
	 * This method is invoked when a callback is requested. The method raises
76
	 * 'OnCallback' event to fire up the event handlers. If you override this
77
	 * method, be sure to call the parent implementation so that the event
78
	 * handler can be invoked.
79
	 * @param TCallbackEventParameter event parameter to be passed to the event handlers
80
	 */
81
	public function onCallback($param)
82
	{
83
		$this->raiseEvent('OnCallback', $this, $param);
84
	}
85
 
86
	/**
87
	 * Updates the button text on the client-side if the
88
	 * {@link setEnableUpdate EnableUpdate} property is set to true.
89
	 * @param string caption of the button
90
	 */
91
	public function setText($value)
92
	{
93
		parent::setText($value);
94
		if($this->getActiveControl()->canUpdateClientSide())
95
			$this->getPage()->getCallbackClient()->update(
96
				$this->getDefaultLabelID(), $value);
97
	}
98
 
99
	/**
100
	 * Sets a value indicating whether the checkbox is to be checked or not.
101
	 * Updates checkbox checked state on the client-side if the
102
	 * {@link setEnableUpdate EnableUpdate} property is set to true.
103
	 * @param boolean whether the checkbox is to be checked or not.
104
	 */
105
	public function setChecked($value)
106
	{
107
		$value = TPropertyValue::ensureBoolean($value);
108
		parent::setChecked($value);
109
		if($this->getActiveControl()->canUpdateClientSide())
110
			$this->getPage()->getCallbackClient()->check($this, $value);
111
	}
112
 
113
	/**
114
	 * Override parent implementation, no javascript is rendered here instead
115
	 * the javascript required for active control is registered in {@link addAttributesToRender}.
116
	 */
117
	protected function renderClientControlScript($writer)
118
	{
119
	}
120
 
121
	/**
122
	 * Ensure that the ID attribute is rendered and registers the javascript code
123
	 * for initializing the active control.
124
	 *
125
	 * Since 3.1.4, the javascript code is not rendered if {@link setAutoPostBack AutoPostBack} is false
126
	 *
127
	 * @param THtmlWriter the writer for the rendering purpose
128
	 * @param string checkbox id
129
	 * @param string onclick js
130
	 */
131
	protected function renderInputTag($writer,$clientID,$onclick)
132
	{
133
		parent::renderInputTag($writer,$clientID,$onclick);
134
		if ($this->getAutoPostBack())
135
			$this->getActiveControl()->registerCallbackClientScript(
136
				$this->getClientClassName(), $this->getPostBackOptions());
137
	}
138
 
139
	/**
140
	 * @return string corresponding javascript class name for this TActiveCheckBox.
141
	 */
142
	protected function getClientClassName()
143
	{
144
		return 'Prado.WebUI.TActiveCheckBox';
145
	}
146
 
147
	/**
148
	 * Overrides parent implementation to ensure label has ID.
149
	 * @return TMap list of attributes to be rendered for label beside the checkbox
150
	 */
151
	public function getLabelAttributes()
152
	{
153
		$attributes = parent::getLabelAttributes();
154
		$attributes['id'] = $this->getDefaultLabelID();
155
		return $attributes;
156
	}
157
 
158
	/**
159
	 * Renders a label beside the checkbox.
160
	 * @param THtmlWriter the writer for the rendering purpose
161
	 * @param string checkbox id
162
	 * @param string label text
163
	 */
164
	protected function renderLabel($writer,$clientID,$text)
165
	{
166
		$writer->addAttribute('id', $this->getDefaultLabelID());
167
		parent::renderLabel($writer, $clientID, $text);
168
	}
169
 
170
	/**
171
	 * @return string checkbox label ID;
172
	 */
173
	protected function getDefaultLabelID()
174
	{
175
		if($attributes=$this->getViewState('LabelAttributes',null))
176
			return TCheckBox::getLabelAttributes()->itemAt('id');
177
		else
178
			return $this->getClientID().'_label';
179
	}
180
}
181
 
182
?>