Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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