Completed
Pull Request — master (#578)
by Fabio
19:18 queued 07:13
created

TCallbackClientSide   A

Complexity

Total Complexity 34

Size/Duplication

Total Lines 267
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 34
c 2
b 0
f 0
lcom 3
cbo 3
dl 0
loc 267
rs 9.2

31 Methods

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