summaryrefslogtreecommitdiff
path: root/framework/Web/UI/ActiveControls/TCallbackClientSide.php
blob: 4cb482adf5febed7fba8eae204b76098bf8c0eac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php
/**
 * TCallbackClientSide class file
 *
 * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
 * @link https://github.com/pradosoft/prado
 * @copyright Copyright &copy; 2005-2016 The PRADO Group
 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
 * @package System.Web.UI.ActiveControls
 */

/**
 * TCallbackClientSide class.
 *
 * The following client side events are executing in order if the callback
 * request and response are send and received successfuly.
 *
 * - <b>onPreDispatch</b> executed before a request is dispatched.
 * - <b>onUninitialized</b> executed when callback request is uninitialized.
 * - <b>onLoading</b>* executed when callback request is initiated
 * - <b>onLoaded</b>* executed when callback request begins.
 * - <b>onInteractive</b> executed when callback request is in progress.
 * - <b>onComplete</b>executed when callback response returns.
 * - <b>onSuccess</b> executed when callback request returns and is successful.
 * - <b>onFailure</b> executed when callback request returns and fails.
 * - <b>onException</b> raised when callback request fails due to request/response errors.
 *
 * * Note that theses 2 events are not fired correctly by Opera. To make
 *   them work in this browser, Prado will fire them just after onPreDispatch.
 *
 * In a general way, onUninitialized, onLoading, onLoaded and onInteractive events
 * are not implemented consistently in all browsers.When cross browser compatibility is
 * needed, it is best to avoid use them
 *
 * The OnSuccess and OnFailure events are raised when the
 * response is returned. A successful request/response will raise
 * OnSuccess event otherwise OnFailure will be raised.
 *
 * - <b>PostState</b> true to collect the form inputs and post them during callback, default is true.
 * - <b>RequestTimeOut</b> The request timeout in milliseconds.
 * - <b>EnablePageStateUpdate</b> enable the callback response to enable the
 *   viewstate update.
 *
 * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
 * @package System.Web.UI.ActiveControls
 * @since 3.1
 */
class TCallbackClientSide extends TClientSideOptions
{
	/**
	 * Returns javascript statement enclosed within a javascript function.
	 * @param string javascript statement
	 * @return string javascript statement wrapped in a javascript function
	 */
	protected function ensureFunction($javascript)
	{
		return "function(sender, parameter){ {$javascript} }";
	}

	/**
	 * @param string javascript code to be executed before a request is dispatched.
	 */
	public function setOnPreDispatch($javascript)
	{
		$this->setFunction('onPreDispatch', $javascript);
	}

	/**
	 * @return string javascript code to be executed before a request is dispatched.
	 */
	public function getOnPreDispatch()
	{
		return $this->getOption('onPreDispatch');
	}

	/**
	 * @return string javascript code for client-side onUninitialized event
	 */
	public function getOnUninitialized()
	{
		return $this->getOption('onUninitialized');
	}

	/**
	 * @param string javascript code for client-side onUninitialized event.
	 */
	public function setOnUninitialized($javascript)
	{
		$this->setFunction('onUninitialized', $javascript);
	}

	/**
	 * @return string javascript code for client-side onLoading event
	 */
	public function getOnLoading()
	{
		return $this->getOption('onLoading');
	}

	/**
	 * @param string javascript code for client-side onLoading event.
	 */
	public function setOnLoading($javascript)
	{
		$this->setFunction('onLoading', $javascript);
	}

	/**
	 * @return string javascript code for client-side onLoaded event
	 */
	public function getOnLoaded()
	{
		return $this->getOption('onLoaded');
	}

	/**
	 * @param string javascript code for client-side onLoaded event.
	 */
	public function setOnLoaded($javascript)
	{
		$this->setFunction('onLoaded', $javascript);
	}
	/**
	 * @return string javascript code for client-side onInteractive event
	 */
	public function getOnInteractive()
	{
		return $this->getOption('onInteractive');
	}

