3 * TCallbackClientSide class file
5 * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
6 * @link http://www.pradosoft.com/
7 * @copyright Copyright © 2005-2014 PradoSoft
8 * @license http://www.pradosoft.com/license/
9 * @package System.Web.UI.ActiveControls
13 * TCallbackClientSide class.
15 * The following client side events are executing in order if the callback
16 * request and response are send and received successfuly.
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.
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.
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
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.
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>HasPriority</b> true to ensure that the callback request will be sent
42 * immediately and will abort existing prioritized requests. It does not affect
43 * callbacks that are not prioritized.
44 * - <b>EnablePageStateUpdate</b> enable the callback response to enable the
45 * viewstate update. This will automatically set HasPriority to true when enabled.
47 * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
48 * @package System.Web.UI.ActiveControls
51 class TCallbackClientSide extends TClientSideOptions
54 * Returns javascript statement enclosed within a javascript function.
55 * @param string javascript statement
56 * @return string javascript statement wrapped in a javascript function
58 protected function ensureFunction($javascript)
60 return "function(sender, parameter){ {$javascript} }";
64 * @param string javascript code to be executed before a request is dispatched.
66 public function setOnPreDispatch($javascript)
68 $this->setFunction('onPreDispatch', $javascript);
72 * @return string javascript code to be executed before a request is dispatched.
74 public function getOnPreDispatch()
76 return $this->getOption('onPreDispatch');
80 * @return string javascript code for client-side onUninitialized event
82 public function getOnUninitialized()
84 return $this->getOption('onUninitialized');
88 * @param string javascript code for client-side onUninitialized event.
90 public function setOnUninitialized($javascript)
92 $this->setFunction('onUninitialized', $javascript);
96 * @return string javascript code for client-side onLoading event
98 public function getOnLoading()
100 return $this->getOption('onLoading');
104 * @param string javascript code for client-side onLoading event.
106 public function setOnLoading($javascript)
108 $this->setFunction('onLoading', $javascript);
112 * @return string javascript code for client-side onLoaded event
114 public function getOnLoaded()
116 return $this->getOption('onLoaded');
120 * @param string javascript code for client-side onLoaded event.
122 public function setOnLoaded($javascript)
124 $this->setFunction('onLoaded', $javascript);
127 * @return string javascript code for client-side onInteractive event
129 public function getOnInteractive()
131 return $this->getOption('onInteractive');
135 * @param string javascript code for client-side onInteractive event.
137 public function setOnInteractive($javascript)
139 $this->setFunction('onInteractive', $javascript);
142 * @return string javascript code for client-side onComplete event
144 public function getOnComplete()
146 return $this->getOption('onComplete');
150 * @param string javascript code for client-side onComplete event.
152 public function setOnComplete($javascript)
154 $this->setFunction('onComplete', $javascript);
157 * @return string javascript code for client-side onSuccess event
159 public function getOnSuccess()
161 return $this->getOption('onSuccess');
165 * @param string javascript code for client-side onSuccess event.
167 public function setOnSuccess($javascript)
169 $this->setFunction('onSuccess', $javascript);
173 * @return string javascript code for client-side onFailure event
175 public function getOnFailure()
177 return $this->getOption('onFailure');
181 * @param string javascript code for client-side onFailure event.
183 public function setOnFailure($javascript)
185 $this->setFunction('onFailure', $javascript);
189 * @return string javascript code for client-side onException event
191 public function getOnException()
193 return $this->getOption('onException');
197 * @param string javascript code for client-side onException event.
199 public function setOnException($javascript)
201 $this->setFunction('onException', $javascript);
205 * @return boolean true to post the inputs of the form on callback, default
206 * is post the inputs on callback.
208 public function getPostState()
210 return $this->getOption('PostInputs');
214 * @param boolean true to post the inputs of the form with callback
215 * requests. Default is to post the inputs.
217 public function setPostState($value)
219 $this->setOption('PostInputs', TPropertyValue::ensureBoolean($value));
223 * @return integer callback request timeout.
225 public function getRequestTimeOut()
227 return $this->getOption('RequestTimeOut');
231 * @param integer callback request timeout
233 public function setRequestTimeOut($value)
235 $this->setOption('RequestTimeOut', TPropertyValue::ensureInteger($value));
239 * @return boolean true if the callback request has priority and will abort
240 * existing prioritized request in order to send immediately. It does not
241 * affect callbacks that are not prioritized. Default is true.
243 public function getHasPriority()
245 $option = $this->getOption('HasPriority');
246 return ($option===null) ? true : $option;
250 * @param boolean true to ensure that the callback request will be sent
251 * immediately and will abort existing prioritized requests. It does not
252 * affect callbacks that are not prioritized.
254 public function setHasPriority($value)
256 $hasPriority = TPropertyValue::ensureBoolean($value);
257 $this->setOption('HasPriority', $hasPriority);
259 $this->setEnablePageStateUpdate(false);
263 * Set to true to enable the callback response to enable the viewstate
264 * update. This will automatically set HasPrority to true.
265 * @param boolean true enables the callback response to update the
268 public function setEnablePageStateUpdate($value)
270 $enabled = TPropertyValue::ensureBoolean($value);
271 $this->setOption('EnablePageStateUpdate', $enabled);
273 $this->setHasPriority(true);
277 * @return boolean client-side viewstate will be updated on callback
278 * response if true. Default is true.
280 public function getEnablePageStateUpdate()
282 $option = $this->getOption('EnablePageStateUpdate');
283 return ($option===null) ? true : $option;
287 * @return string post back target ID
289 public function getPostBackTarget()
291 return $this->getOption('EventTarget');
295 * @param string post back target ID
297 public function setPostBackTarget($value)
299 if($value instanceof TControl)
300 $value = $value->getUniqueID();
301 $this->setOption('EventTarget', $value);
305 * @return string post back event parameter.
307 public function getPostBackParameter()
309 return $this->getOption('EventParameter');
313 * @param string post back event parameter.
315 public function setPostBackParameter($value)
317 $this->setOption('EventParameter', $value);