|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TActiveRatingList class file. |
|
5
|
|
|
* |
|
6
|
|
|
* @author Wei Zhuo <weizhuo[at]gamil[dot]com> |
|
7
|
|
|
* @author Bradley Booms <bradley[dot]booms[at]gmail[dot]com> |
|
8
|
|
|
* @link https://github.com/pradosoft/prado |
|
9
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/LICENSE |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Prado\Web\UI\ActiveControls; |
|
13
|
|
|
|
|
14
|
|
|
use Prado\Web\UI\WebControls\TRatingList; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* TActiveRatingList Class |
|
18
|
|
|
* |
|
19
|
|
|
* Displays clickable images that represent a TRadioButtonList |
|
20
|
|
|
* |
|
21
|
|
|
* @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
22
|
|
|
* @author Bradley Booms <bradley[dot]booms[at]gmail[dot]com> |
|
23
|
|
|
* @since 3.1 |
|
24
|
|
|
* @method TActiveControlAdapter getAdapter() |
|
25
|
|
|
*/ |
|
26
|
|
|
class TActiveRatingList extends TRatingList 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
|
|
|
$this->setAdapter(new TActiveListControlAdapter($this)); |
|
36
|
|
|
$this->setAutoPostBack(true); |
|
37
|
|
|
parent::__construct(); |
|
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->getActiveControl()->getClientSide(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Raises the callback event. This method is required by {@see |
|
58
|
|
|
* ICallbackEventHandler} interface. |
|
59
|
|
|
* This method is mainly used by framework and control developers. |
|
60
|
|
|
* @param TCallbackEventParameter $param the event parameter |
|
61
|
|
|
*/ |
|
62
|
|
|
public function raiseCallbackEvent($param) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->onCallback($param); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* This method is invoked when a callback is requested. The method raises |
|
69
|
|
|
* 'OnCallback' event to fire up the event handlers. If you override this |
|
70
|
|
|
* method, be sure to call the parent implementation so that the event |
|
71
|
|
|
* handler can be invoked. |
|
72
|
|
|
* @param TCallbackEventParameter $param event parameter to be passed to the event handlers |
|
73
|
|
|
*/ |
|
74
|
|
|
public function onCallback($param) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->raiseEvent('OnCallback', $this, $param); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param bool $value whether the items in the column can be edited |
|
81
|
|
|
*/ |
|
82
|
|
|
public function setReadOnly($value) |
|
83
|
|
|
{ |
|
84
|
|
|
if (parent::getReadOnly() === $value) { |
|
85
|
|
|
return; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
parent::setReadOnly($value); |
|
89
|
|
|
$value = $this->getReadOnly(); |
|
90
|
|
|
$this->callClientFunction('setReadOnly', $value); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param float $value rating value, also sets the selected Index |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setRating($value) |
|
97
|
|
|
{ |
|
98
|
|
|
if (parent::getRating() === $value) { |
|
99
|
|
|
return; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
parent::setRating($value); |
|
103
|
|
|
$value = $this->getRating(); |
|
104
|
|
|
$this->callClientFunction('setRating', $value); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Calls the client-side static method for this control class. |
|
109
|
|
|
* @param string $func static method name |
|
110
|
|
|
* @param mixed $value method parmaeter |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function callClientFunction($func, $value) |
|
113
|
|
|
{ |
|
114
|
|
|
if ($this->getActiveControl()->canUpdateClientSide()) { |
|
115
|
|
|
$client = $this->getPage()->getCallbackClient(); |
|
116
|
|
|
$code = 'Prado.Registry[\'' . $this->getClientID() . '\'].' . $func . '(' . $value . ')'; |
|
117
|
|
|
$client->evaluateScript($code); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param string $value caption text |
|
123
|
|
|
*/ |
|
124
|
|
|
public function setCaption($value) |
|
125
|
|
|
{ |
|
126
|
|
|
if (parent::getCaption() === $value) { |
|
127
|
|
|
return; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
parent::setCaption($value); |
|
131
|
|
|
// if it's an active control, this should not be needed. |
|
132
|
|
|
$this->callClientFunction('setCaption', $value); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Ensure that the ID attribute is rendered and registers the javascript code |
|
137
|
|
|
* for initializing the active control. |
|
138
|
|
|
* @param mixed $writer |
|
139
|
|
|
*/ |
|
140
|
|
|
protected function addAttributesToRender($writer) |
|
141
|
|
|
{ |
|
142
|
|
|
parent::addAttributesToRender($writer); |
|
143
|
|
|
$this->getActiveControl()->registerCallbackClientScript( |
|
144
|
|
|
$this->getClientClassName(), |
|
145
|
|
|
$this->getPostBackOptions() |
|
146
|
|
|
); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Gets the name of the javascript class responsible for performing postback for this control. |
|
151
|
|
|
* This method overrides the parent implementation. |
|
152
|
|
|
* @return string the javascript class name |
|
153
|
|
|
*/ |
|
154
|
|
|
protected function getClientClassName() |
|
155
|
|
|
{ |
|
156
|
|
|
return 'Prado.WebUI.TActiveRatingList'; |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|