summaryrefslogtreecommitdiff
path: root/framework/Web/UI/ActiveControls
diff options
context:
space:
mode:
authorwei <>2006-08-12 12:54:27 +0000
committerwei <>2006-08-12 12:54:27 +0000
commit1180e6486139a9c9662984367c4f624394e06f35 (patch)
treef89a379960284595d5a425e22424582eea57422c /framework/Web/UI/ActiveControls
parent54d4919e3f1b00b644fa3c107acdf20159a1b154 (diff)
Add Triggered Callbacks
Diffstat (limited to 'framework/Web/UI/ActiveControls')
-rw-r--r--framework/Web/UI/ActiveControls/TBaseActiveControl.php4
-rw-r--r--framework/Web/UI/ActiveControls/TEventTriggeredCallback.php70
-rw-r--r--framework/Web/UI/ActiveControls/TPeriodicCallback.php (renamed from framework/Web/UI/ActiveControls/TCallbackTimer.php)40
-rw-r--r--framework/Web/UI/ActiveControls/TTriggeredCallback.php49
-rw-r--r--framework/Web/UI/ActiveControls/TValueTriggeredCallback.php92
5 files changed, 234 insertions, 21 deletions
diff --git a/framework/Web/UI/ActiveControls/TBaseActiveControl.php b/framework/Web/UI/ActiveControls/TBaseActiveControl.php
index cb944253..c368cb68 100644
--- a/framework/Web/UI/ActiveControls/TBaseActiveControl.php
+++ b/framework/Web/UI/ActiveControls/TBaseActiveControl.php
@@ -328,8 +328,10 @@ class TBaseActiveCallbackControl extends TBaseActiveControl
$options = array_merge($this->getClientSideOptions(),$options);
else
$options = $this->getClientSideOptions();
+
//remove true as default to save bytes
- $options['CausesValidation']= $options['CausesValidation'] ? '' : false;
+ if($options['CausesValidation']===true)
+ $options['CausesValidation']='';
$cs->registerCallbackControl($class, $options);
}
diff --git a/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php b/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php
new file mode 100644
index 00000000..42f49976
--- /dev/null
+++ b/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php
@@ -0,0 +1,70 @@
+<?php
+
+class TEventTriggeredCallback extends TTriggeredCallback
+{
+ /**
+ * @return string The client-side event name the trigger listens to.
+ */
+ public function getEventName()
+ {
+ return $this->getViewState('EventName', '');
+ }
+
+ /**
+ * Sets the client-side event name that fires the callback request.
+ * @param string The client-side event name the trigger listens to.
+ */
+ public function setEventName($value)
+ {
+ $this->setViewState('EventName', $value, '');
+ }
+
+ /**
+ * @param boolean true to prevent/stop default event action.
+ */
+ public function setPreventDefaultAction($value)
+ {
+ $this->setViewState('StopEvent', TPropertyValue::ensureBoolean($value), false);
+ }
+
+ /**
+ * @return boolean true to prevent/stop default event action.
+ */
+ public function getPreventDefaultAction()
+ {
+ return $this->getViewState('StopEvent', false);
+ }
+
+ /**
+ * @return array list of timer options for client-side.
+ */
+ protected function getTriggerOptions()
+ {
+ $options = parent::getTriggerOptions();
+ $name = preg_replace('/^on/', '', $this->getEventName());
+ $options['EventName'] = strtolower($name);
+ $options['StopEvent'] = $this->getPreventDefaultAction();
+ return $options;
+ }
+
+ /**
+ * Registers the javascript code for initializing the active control.
+ * @param THtmlWriter the renderer.
+ */
+ public function render($writer)
+ {
+ parent::render($writer);
+ $this->getActiveControl()->registerCallbackClientScript(
+ $this->getClientClassName(), $this->getTriggerOptions());
+ }
+
+ /**
+ * @return string corresponding javascript class name for TEventTriggeredCallback.
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TEventTriggeredCallback';
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Web/UI/ActiveControls/TCallbackTimer.php b/framework/Web/UI/ActiveControls/TPeriodicCallback.php
index bae41e1f..e620ac46 100644
--- a/framework/Web/UI/ActiveControls/TCallbackTimer.php
+++ b/framework/Web/UI/ActiveControls/TPeriodicCallback.php
@@ -1,6 +1,6 @@
<?php
/**
- * TCallbackTimer class file.
+ * TPeriodicCallback class file.
*
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
* @link http://www.pradosoft.com/
@@ -16,13 +16,13 @@
Prado::using('System.Web.UI.ActiveControls.TCallback');
/**
- * TCallbackTimer class.
- *
- * TCallbackTimer sends callback request every {@link setInterval Interval} seconds.
+ * TPeriodicCallback class.
+ *
+ * TPeriodicCallback sends callback request every {@link setInterval Interval} seconds.
* Upon each callback request, the {@link onCallback OnCallback} event is raised.
- *
+ *
* The intervals between each request can be increased when the browser is inactive
- * by changing the {@link setDecayRate DecayRate} to a positive number. The
+ * by changing the {@link setDecayRate DecayRate} to a positive number. The
* default decay rate, {@link setDecayType DecayType}, is linear and can be changed to
* 'Exponential', 'Linear', 'Quadratic' or 'Cubic'.
*
@@ -31,7 +31,7 @@ Prado::using('System.Web.UI.ActiveControls.TCallback');
* @package System.Web.UI.ActiveControls
* @since 3.0
*/
-class TCallbackTimer extends TCallback
+class TPeriodicCallback extends TCallback
{
/**
* @return float seconds between callback requests. Default is 1 second.
@@ -40,7 +40,7 @@ class TCallbackTimer extends TCallback
{
return $this->getViewState('Interval', 1);
}
-
+
/**
* @param float seconds between callback requests, must be a positive number, default is 1 second.
*/
@@ -51,7 +51,7 @@ class TCallbackTimer extends TCallback
throw new TConfigurationException('callback_interval_be_positive', $this->getID());
$this->setViewState('Interval', $interval, 1);
}
-
+
/**
* Gets the decay rate between callbacks. Default is 0;
* @return float decay rate between callbacks.
@@ -60,7 +60,7 @@ class TCallbackTimer extends TCallback
{
return $this->getViewState('Decay', 0);
}
-
+
/**
* Sets the decay rate between callback. Default is 0;
* @param float decay rate between callbacks.
@@ -72,13 +72,13 @@ class TCallbackTimer extends TCallback
throw new TConfigurationException('callback_decay_be_not_negative', $this->getID());
$this->setViewState('Decay', $decay);
}
-
+
/**
* @param string Decay type, allows 'Exponential', 'Linear', 'Quadratic' and 'Cubic'. Default is 'Linear'.
*/
public function setDecayType($value)
{
- $this->setViewState('DecayType', TPropertyValue::ensureEnum($value,
+ $this->setViewState('DecayType', TPropertyValue::ensureEnum($value,
'Exponential', 'Linear', 'Quadratic', 'Cubic'), 'Linear');
}
@@ -89,27 +89,27 @@ class TCallbackTimer extends TCallback
{
return $this->getViewState('DecayType', 'Linear');
}
-
+
/**
* Registers the javascript code to start the timer.
*/
public function startTimer()
{
$id = $this->getClientID();
- $code = "Prado.WebUI.TCallbackTimer.start('{$id}');";
+ $code = "Prado.WebUI.TPeriodicCallback.start('{$id}');";
$cs = $this->getPage()->getClientScript();
$cs->registerEndScript("{$id}:start", $code);
}
-
+
/**
* Registers the javascript code to stop the timer.
*/
public function stopTimer()
{
$id = $this->getClientID();
- $code = "Prado.WebUI.TCallbackTimer.stop('{$id}');";
+ $code = "Prado.WebUI.TPeriodicCallback.stop('{$id}');";
$cs = $this->getPage()->getClientScript();
- $cs->registerEndScript("{$id}:stop", $code);
+ $cs->registerEndScript("{$id}:stop", $code);
}
/**
@@ -132,15 +132,15 @@ class TCallbackTimer extends TCallback
{
parent::render($writer);
$this->getActiveControl()->registerCallbackClientScript(
- $this->getClientClassName(), $this->getTimerOptions());
+ $this->getClientClassName(), $this->getTimerOptions());
}
/**
- * @return string corresponding javascript class name for this TActiveButton.
+ * @return string corresponding javascript class name for TPeriodicCallback.
*/
protected function getClientClassName()
{
- return 'Prado.WebUI.TCallbackTimer';
+ return 'Prado.WebUI.TPeriodicCallback';
}
}
diff --git a/framework/Web/UI/ActiveControls/TTriggeredCallback.php b/framework/Web/UI/ActiveControls/TTriggeredCallback.php
new file mode 100644
index 00000000..076166c9
--- /dev/null
+++ b/framework/Web/UI/ActiveControls/TTriggeredCallback.php
@@ -0,0 +1,49 @@
+<?php
+
+abstract class TTriggeredCallback extends TCallback
+{
+ /**
+ * @return string The ID of the server control the trigger is bounded to.
+ */
+ public function getControlID()
+ {
+ return $this->getViewState('ControlID', '');
+ }
+
+ /**
+ * @param string The ID of the server control the trigger is bounded to.
+ */
+ public function setControlID($value)
+ {
+ $this->setViewState('ControlID', $value, '');
+ }
+
+ /**
+ * @return string target control client ID or html element ID if
+ * control is not found in hierarchy.
+ */
+ protected function getTargetControl()
+ {
+ $id = $this->getControlID();
+ if(($control=$this->findControl($id)) instanceof TControl)
+ return $control->getClientID();
+ if($id==='')
+ {
+ throw new TConfigurationException(
+ 'ttriggeredcallback_invalid_controlid', get_class($this));
+ }
+ return $id;
+ }
+
+ /**
+ * @return array list of trigger callback options.
+ */
+ protected function getTriggerOptions()
+ {
+ $options['ID'] = $this->getClientID();
+ $options['ControlID'] = $this->getTargetControl();
+ return $options;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php b/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php
new file mode 100644
index 00000000..bb50e4f1
--- /dev/null
+++ b/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php
@@ -0,0 +1,92 @@
+<?php
+
+class TValueTriggeredCallback extends TTriggeredCallback
+{
+ /**
+ * @return string The control property name to observe value changes.
+ */
+ public function getPropertyName()
+ {
+ return $this->getViewState('PropertyName', '');
+ }
+
+ /**
+ * Sets the control property name to observe value changes that fires the callback request.
+ * @param string The control property name to observe value changes.
+ */
+ public function setPropertyName($value)
+ {
+ $this->setViewState('PropertyName', $value, '');
+ }
+
+ /**
+ * Sets the polling interval in seconds to observe property changes.
+ * Default is 1 second.
+ * @param float polling interval in seconds.
+ */
+ public function setPollingInterval($value)
+ {
+ $this->setViewState('Interval', TPropertyValue::ensureFloat($value), 1);
+ }
+
+ /**
+ * Gets the decay rate between callbacks. Default is 0;
+ * @return float decay rate between callbacks.
+ */
+ public function getDecayRate()
+ {
+ return $this->getViewState('Decay', 0);
+ }
+
+ /**
+ * Sets the decay rate between callback. Default is 0;
+ * @param float decay rate between callbacks.
+ */
+ public function setDecayRate($value)
+ {
+ $decay = TPropertyValue::ensureFloat($value);
+ if($decay < 0)
+ throw new TConfigurationException('callback_decay_be_not_negative', $this->getID());
+ $this->setViewState('Decay', $decay);
+ }
+
+ /**
+ * @return float polling interval, 1 second default.
+ */
+ public function getPollingInterval()
+ {
+ return $this->getViewState('Interval', 1);
+ }
+
+ /**
+ * @return array list of timer options for client-side.
+ */
+ protected function getTriggerOptions()
+ {
+ $options = parent::getTriggerOptions();
+ $options['PropertyName'] = $this->getPropertyName();
+ $options['Interval'] = $this->getPollingInterval();
+ $options['Decay'] = $this->getDecayRate();
+ return $options;
+ }
+
+ /**
+ * Registers the javascript code for initializing the active control.
+ * @param THtmlWriter the renderer.
+ */
+ public function render($writer)
+ {
+ parent::render($writer);
+ $this->getActiveControl()->registerCallbackClientScript(
+ $this->getClientClassName(), $this->getTriggerOptions());
+ }
+
+ /**
+ * @return string corresponding javascript class name for TEventTriggeredCallback.
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TValueTriggeredCallback';
+ }
+}
+?> \ No newline at end of file