3 * TValueTriggeredCallback 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
12 Prado::using('System.Web.UI.ActiveControls.TTriggeredCallback');
15 * TValueTriggeredCallback Class
17 * Observes the value with {@link setPropertyName PropertyName} of a
18 * control with {@link setControlID ControlID}. Changes to the observed
19 * property value will trigger a new callback request. The property value is checked
20 * for changes every{@link setInterval Interval} seconds.
22 * A {@link setDecayRate DecayRate} can be set to increase the polling
23 * interval linearly if no changes are observed. Once a change is
24 * observed, the polling interval is reset to the original value.
26 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
27 * @package System.Web.UI.ActiveControls
30 class TValueTriggeredCallback extends TTriggeredCallback
33 * @return string The control property name to observe value changes.
35 public function getPropertyName()
37 return $this->getViewState('PropertyName', '');
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.
44 public function setPropertyName($value)
46 $this->setViewState('PropertyName', $value, '');
50 * Sets the polling interval in seconds to observe property changes.
51 * Default is 1 second.
52 * @param float polling interval in seconds.
54 public function setInterval($value)
56 $this->setViewState('Interval', TPropertyValue::ensureFloat($value), 1);
60 * @return float polling interval, 1 second default.
62 public function getInterval()
64 return $this->getViewState('Interval', 1);
68 * Gets the decay rate between callbacks. Default is 0;
69 * @return float decay rate between callbacks.
71 public function getDecayRate()
73 return $this->getViewState('Decay', 0);
77 * Sets the decay rate between callback. Default is 0;
78 * @param float decay rate between callbacks.
80 public function setDecayRate($value)
82 $decay = TPropertyValue::ensureFloat($value);
84 throw new TConfigurationException('callback_decay_be_not_negative', $this->getID());
85 $this->setViewState('Decay', $decay);
89 * @return array list of timer options for client-side.
91 protected function getTriggerOptions()
93 $options = parent::getTriggerOptions();
94 $options['PropertyName'] = $this->getPropertyName();
95 $options['Interval'] = $this->getInterval();
96 $options['Decay'] = $this->getDecayRate();
101 * Registers the javascript code for initializing the active control.
102 * @param THtmlWriter the renderer.
104 public function render($writer)
106 parent::render($writer);
107 $this->getActiveControl()->registerCallbackClientScript(
108 $this->getClientClassName(), $this->getTriggerOptions());
112 * @return string corresponding javascript class name for TEventTriggeredCallback.
114 protected function getClientClassName()
116 return 'Prado.WebUI.TValueTriggeredCallback';