| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TActiveListControlAdapter class file.
|
|
|
4 |
*
|
|
|
5 |
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: TActiveListControlAdapter.php 2482 2008-07-30 02:07:13Z knut $
|
|
|
10 |
* @package System.Web.UI.ActiveControls
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* Load active control adapter.
|
|
|
15 |
*/
|
|
|
16 |
Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
|
|
|
17 |
Prado::using('System.Web.UI.WebControls.TListControl');
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* TActiveListControlAdapter class.
|
|
|
21 |
*
|
|
|
22 |
* Adapte the list controls to allows the selections on the client-side to be altered
|
|
|
23 |
* during callback response.
|
|
|
24 |
*
|
|
|
25 |
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
|
|
|
26 |
* @version $Id: TActiveListControlAdapter.php 2482 2008-07-30 02:07:13Z knut $
|
|
|
27 |
* @package System.Web.UI.ActiveControls
|
|
|
28 |
* @since 3.1
|
|
|
29 |
*/
|
|
|
30 |
class TActiveListControlAdapter extends TActiveControlAdapter implements IListControlAdapter
|
|
|
31 |
{
|
|
|
32 |
/**
|
|
|
33 |
* @return boolean true if can update client-side attributes.
|
|
|
34 |
*/
|
|
|
35 |
protected function canUpdateClientSide()
|
|
|
36 |
{
|
|
|
37 |
return $this->getControl()->getActiveControl()->canUpdateClientSide();
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Selects an item based on zero-base index on the client side.
|
|
|
42 |
* @param integer the index (zero-based) of the item to be selected
|
|
|
43 |
*/
|
|
|
44 |
public function setSelectedIndex($index)
|
|
|
45 |
{
|
|
|
46 |
if($this->canUpdateClientSide())
|
|
|
47 |
{
|
|
|
48 |
$this->updateListItems();
|
|
|
49 |
$this->getPage()->getCallbackClient()->select(
|
|
|
50 |
$this->getControl(), 'Index', $index);
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Selects a list of item based on zero-base indices on the client side.
|
|
|
56 |
* @param array list of index of items to be selected
|
|
|
57 |
*/
|
|
|
58 |
public function setSelectedIndices($indices)
|
|
|
59 |
{
|
|
|
60 |
if($this->canUpdateClientSide())
|
|
|
61 |
{
|
|
|
62 |
$this->updateListItems();
|
|
|
63 |
$n = $this->getControl()->getItemCount();
|
|
|
64 |
$list = array();
|
|
|
65 |
foreach($indices as $index)
|
|
|
66 |
{
|
|
|
67 |
$index = intval($index);
|
|
|
68 |
if($index >= 0 && $index <= $n)
|
|
|
69 |
$list[] = $index;
|
|
|
70 |
}
|
|
|
71 |
if(count($list) > 0)
|
|
|
72 |
$this->getPage()->getCallbackClient()->select(
|
|
|
73 |
$this->getControl(), 'Indices', $list);
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Sets selection by item value on the client side.
|
|
|
79 |
* @param string the value of the item to be selected.
|
|
|
80 |
*/
|
|
|
81 |
public function setSelectedValue($value)
|
|
|
82 |
{
|
|
|
83 |
if($this->canUpdateClientSide())
|
|
|
84 |
{
|
|
|
85 |
$this->updateListItems();
|
|
|
86 |
$this->getPage()->getCallbackClient()->select(
|
|
|
87 |
$this->getControl(), 'Value', $value);
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Sets selection by a list of item values on the client side.
|
|
|
93 |
* @param array list of the selected item values
|
|
|
94 |
*/
|
|
|
95 |
public function setSelectedValues($values)
|
|
|
96 |
{
|
|
|
97 |
if($this->canUpdateClientSide())
|
|
|
98 |
{
|
|
|
99 |
$this->updateListItems();
|
|
|
100 |
$list = array();
|
|
|
101 |
foreach($values as $value)
|
|
|
102 |
$list[] = $value;
|
|
|
103 |
if(count($list) > 0)
|
|
|
104 |
$this->getPage()->getCallbackClient()->select(
|
|
|
105 |
$this->getControl(), 'Values', $list);
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
/**
|
|
|
110 |
* Clears all existing selections on the client side.
|
|
|
111 |
*/
|
|
|
112 |
public function clearSelection()
|
|
|
113 |
{
|
|
|
114 |
if($this->canUpdateClientSide())
|
|
|
115 |
{
|
|
|
116 |
$this->updateListItems();
|
|
|
117 |
$this->getPage()->getCallbackClient()->select($this->getControl(), 'Clear');
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
/**
|
|
|
122 |
* Update the client-side list options.
|
|
|
123 |
*/
|
|
|
124 |
public function updateListItems()
|
|
|
125 |
{
|
|
|
126 |
if($this->canUpdateClientSide())
|
|
|
127 |
{
|
|
|
128 |
$items = $this->getControl()->getItems();
|
|
|
129 |
if($items instanceof TActiveListItemCollection
|
|
|
130 |
&& $items->getListHasChanged())
|
|
|
131 |
{
|
|
|
132 |
$items->updateClientSide();
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
/**
|
|
|
139 |
* TActiveListItemCollection class.
|
|
|
140 |
*
|
|
|
141 |
* Allows TActiveDropDownList and TActiveListBox to add new options
|
|
|
142 |
* during callback response. New options can only be added <b>after</b> the
|
|
|
143 |
* {@link TControl::onLoad OnLoad} event.
|
|
|
144 |
*
|
|
|
145 |
* The {@link getListHasChanged ListHasChanged} property is true when the
|
|
|
146 |
* list items has changed. The control responsible for the list needs to
|
|
|
147 |
* repopulate the client-side options.
|
|
|
148 |
*
|
|
|
149 |
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
|
|
|
150 |
* @version $Id: TActiveListControlAdapter.php 2482 2008-07-30 02:07:13Z knut $
|
|
|
151 |
* @package System.Web.UI.ActiveControls
|
|
|
152 |
* @since 3.1
|
|
|
153 |
*/
|
|
|
154 |
class TActiveListItemCollection extends TListItemCollection
|
|
|
155 |
{
|
|
|
156 |
/**
|
|
|
157 |
* @var IActiveControl control instance.
|
|
|
158 |
*/
|
|
|
159 |
private $_control;
|
|
|
160 |
/**
|
|
|
161 |
* @var boolean true if list items were changed.
|
|
|
162 |
*/
|
|
|
163 |
private $_hasChanged=false;
|
|
|
164 |
|
|
|
165 |
/**
|
|
|
166 |
* @return boolean true if active controls can update client-side and
|
|
|
167 |
* the onLoad event has already been raised.
|
|
|
168 |
*/
|
|
|
169 |
protected function canUpdateClientSide()
|
|
|
170 |
{
|
|
|
171 |
return $this->getControl()->getActiveControl()->canUpdateClientSide()
|
|
|
172 |
&& $this->getControl()->getHasLoaded();
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
/**
|
|
|
176 |
* @param IActiveControl a active list control.
|
|
|
177 |
*/
|
|
|
178 |
public function setControl(IActiveControl $control)
|
|
|
179 |
{
|
|
|
180 |
$this->_control = $control;
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
/**
|
|
|
184 |
* @return IActiveControl active control using the collection.
|
|
|
185 |
*/
|
|
|
186 |
public function getControl()
|
|
|
187 |
{
|
|
|
188 |
return $this->_control;
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
/**
|
|
|
192 |
* @return boolean true if the list has changed after onLoad event.
|
|
|
193 |
*/
|
|
|
194 |
public function getListHasChanged()
|
|
|
195 |
{
|
|
|
196 |
return $this->_hasChanged;
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
/**
|
|
|
200 |
* Update client-side list items.
|
|
|
201 |
*/
|
|
|
202 |
public function updateClientSide()
|
|
|
203 |
{
|
|
|
204 |
$client = $this->getControl()->getPage()->getCallbackClient();
|
|
|
205 |
$client->setListItems($this->getControl(), $this);
|
|
|
206 |
$this->_hasChanged=false;
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
/**
|
|
|
210 |
* Inserts an item into the collection.
|
|
|
211 |
* The new option is added on the client-side during callback.
|
|
|
212 |
* @param integer the location where the item will be inserted.
|
|
|
213 |
* The current item at the place and the following ones will be moved backward.
|
|
|
214 |
* @param TListItem the item to be inserted.
|
|
|
215 |
* @throws TInvalidDataTypeException if the item being inserted is neither a string nor TListItem
|
|
|
216 |
*/
|
|
|
217 |
public function insertAt($index, $value)
|
|
|
218 |
{
|
|
|
219 |
parent::insertAt($index, $value);
|
|
|
220 |
if($this->canUpdateClientSide())
|
|
|
221 |
$this->_hasChanged = true;
|
|
|
222 |
}
|
|
|
223 |
|
|
|
224 |
/**
|
|
|
225 |
* Removes an item from at specified index.
|
|
|
226 |
* @param int zero based index.
|
|
|
227 |
*/
|
|
|
228 |
public function removeAt($index)
|
|
|
229 |
{
|
|
|
230 |
parent::removeAt($index);
|
|
|
231 |
if($this->canUpdateClientSide())
|
|
|
232 |
$this->_hasChanged = true;
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
?>
|