|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* TActiveListBox class file. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Wei Zhuo <weizhuo[at]gamil[dot]com> |
|
6
|
|
|
* @link https://github.com/pradosoft/prado |
|
7
|
|
|
* @copyright Copyright © 2005-2015 The PRADO Group |
|
8
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9
|
|
|
* @package System.Web.UI.ActiveControls |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Load active list control adapter |
|
14
|
|
|
*/ |
|
15
|
|
|
Prado::using('System.Web.UI.ActiveControls.TActiveListControlAdapter'); |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* TActiveListBox class. |
|
19
|
|
|
* |
|
20
|
|
|
* List items can be added dynamically during a callback request. |
|
21
|
|
|
* |
|
22
|
|
|
* @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
23
|
|
|
* @package System.Web.UI.ActiveControls |
|
24
|
|
|
* @since 3.1 |
|
25
|
|
|
*/ |
|
26
|
|
|
class TActiveListBox extends TListBox implements IActiveControl, ICallbackEventHandler |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Creates a new callback control, sets the adapter to |
|
30
|
|
|
* TActiveListControlAdapter. If you override this class, be sure to set the |
|
31
|
|
|
* adapter appropriately by, for example, by calling this constructor. |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct() |
|
34
|
|
|
{ |
|
35
|
|
|
parent::__construct(); |
|
36
|
|
|
$this->setAdapter(new TActiveListControlAdapter($this)); |
|
37
|
|
|
$this->setAutoPostBack(true); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return TBaseActiveCallbackControl standard callback control options. |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getActiveControl() |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->getAdapter()->getBaseActiveControl(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return TCallbackClientSide client side request options. |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getClientSide() |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->getAdapter()->getBaseActiveControl()->getClientSide(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Creates a collection object to hold list items. A specialized |
|
58
|
|
|
* TActiveListItemCollection is created to allow the drop down list options |
|
59
|
|
|
* to be added. |
|
60
|
|
|
* This method may be overriden to create a customized collection. |
|
61
|
|
|
* @return TActiveListItemCollection the collection object |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function createListItemCollection() |
|
64
|
|
|
{ |
|
65
|
|
|
$collection = new TActiveListItemCollection; |
|
66
|
|
|
$collection->setControl($this); |
|
67
|
|
|
return $collection; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Javascript client class for this control. |
|
72
|
|
|
* This method overrides the parent implementation. |
|
73
|
|
|
* @return null no javascript class name. |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function getClientClassName() |
|
76
|
|
|
{ |
|
77
|
|
|
return 'Prado.WebUI.TActiveListBox'; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Sets the selection mode of the list control (Single, Multiple) |
|
82
|
|
|
* on the client-side if the {@link setEnableUpdate EnableUpdate} |
|
83
|
|
|
* property is set to true. |
|
84
|
|
|
* @param string the selection mode |
|
85
|
|
|
*/ |
|
86
|
|
|
public function setSelectionMode($value) |
|
87
|
|
|
{ |
|
88
|
|
|
if(parent::getSelectionMode() === $value) |
|
|
|
|
|
|
89
|
|
|
return; |
|
90
|
|
|
|
|
91
|
|
|
parent::setSelectionMode($value); |
|
92
|
|
|
$multiple = $this->getIsMultiSelect(); |
|
93
|
|
|
$id = $this->getUniqueID(); $multi_id = $id.'[]'; |
|
|
|
|
|
|
94
|
|
|
if($this->getActiveControl()->canUpdateClientSide()) |
|
95
|
|
|
{ |
|
96
|
|
|
$client = $this->getPage()->getCallbackClient(); |
|
97
|
|
|
$client->setAttribute($this, 'multiple', $multiple ? 'multiple' : false); |
|
98
|
|
|
$client->setAttribute($this, 'name', $multiple ? $multi_id : $id); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Raises the callback event. This method is required by {@link |
|
104
|
|
|
* ICallbackEventHandler} interface. |
|
105
|
|
|
* This method is mainly used by framework and control developers. |
|
106
|
|
|
* @param TCallbackEventParameter the event parameter |
|
107
|
|
|
*/ |
|
108
|
|
|
public function raiseCallbackEvent($param) |
|
109
|
|
|
{ |
|
110
|
|
|
$this->onCallback($param); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* This method is invoked when a callback is requested. The method raises |
|
115
|
|
|
* 'OnCallback' event to fire up the event handlers. If you override this |
|
116
|
|
|
* method, be sure to call the parent implementation so that the event |
|
117
|
|
|
* handler can be invoked. |
|
118
|
|
|
* @param TCallbackEventParameter event parameter to be passed to the event handlers |
|
119
|
|
|
*/ |
|
120
|
|
|
public function onCallback($param) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->raiseEvent('OnCallback', $this, $param); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Updates the client-side options if the item list has changed after the OnLoad event. |
|
127
|
|
|
*/ |
|
128
|
|
|
public function onPreRender($param) |
|
129
|
|
|
{ |
|
130
|
|
|
parent::onPreRender($param); |
|
131
|
|
|
$this->getAdapter()->updateListItems(); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Override parent implementation, no javascript is rendered here instead |
|
136
|
|
|
* the javascript required for active control is registered in {@link addAttributesToRender}. |
|
137
|
|
|
*/ |
|
138
|
|
|
protected function renderClientControlScript($writer) |
|
139
|
|
|
{ |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Ensure that the ID attribute is rendered and registers the javascript code |
|
144
|
|
|
* for initializing the active control. |
|
145
|
|
|
*/ |
|
146
|
|
|
protected function addAttributesToRender($writer) |
|
147
|
|
|
{ |
|
148
|
|
|
parent::addAttributesToRender($writer); |
|
149
|
|
|
$writer->addAttribute('id',$this->getClientID()); |
|
150
|
|
|
if ($this->getAutoPostBack()) |
|
151
|
|
|
$this->getActiveControl()->registerCallbackClientScript( |
|
152
|
|
|
$this->getClientClassName(), $this->getPostBackOptions()); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.