Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TActiveRadioButton 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: TActiveRadioButton.php 2600 2009-01-07 12:58:53Z christophe.boulain $
10
 * @package System.Web.UI.ActiveControls
11
 */
12
 
13
/**
14
 * TActiveRadioButton class.
15
 *
16
 * The active control counter part to radio button. The {@link setAutoPostBack AutoPostBack}
17
 * property is set to true by default. Thus, when the radio button is clicked a
18
 * {@link onCallback OnCallback} event is raise after {@link OnCheckedChanged} event.
19
 *
20
 * The {@link setText Text} and {@link setChecked Checked} properties can be
21
 * changed during a callback.
22
 *
23
 * The {@link setGroupName GroupName} property may <b>NOT</b> be changed
24
 * during callback because the client-side <tt>name</tt> attribute is read-only
25
 * and can not be changed using javascript.
26
 *
27
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
28
 * @version $Id: TActiveRadioButton.php 2600 2009-01-07 12:58:53Z christophe.boulain $
29
 * @package System.Web.UI.ActiveControls
30
 * @since 3.1
31
 */
32
class TActiveRadioButton extends TRadioButton implements IActiveControl, ICallbackEventHandler
33
{
34
	/**
35
	 * Creates a new callback control, sets the adapter to
36
	 * TActiveControlAdapter. If you override this class, be sure to set the
37
	 * adapter appropriately by, for example, by calling this constructor.
38
	 */
39
	public function __construct()
40
	{
41
		parent::__construct();
42
		$this->setAdapter(new TActiveControlAdapter($this));
43
		$this->setAutoPostBack(true);
44
	}
45
 
46
	/**
47
	 * @return TBaseActiveCallbackControl standard callback control options.
48
	 */
49
	public function getActiveControl()
50
	{
51
		return $this->getAdapter()->getBaseActiveControl();
52
	}
53
 
54
	/**
55
	 * @return TCallbackClientSide client side request options.
56
	 */
57
	public function getClientSide()
58
	{
59
		return $this->getAdapter()->getBaseActiveControl()->getClientSide();
60
	}
61
 
62
	/**
63
	 * Raises the callback event. This method is required by {@link
64
	 * ICallbackEventHandler} interface.
65
	 * This method is mainly used by framework and control developers.
66
	 * @param TCallbackEventParameter the event parameter
67
	 */
68
 	public function raiseCallbackEvent($param)
69
	{
70
		$this->onCallback($param);
71
	}
72
 
73
	/**
74
	 * This method is invoked when a callback is requested. The method raises
75
	 * 'OnCallback' event to fire up the event handlers. If you override this
76
	 * method, be sure to call the parent implementation so that the event
77
	 * handler can be invoked.
78
	 * @param TCallbackEventParameter event parameter to be passed to the event handlers
79
	 */
80
	public function onCallback($param)
81
	{
82
		$this->raiseEvent('OnCallback', $this, $param);
83
	}
84
 
85
	/**
86
	 * Updates the button text on the client-side if the
87
	 * {@link setEnableUpdate EnableUpdate} property is set to true.
88
	 * @param string caption of the button
89
	 */
90
	public function setText($value)
91
	{
92
		parent::setText($value);
93
		if($this->getActiveControl()->canUpdateClientSide())
94
			$this->getPage()->getCallbackClient()->update(
95
				$this->getDefaultLabelID(), $value);
96
	}
97
 
98
	/**
99
	 * Checks the radio button.
100
	 * Updates radio button checked state on the client-side if the
101
	 * {@link setEnableUpdate EnableUpdate} property is set to true.
102
	 * @param boolean whether the radio button is to be checked or not.
103
	 */
104
	public function setChecked($value)
105
	{
106
		$value = TPropertyValue::ensureBoolean($value);
107
		parent::setChecked($value);
108
		if($this->getActiveControl()->canUpdateClientSide())
109
			$this->getPage()->getCallbackClient()->check($this, $value);
110
	}
111
 
112
	/**
113
	 * Override parent implementation, no javascript is rendered here instead
114
	 * the javascript required for active control is registered in {@link addAttributesToRender}.
115
	 */
116
	protected function renderClientControlScript($writer)
117
	{
118
	}
119
 
120
	/**
121
	 * Ensure that the ID attribute is rendered and registers the javascript code
122
	 * for initializing the active control.
123
	 * Since 3.1.4, the javascript code is not rendered if {@link setAutoPostBack AutoPostBack} is false
124
	 *
125
	 */
126
	protected function renderInputTag($writer,$clientID,$onclick)
127
	{
128
		parent::renderInputTag($writer,$clientID,$onclick);
129
		if ($this->getAutoPostBack())
130
			$this->getActiveControl()->registerCallbackClientScript(
131
				$this->getClientClassName(), $this->getPostBackOptions());
132
	}
133
 
134
	/**
135
	 * @return string corresponding javascript class name for this TActiveRadioButton.
136
	 */
137
	protected function getClientClassName()
138
	{
139
		return 'Prado.WebUI.TActiveRadioButton';
140
	}
141
 
142
	/**
143
	 * Overrides parent implementation to ensure label has ID.
144
	 * @return TMap list of attributes to be rendered for label beside the radio button
145
	 */
146
	public function getLabelAttributes()
147
	{
148
		$attributes = parent::getLabelAttributes();
149
		$attributes['id'] = $this->getDefaultLabelID();
150
		return $attributes;
151
	}
152
 
153
	/**
154
	 * Renders a label beside the radio button.
155
	 * @param THtmlWriter the writer for the rendering purpose
156
	 * @param string radio button id
157
	 * @param string label text
158
	 */
159
	protected function renderLabel($writer,$clientID,$text)
160
	{
161
		$writer->addAttribute('id', $this->getDefaultLabelID());
162
		parent::renderLabel($writer, $clientID, $text);
163
	}
164
 
165
	/**
166
	 * @return string radio button label ID;
167
	 */
168
	protected function getDefaultLabelID()
169
	{
170
		if($attributes=$this->getViewState('LabelAttributes',null))
171
			return $this->getLabelAttributes()->itemAt('id');
172
		else
173
			return $this->getClientID().'_label';
174
	}
175
}
176
 
177
?>