| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TTimeTriggeredCallback class file.
|
|
|
4 |
*
|
|
|
5 |
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: TTimeTriggeredCallback.php 2532 2008-10-16 09:12:20Z tof $
|
|
|
10 |
* @package System.Web.UI.ActiveControls
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* Load active callback control.
|
|
|
15 |
*/
|
|
|
16 |
Prado::using('System.Web.UI.ActiveControls.TCallback');
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* TTimeTriggeredCallback class.
|
|
|
20 |
*
|
|
|
21 |
* TTimeTriggeredCallback sends callback request every {@link setInterval Interval} seconds.
|
|
|
22 |
* Upon each callback request, the {@link onCallback OnCallback} event is raised.
|
|
|
23 |
*
|
|
|
24 |
* The timer can be started by calling {@link startTimer()} and stopped using
|
|
|
25 |
* {@link stopTimer()}. The timer can be automatically started when
|
|
|
26 |
* {@link setStartTimerOnLoad StartTimerOnLoad} is true.
|
|
|
27 |
*
|
|
|
28 |
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
|
|
|
29 |
* @version $Id: TTimeTriggeredCallback.php 2532 2008-10-16 09:12:20Z tof $
|
|
|
30 |
* @package System.Web.UI.ActiveControls
|
|
|
31 |
* @since 3.1
|
|
|
32 |
*/
|
|
|
33 |
class TTimeTriggeredCallback extends TCallback
|
|
|
34 |
{
|
|
|
35 |
/**
|
|
|
36 |
* @return float seconds between callback requests. Default is 1 second.
|
|
|
37 |
*/
|
|
|
38 |
public function getInterval()
|
|
|
39 |
{
|
|
|
40 |
return $this->getViewState('Interval', 1);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* @param float seconds between callback requests, must be a positive number, default is 1 second.
|
|
|
45 |
*/
|
|
|
46 |
public function setInterval($value)
|
|
|
47 |
{
|
|
|
48 |
$interval = TPropertyValue::ensureFloat($value);
|
|
|
49 |
if($interval <= 0)
|
|
|
50 |
throw new TConfigurationException('callback_interval_be_positive', $this->getID());
|
|
|
51 |
$this->setViewState('Interval', $interval, 1);
|
|
|
52 |
if ($this->getActiveControl()->canUpdateClientSide()){
|
|
|
53 |
$client = $this->getPage()->getCallbackClient();
|
|
|
54 |
$client->callClientFunction('Prado.WebUI.TTimeTriggeredCallback.setInterval', array($this, $interval));
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* Registers the javascript code to start the timer.
|
|
|
60 |
*/
|
|
|
61 |
public function startTimer()
|
|
|
62 |
{
|
|
|
63 |
$client = $this->getPage()->getCallbackClient();
|
|
|
64 |
$client->callClientFunction('Prado.WebUI.TTimeTriggeredCallback.start', array($this));
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* Registers the javascript code to stop the timer.
|
|
|
69 |
*/
|
|
|
70 |
public function stopTimer()
|
|
|
71 |
{
|
|
|
72 |
$client = $this->getPage()->getCallbackClient();
|
|
|
73 |
$client->callClientFunction('Prado.WebUI.TTimeTriggeredCallback.stop', array($this));
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
* @param boolean true to start the timer when page loads.
|
|
|
78 |
*/
|
|
|
79 |
public function setStartTimerOnLoad($value)
|
|
|
80 |
{
|
|
|
81 |
$this->setViewState('StartTimerOnLoad',
|
|
|
82 |
TPropertyValue::ensureBoolean($value), false);
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
/**
|
|
|
86 |
* @return boolean true to start the timer when page loads.
|
|
|
87 |
*/
|
|
|
88 |
public function getStartTimerOnLoad()
|
|
|
89 |
{
|
|
|
90 |
return $this->getViewState('StartTimerOnLoad', false);
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
/**
|
|
|
94 |
* @return array list of timer options for client-side.
|
|
|
95 |
*/
|
|
|
96 |
protected function getTriggerOptions()
|
|
|
97 |
{
|
|
|
98 |
$options['ID'] = $this->getClientID();
|
|
|
99 |
$options['EventTarget']= $this->getUniqueID();
|
|
|
100 |
$options['Interval'] = $this->getInterval();
|
|
|
101 |
return $options;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
/**
|
|
|
105 |
* Registers the javascript code for initializing the active control.
|
|
|
106 |
* @param THtmlWriter the renderer.
|
|
|
107 |
*/
|
|
|
108 |
public function render($writer)
|
|
|
109 |
{
|
|
|
110 |
parent::render($writer);
|
|
|
111 |
$this->getActiveControl()->registerCallbackClientScript(
|
|
|
112 |
$this->getClientClassName(), $this->getTriggerOptions());
|
|
|
113 |
if($this->getStartTimerOnLoad()){
|
|
|
114 |
$id = $this->getClientID();
|
|
|
115 |
$code = "Prado.WebUI.TTimeTriggeredCallback.start('{$id}');";
|
|
|
116 |
$cs = $this->getPage()->getClientScript();
|
|
|
117 |
$cs->registerEndScript("{$id}:start", $code);
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
/**
|
|
|
122 |
* @return string corresponding javascript class name for TTimeTriggeredCallback.
|
|
|
123 |
*/
|
|
|
124 |
protected function getClientClassName()
|
|
|
125 |
{
|
|
|
126 |
return 'Prado.WebUI.TTimeTriggeredCallback';
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
?>
|