	/**
	 * @param string javascript code for client-side onInteractive event.
	 */
	public function setOnInteractive($javascript)
	{
		$this->setFunction('onInteractive', $javascript);
	}
	/**
	 * @return string javascript code for client-side onComplete event
	 */
	public function getOnComplete()
	{
		return $this->getOption('onComplete');
	}

	/**
	 * @param string javascript code for client-side onComplete event.
	 */
	public function setOnComplete($javascript)
	{
		$this->setFunction('onComplete', $javascript);
	}
	/**
	 * @return string javascript code for client-side onSuccess event
	 */
	public function getOnSuccess()
	{
		return $this->getOption('onSuccess');
	}

	/**
	 * @param string javascript code for client-side onSuccess event.
	 */
	public function setOnSuccess($javascript)
	{
		$this->setFunction('onSuccess', $javascript);
	}

	/**
	 * @return string javascript code for client-side onFailure event
	 */
	public function getOnFailure()
	{
		return $this->getOption('onFailure');
	}

	/**
	 * @param string javascript code for client-side onFailure event.
	 */
	public function setOnFailure($javascript)
	{
		$this->setFunction('onFailure', $javascript);
	}

	/**
	 * @return string javascript code for client-side onException event
	 */
	public function getOnException()
	{
		return $this->getOption('onException');
	}

	/**
	 * @param string javascript code for client-side onException event.
	 */
	public function setOnException($javascript)
	{
		$this->setFunction('onException', $javascript);
	}

	/**
	 * @return boolean true to post the inputs of the form on callback, default
	 * is post the inputs on callback.
	 */
	public function getPostState()
	{
		return $this->getOption('PostInputs');
	}

	/**
	 * @param boolean true to post the inputs of the form with callback
	 * requests. Default is to post the inputs.
	 */
	public function setPostState($value)
	{
		$this->setOption('PostInputs', TPropertyValue::ensureBoolean($value));
	}

	/**
	 * @return integer callback request timeout.
	 */
	public function getRequestTimeOut()
	{
		return $this->getOption('RequestTimeOut');
	}

	/**
	 * @param integer callback request timeout
	 */
	public function setRequestTimeOut($value)
	{
		$this->setOption('RequestTimeOut', TPropertyValue::ensureInteger($value));
	}

	/**
	 * @return boolean true if the callback request has priority and will abort
	 * existing prioritized request in order to send immediately. It does not
	 * affect callbacks that are not prioritized. Default is true.
	 * @deprecated since 3.3.0
	 */
	public function getHasPriority()
	{
		return true;
	}

	/**
	 * @param boolean true to ensure that the callback request will be sent
	 * immediately and will abort existing prioritized requests. It does not
	 * affect callbacks that are not prioritized.
	 * @deprecated since 3.3.0
	 */
	public function setHasPriority($value)
	{
		// mimic the old behavior
		if(!$value)
			$this->setEnablePageStateUpdate(false);
	}

	/**
	 * Set to true to enable the callback response to enable the viewstate
	 * update. This will automatically set HasPrority to true.
	 * @param boolean true enables the callback response to update the
	 * viewstate.
	 */
	public function setEnablePageStateUpdate($value)
	{
		$enabled = TPropertyValue::ensureBoolean($value);
		$this->setOption('EnablePageStateUpdate', $enabled);
	}

	/**
	 * @return boolean client-side viewstate will be updated on callback
	 * response if true. Default is true.
	 */
	public function getEnablePageStateUpdate()
	{
		$option = $this->getOption('EnablePageStateUpdate');
		return ($option===null) ? true : $option;
	}

	/**
	 * @return string post back target ID
	 */
	public function getPostBackTarget()
	{
		return $this->getOption('EventTarget');
	}

	/**
	 * @param string post back target ID
	 */
	public function setPostBackTarget($value)
	{
		if($value instanceof TControl)
			$value = $value->getUniqueID();
		$this->setOption('EventTarget', $value);
	}

	/**
	 * @return string post back event parameter.
	 */
	public function getPostBackParameter()
	{
		return $this->getOption('EventParameter');
	}

	/**
	 * @param string post back event parameter.
	 */
	public function setPostBackParameter($value)
	{
		$this->setOption('EventParameter', $value);
	}
}