summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TCheckBoxList.php
blob: c4addcddd569c2c5259c9170357b8c474ce211d8 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php

Prado::using('System.Web.UI.WebControls.TRepeatInfo');

class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingContainer, IPostBackDataHandler
{
	private $_repeatedControl;
	private $_isEnabled;

	public function __construct()
	{
		parent::__construct();
		$this->_repeatedControl=$this->createRepeatedControl();
		$this->_repeatedControl->setEnableViewState(false);
		$this->_repeatedControl->setID('0');
		$this->getControls()->add($this->_repeatedControl);
	}

	protected function createRepeatedControl()
	{
		return new TCheckBox;
	}

	public function findControl($id)
	{
		return $this;
	}

	protected function getIsMultiSelect()
	{
		return true;
	}

	protected function createStyle()
	{
		return new TTableStyle;
	}

	protected function getRepeatInfo()
	{
		if(($repeatInfo=$this->getViewState('RepeatInfo',null))===null)
		{
			$repeatInfo=new TRepeatInfo;
			$this->setViewState('RepeatInfo',$repeatInfo,null);
		}
		return $repeatInfo;
	}

	/**
	 * @return string the alignment of the text caption, defaults to 'Right'.
	 */
	public function getTextAlign()
	{
		return $this->getViewState('TextAlign','Right');
	}

	/**
	 * Sets the text alignment of the checkboxes
	 * @param string either 'Left' or 'Right'
	 */
	public function setTextAlign($value)
	{
		$this->setViewState('TextAlign',TPropertyValue::ensureEnum($value,array('Left','Right')),'Right');
	}

	/**
	 * @return integer the number of columns that the list should be displayed with. Defaults to 0 meaning not set.
	 */
	public function getRepeatColumns()
	{
		return $this->getRepeatInfo()->getRepeatColumns();
	}

	/**
	 * Sets the number of columns that the list should be displayed with.
	 * @param integer the number of columns that the list should be displayed with.
	 */
	public function setRepeatColumns($value)
	{
		$this->getRepeatInfo()->setRepeatColumns($value);
	}

	/**
	 * @return string the direction of traversing the list, defaults to 'Vertical'
	 */
	public function getRepeatDirection()
	{
		return $this->getRepeatInfo()->getRepeatDirection();
	}

	/**
	 * Sets the direction of traversing the list (Vertical, Horizontal)
	 * @param string the direction of traversing the list
	 */
	public function setRepeatDirection($value)
	{
		$this->getRepeatInfo()->setRepeatDirection($value);
	}

	/**
	 * @return string how the list should be displayed, using table or using line breaks. Defaults to 'Table'.
	 */
	public function getRepeatLayout()
	{
		return $this->getRepeatInfo()->getRepeatLayout();
	}

	/**
	 * Sets how the list should be displayed, using table or using line breaks (Table, Flow)
	 * @param string how the list should be displayed, using table or using line breaks (Table, Flow)
	 */
	public function setRepeatLayout($value)
	{
		$this->getRepeatInfo()->setRepeatLayout($value);
	}

	/**
	 * @return integer the cellspacing for the table keeping the checkbox list. Defaults to -1, meaning not set.
	 */
	public function getCellSpacing()
	{
		if($this->getHasStyle())
			return $this->getStyle()->getCellSpacing();
		else
			return -1;
	}

	/**
	 * Sets the cellspacing for the table keeping the checkbox list.
	 * @param integer the cellspacing for the table keeping the checkbox list.
	 */
	public function setCellSpacing($value)
	{
		$this->getStyle()->setCellSpacing($value);
	}

	/**
	 * @return integer the cellpadding for the table keeping the checkbox list. Defaults to -1, meaning not set.
	 */
	public function getCellPadding()
	{
		if($this->getHasStyle())
			return $this->getStyle()->getCellPadding();
		else
			return -1;
	}

	/**
	 * Sets the cellpadding for the table keeping the checkbox list.
	 * @param integer the cellpadding for the table keeping the checkbox list.
	 */
	public function setCellPadding($value)
	{
		$this->getStyle()->setCellPadding($value);
	}

	public function loadPostData($key,$values)
	{
	}

	public function raisePostDataChangedEvent()
	{
	}

	public function getHasHeader()
	{
		return false;
	}

	public function getHasFooter()
	{
		return false;
	}

	public function getHasSeparators()
	{
		return false;
	}

	public function getItemStyle($itemType,$index)
	{
		return null;
	}

	public function getRepeatedItemCount()
	{
		if($this->getHasItems())
			return $this->getItems()->getCount();
		else
			return 0;
	}

	public function renderItem($writer,$repeatInfo,$itemType,$index)
	{
		$item=$this->getItems()->itemAt($index);
		if($item->getHasAttributes())
			$this->_repeatedControl->getAttributes()->copyFrom($item->getAttributes());
		else if($this->_repeatedControl->getHasAttributes())
			$this->_repeatedControl->getAttributes()->clear();
		$this->_repeatedControl->setID("$index");
		$this->_repeatedControl->setText($item->getText());
		$this->_repeatedControl->setChecked($item->getSelected());
		$this->_repeatedControl->setEnabled($this->_isEnabled && $item->getEnabled());
		$this->_repeatedControl->renderControl($writer);
	}

	protected function onPreRender($param)
	{
		parent::onPreRender($param);
		$this->_repeatedControl->setAutoPostBack($this->getAutoPostBack());
		$this->_repeatedControl->setCausesValidation($this->getCausesValidation());
		$this->_repeatedControl->setValidationGroup($this->getValidationGroup());
		$page=$this->getPage();
		$n=$this->getRepeatedItemCount();
		for($i=0;$i<$n;++$i)
		{
			$this->_repeatedControl->setID("$i");
			$page->registerRequiresPostData($this->_repeatedControl);
		}
	}

	protected function render($writer)
	{
		if($this->getRepeatedItemCount()>0)
		{
			$this->_isEnabled=$this->getEnabled(true);
			$repeatInfo=$this->getRepeatInfo();
			$accessKey=$this->getAccessKey();
			$tabIndex=$this->getTabIndex();
			$this->_repeatedControl->setTextAlign($this->getTextAlign());
			$this->_repeatedControl->setAccessKey($accessKey);
			$this->_repeatedControl->setTabIndex($tabIndex);
			$this->setAccessKey('');
			$this->setTabIndex(0);
			$repeatInfo->renderRepeater($writer,$this);
			$this->setAccessKey($accessKey);
			$this->setTabIndex($tabIndex);
		}
	}
}

?>