3 * TTimeTriggeredCallback 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 * Load active callback control.
15 Prado::using('System.Web.UI.ActiveControls.TCallback');
18 * TTimeTriggeredCallback class.
20 * TTimeTriggeredCallback sends callback request every {@link setInterval Interval} seconds.
21 * Upon each callback request, the {@link onCallback OnCallback} event is raised.
23 * The timer can be started by calling {@link startTimer()} and stopped using
24 * {@link stopTimer()}. The timer can be automatically started when
25 * {@link setStartTimerOnLoad StartTimerOnLoad} is true.
27 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
28 * @package System.Web.UI.ActiveControls
31 class TTimeTriggeredCallback extends TCallback
34 * @return float seconds between callback requests. Default is 1 second.
36 public function getInterval()
38 return $this->getViewState('Interval', 1);
42 * @param float seconds between callback requests, must be a positive number, default is 1 second.
44 public function setInterval($value)
46 $interval = TPropertyValue::ensureFloat($value);
48 throw new TConfigurationException('callback_interval_be_positive', $this->getID());
49 $this->setViewState('Interval', $interval, 1);
50 if ($this->getActiveControl()->canUpdateClientSide()){
51 $client = $this->getPage()->getCallbackClient();
52 $client->callClientFunction('Prado.WebUI.TTimeTriggeredCallback.setTimerInterval', array($this, $interval));
57 * Registers the javascript code to start the timer.
59 public function startTimer()
61 $client = $this->getPage()->getCallbackClient();
62 $client->callClientFunction('Prado.WebUI.TTimeTriggeredCallback.start', array($this));
66 * Registers the javascript code to stop the timer.
68 public function stopTimer()
70 $client = $this->getPage()->getCallbackClient();
71 $client->callClientFunction('Prado.WebUI.TTimeTriggeredCallback.stop', array($this));
75 * @param boolean true to start the timer when page loads.
77 public function setStartTimerOnLoad($value)
79 $this->setViewState('StartTimerOnLoad',
80 TPropertyValue::ensureBoolean($value), false);
84 * @return boolean true to start the timer when page loads.
86 public function getStartTimerOnLoad()
88 return $this->getViewState('StartTimerOnLoad', false);
92 * @return array list of timer options for client-side.
94 protected function getTriggerOptions()
96 $options['ID'] = $this->getClientID();
97 $options['EventTarget']= $this->getUniqueID();
98 $options['Interval'] = $this->getInterval();
103 * Registers the javascript code for initializing the active control.
104 * @param THtmlWriter the renderer.
106 public function render($writer)
108 parent::render($writer);
109 $this->getActiveControl()->registerCallbackClientScript(
110 $this->getClientClassName(), $this->getTriggerOptions());
111 if($this->getStartTimerOnLoad()){
112 $id = $this->getClientID();
113 $code = "Prado.WebUI.TTimeTriggeredCallback.start('{$id}');";
114 $cs = $this->getPage()->getClientScript();
115 $cs->registerEndScript("{$id}:start", $code);
120 * @return string corresponding javascript class name for TTimeTriggeredCallback.
122 protected function getClientClassName()
124 return 'Prado.WebUI.TTimeTriggeredCallback';