Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TValueTriggeredCallback 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: TValueTriggeredCallback.php 2541 2008-10-21 15:05:13Z qiang.xue $
10
 * @package System.Web.UI.ActiveControls
11
 */
12
 
13
/**
14
 * TValueTriggeredCallback Class
15
 *
16
 * Observes the value with {@link setPropertyName PropertyName} of a
17
 * control with {@link setControlID ControlID}. Changes to the observed
18
 * property value will trigger a new callback request. The property value is checked
19
 * for changes every{@link setInterval Interval} seconds.
20
 *
21
 * A {@link setDecayRate DecayRate} can be set to increase the polling
22
 * interval linearly if no changes are observed. Once a change is
23
 * observe, the polling interval is reset to the original value.
24
 *
25
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
26
 * @version $Id: TValueTriggeredCallback.php 2541 2008-10-21 15:05:13Z qiang.xue $
27
 * @package System.Web.UI.ActiveControls
28
 * @since 3.1
29
 */
30
class TValueTriggeredCallback extends TTriggeredCallback
31
{
32
	/**
33
	 * @return string The control property name to observe value changes.
34
	 */
35
	public function getPropertyName()
36
	{
37
		return $this->getViewState('PropertyName', '');
38
	}
39
 
40
	/**
41
	 * Sets the control property name to observe value changes that fires the callback request.
42
	 * @param string The control property name to observe value changes.
43
	 */
44
	public function setPropertyName($value)
45
	{
46
		$this->setViewState('PropertyName', $value, '');
47
	}
48
 
49
	/**
50
	 * Sets the polling interval in seconds to observe property changes.
51
	 * Default is 1 second.
52
	 * @param float polling interval in seconds.
53
	 */
54
	public function setInterval($value)
55
	{
56
		$this->setViewState('Interval', TPropertyValue::ensureFloat($value), 1);
57
	}
58
 
59
	/**
60
	 * @return float polling interval, 1 second default.
61
	 */
62
	public function getInterval()
63
	{
64
		return $this->getViewState('Interval', 1);
65
	}
66
 
67
	/**
68
	 * Gets the decay rate between callbacks. Default is 0;
69
	 * @return float decay rate between callbacks.
70
	 */
71
	public function getDecayRate()
72
	{
73
		return $this->getViewState('Decay', 0);
74
	}
75
 
76
	/**
77
	 * Sets the decay rate between callback. Default is 0;
78
	 * @param float decay rate between callbacks.
79
	 */
80
	public function setDecayRate($value)
81
	{
82
		$decay = TPropertyValue::ensureFloat($value);
83
		if($decay < 0)
84
			throw new TConfigurationException('callback_decay_be_not_negative', $this->getID());
85
		$this->setViewState('Decay', $decay);
86
	}
87
 
88
	/**
89
	 * @return array list of timer options for client-side.
90
	 */
91
	protected function getTriggerOptions()
92
	{
93
		$options = parent::getTriggerOptions();
94
		$options['PropertyName'] = $this->getPropertyName();
95
		$options['Interval'] = $this->getInterval();
96
		$options['Decay'] = $this->getDecayRate();
97
		return $options;
98
	}
99
 
100
	/**
101
	 * Registers the javascript code for initializing the active control.
102
	 * @param THtmlWriter the renderer.
103
	 */
104
	public function render($writer)
105
	{
106
		parent::render($writer);
107
		$this->getActiveControl()->registerCallbackClientScript(
108
			$this->getClientClassName(), $this->getTriggerOptions());
109
	}
110
 
111
	/**
112
	 * @return string corresponding javascript class name for TEventTriggeredCallback.
113
	 */
114
	protected function getClientClassName()
115
	{
116
		return 'Prado.WebUI.TValueTriggeredCallback';
117
	}
118
}