1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* TCallbackClientSide class file |
4
|
|
|
* |
5
|
|
|
* @author Wei Zhuo <weizhuo[at]gamil[dot]com> |
6
|
|
|
* @link https://github.com/pradosoft/prado |
7
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/LICENSE |
8
|
|
|
* @package Prado\Web\UI\ActiveControls |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Prado\Web\UI\ActiveControls; |
12
|
|
|
|
13
|
|
|
use Prado\TPropertyValue; |
14
|
|
|
use Prado\Web\UI\TClientSideOptions; |
15
|
|
|
use Prado\Web\UI\TControl; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* TCallbackClientSide class. |
19
|
|
|
* |
20
|
|
|
* The following client side events are executing in order if the callback |
21
|
|
|
* request and response are send and received successfuly. |
22
|
|
|
* |
23
|
|
|
* - <b>onPreDispatch</b> executed before a request is dispatched. |
24
|
|
|
* - <b>onUninitialized</b> executed when callback request is uninitialized. |
25
|
|
|
* - <b>onLoading</b>* executed when callback request is initiated |
26
|
|
|
* - <b>onLoaded</b>* executed when callback request begins. |
27
|
|
|
* - <b>onInteractive</b> executed when callback request is in progress. |
28
|
|
|
* - <b>onComplete</b>executed when callback response returns. |
29
|
|
|
* - <b>onSuccess</b> executed when callback request returns and is successful. |
30
|
|
|
* - <b>onFailure</b> executed when callback request returns and fails. |
31
|
|
|
* - <b>onException</b> raised when callback request fails due to request/response errors. |
32
|
|
|
* |
33
|
|
|
* * Note that theses 2 events are not fired correctly by Opera. To make |
34
|
|
|
* them work in this browser, Prado will fire them just after onPreDispatch. |
35
|
|
|
* |
36
|
|
|
* In a general way, onUninitialized, onLoading, onLoaded and onInteractive events |
37
|
|
|
* are not implemented consistently in all browsers.When cross browser compatibility is |
38
|
|
|
* needed, it is best to avoid use them |
39
|
|
|
* |
40
|
|
|
* The OnSuccess and OnFailure events are raised when the |
41
|
|
|
* response is returned. A successful request/response will raise |
42
|
|
|
* OnSuccess event otherwise OnFailure will be raised. |
43
|
|
|
* |
44
|
|
|
* - <b>PostState</b> true to collect the form inputs and post them during callback, default is true. |
45
|
|
|
* - <b>RequestTimeOut</b> The request timeout in milliseconds. |
46
|
|
|
* - <b>RetryLimit</b> The number of times the request is retried when it timeouts, default 1 |
47
|
|
|
* - <b>EnablePageStateUpdate</b> enable the callback response to enable the |
48
|
|
|
* viewstate update. |
49
|
|
|
* |
50
|
|
|
* @author Wei Zhuo <weizhuo[at]gamil[dot]com> |
51
|
|
|
* @package Prado\Web\UI\ActiveControls |
52
|
|
|
* @since 3.1 |
53
|
|
|
*/ |
54
|
|
|
class TCallbackClientSide extends TClientSideOptions |
55
|
|
|
{ |
56
|
|
|
/** |
57
|
|
|
* Returns javascript statement enclosed within a javascript function. |
58
|
|
|
* @param string $javascript javascript statement |
59
|
|
|
* @return string javascript statement wrapped in a javascript function |
60
|
|
|
*/ |
61
|
|
|
protected function ensureFunction($javascript) |
62
|
|
|
{ |
63
|
|
|
return "function(sender, parameter){ {$javascript} }"; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $javascript javascript code to be executed before a request is dispatched. |
68
|
|
|
*/ |
69
|
|
|
public function setOnPreDispatch($javascript) |
70
|
|
|
{ |
71
|
|
|
$this->setFunction('onPreDispatch', $javascript); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string javascript code to be executed before a request is dispatched. |
76
|
|
|
*/ |
77
|
|
|
public function getOnPreDispatch() |
78
|
|
|
{ |
79
|
|
|
return $this->getOption('onPreDispatch'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string javascript code for client-side onUninitialized event |
84
|
|
|
*/ |
85
|
|
|
public function getOnUninitialized() |
86
|
|
|
{ |
87
|
|
|
return $this->getOption('onUninitialized'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $javascript javascript code for client-side onUninitialized event. |
92
|
|
|
*/ |
93
|
|
|
public function setOnUninitialized($javascript) |
94
|
|
|
{ |
95
|
|
|
$this->setFunction('onUninitialized', $javascript); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return string javascript code for client-side onLoading event |
100
|
|
|
*/ |
101
|
|
|
public function getOnLoading() |
102
|
|
|
{ |
103
|
|
|
return $this->getOption('onLoading'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param string $javascript javascript code for client-side onLoading event. |
108
|
|
|
*/ |
109
|
|
|
public function setOnLoading($javascript) |
110
|
|
|
{ |
111
|
|
|
$this->setFunction('onLoading', $javascript); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string javascript code for client-side onLoaded event |
116
|
|
|
*/ |
117
|
|
|
public function getOnLoaded() |
118
|
|
|
{ |
119
|
|
|
return $this->getOption('onLoaded'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param string $javascript javascript code for client-side onLoaded event. |
124
|
|
|
*/ |
125
|
|
|
public function setOnLoaded($javascript) |
126
|
|
|
{ |
127
|
|
|
$this->setFunction('onLoaded', $javascript); |
128
|
|
|
} |
129
|
|
|
/** |
130
|
|
|
* @return string javascript code for client-side onInteractive event |
131
|
|
|
*/ |
132
|
|
|
public function getOnInteractive() |
133
|
|
|
{ |
134
|
|
|
return $this->getOption('onInteractive'); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param string $javascript javascript code for client-side onInteractive event. |
139
|
|
|
*/ |
140
|
|
|
public function setOnInteractive($javascript) |
141
|
|
|
{ |
142
|
|
|
$this->setFunction('onInteractive', $javascript); |
143
|
|
|
} |
144
|
|
|
/** |
145
|
|
|
* @return string javascript code for client-side onComplete event |
146
|
|
|
*/ |
147
|
|
|
public function getOnComplete() |
148
|
|
|
{ |
149
|
|
|
return $this->getOption('onComplete'); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param string $javascript javascript code for client-side onComplete event. |
154
|
|
|
*/ |
155
|
|
|
public function setOnComplete($javascript) |
156
|
|
|
{ |
157
|
|
|
$this->setFunction('onComplete', $javascript); |
158
|
|
|
} |
159
|
|
|
/** |
160
|
|
|
* @return string javascript code for client-side onSuccess event |
161
|
|
|
*/ |
162
|
|
|
public function getOnSuccess() |
163
|
|
|
{ |
164
|
|
|
return $this->getOption('onSuccess'); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param string $javascript javascript code for client-side onSuccess event. |
169
|
|
|
*/ |
170
|
|
|
public function setOnSuccess($javascript) |
171
|
|
|
{ |
172
|
|
|
$this->setFunction('onSuccess', $javascript); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @return string javascript code for client-side onFailure event |
177
|
|
|
*/ |
178
|
|
|
public function getOnFailure() |
179
|
|
|
{ |
180
|
|
|
return $this->getOption('onFailure'); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @param string $javascript javascript code for client-side onFailure event. |
185
|
|
|
*/ |
186
|
|
|
public function setOnFailure($javascript) |
187
|
|
|
{ |
188
|
|
|
$this->setFunction('onFailure', $javascript); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @return string javascript code for client-side onException event |
193
|
|
|
*/ |
194
|
|
|
public function getOnException() |
195
|
|
|
{ |
196
|
|
|
return $this->getOption('onException'); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param string $javascript javascript code for client-side onException event. |
201
|
|
|
*/ |
202
|
|
|
public function setOnException($javascript) |
203
|
|
|
{ |
204
|
|
|
$this->setFunction('onException', $javascript); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @return bool true to post the inputs of the form on callback, default |
209
|
|
|
* is post the inputs on callback. |
210
|
|
|
*/ |
211
|
|
|
public function getPostState() |
212
|
|
|
{ |
213
|
|
|
return $this->getOption('PostInputs'); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @param bool $value true to post the inputs of the form with callback |
218
|
|
|
* requests. Default is to post the inputs. |
219
|
|
|
*/ |
220
|
|
|
public function setPostState($value) |
221
|
|
|
{ |
222
|
|
|
$this->setOption('PostInputs', TPropertyValue::ensureBoolean($value)); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @return int callback request timeout. |
227
|
|
|
*/ |
228
|
|
|
public function getRequestTimeOut() |
229
|
|
|
{ |
230
|
|
|
return $this->getOption('RequestTimeOut'); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @param int $value callback request timeout |
235
|
|
|
*/ |
236
|
|
|
public function setRequestTimeOut($value) |
237
|
|
|
{ |
238
|
|
|
$this->setOption('RequestTimeOut', TPropertyValue::ensureInteger($value)); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Set to true to enable the callback response to enable the viewstate |
243
|
|
|
* update. This will automatically set HasPrority to true. |
244
|
|
|
* @param bool $value true enables the callback response to update the |
245
|
|
|
* viewstate. |
246
|
|
|
*/ |
247
|
|
|
public function setEnablePageStateUpdate($value) |
248
|
|
|
{ |
249
|
|
|
$enabled = TPropertyValue::ensureBoolean($value); |
250
|
|
|
$this->setOption('EnablePageStateUpdate', $enabled); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @return bool client-side viewstate will be updated on callback |
255
|
|
|
* response if true. Default is true. |
256
|
|
|
*/ |
257
|
|
|
public function getEnablePageStateUpdate() |
258
|
|
|
{ |
259
|
|
|
$option = $this->getOption('EnablePageStateUpdate'); |
260
|
|
|
return ($option === null) ? true : $option; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @return string post back target ID |
265
|
|
|
*/ |
266
|
|
|
public function getPostBackTarget() |
267
|
|
|
{ |
268
|
|
|
return $this->getOption('EventTarget'); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @param string $value post back target ID |
273
|
|
|
*/ |
274
|
|
|
public function setPostBackTarget($value) |
275
|
|
|
{ |
276
|
|
|
if ($value instanceof TControl) { |
277
|
|
|
$value = $value->getUniqueID(); |
278
|
|
|
} |
279
|
|
|
$this->setOption('EventTarget', $value); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @return string post back event parameter. |
284
|
|
|
*/ |
285
|
|
|
public function getPostBackParameter() |
286
|
|
|
{ |
287
|
|
|
return $this->getOption('EventParameter'); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @param string $value post back event parameter. |
292
|
|
|
*/ |
293
|
|
|
public function setPostBackParameter($value) |
294
|
|
|
{ |
295
|
|
|
$this->setOption('EventParameter', $value); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @return int number of retries before an ajax callback is considered failed |
300
|
|
|
* @since 4.1 |
301
|
|
|
*/ |
302
|
|
|
public function getRetryLimit() |
303
|
|
|
{ |
304
|
|
|
return $this->getOption('RetryLimit'); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* @param bool $value number of retries before an ajax callback is considered failed. |
309
|
|
|
* The request will be retried only when it fails for timeout. |
310
|
|
|
* The default is 1 (do not retry). |
311
|
|
|
* @since 4.1 |
312
|
|
|
*/ |
313
|
|
|
public function setRetryLimit($value) |
314
|
|
|
{ |
315
|
|
|
$this->setOption('RetryLimit', TPropertyValue::ensureInteger($value)); |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
|