summaryrefslogtreecommitdiff
path: root/framework/Web/UI/ActiveControls
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/UI/ActiveControls')
-rw-r--r--framework/Web/UI/ActiveControls/TActiveLinkButton.php2
-rw-r--r--framework/Web/UI/ActiveControls/TActivePageAdapter.php21
-rw-r--r--framework/Web/UI/ActiveControls/TAutoComplete.php32
-rwxr-xr-xframework/Web/UI/ActiveControls/TCallbackResponseAdapter.php21
-rw-r--r--framework/Web/UI/ActiveControls/TTimeTriggeredCallback.php47
-rw-r--r--framework/Web/UI/ActiveControls/TValueTriggeredCallback.php26
6 files changed, 76 insertions, 73 deletions
diff --git a/framework/Web/UI/ActiveControls/TActiveLinkButton.php b/framework/Web/UI/ActiveControls/TActiveLinkButton.php
index 019c002c..9b30fffc 100644
--- a/framework/Web/UI/ActiveControls/TActiveLinkButton.php
+++ b/framework/Web/UI/ActiveControls/TActiveLinkButton.php
@@ -93,7 +93,7 @@ class TActiveLinkButton extends TLinkButton implements IActiveControl, ICallback
{
parent::setText($value);
if($this->getActiveControl()->canUpdateClientSide())
- $this->getPage()->getCallbackClient()->replaceContent($this, $value);
+ $this->getPage()->getCallbackClient()->update($this, $value);
}
/**
diff --git a/framework/Web/UI/ActiveControls/TActivePageAdapter.php b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
index 2df19053..514b6880 100644
--- a/framework/Web/UI/ActiveControls/TActivePageAdapter.php
+++ b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
@@ -46,6 +46,11 @@ class TActivePageAdapter extends TControlAdapter
const CALLBACK_PAGESTATE_HEADER = 'X-PRADO-PAGESTATE';
/**
+ * Callback redirect url header name.
+ */
+ const CALLBACK_REDIRECT = 'X-PRADO-REDIRECT';
+
+ /**
* @var ICallbackEventHandler callback event handler.
*/
private $_callbackEventTarget;
@@ -112,7 +117,21 @@ class TActivePageAdapter extends TControlAdapter
public function renderCallbackResponse($writer)
{
Prado::trace("ActivePage renderCallbackResponse()",'System.Web.UI.ActiveControls.TActivePageAdapter');
- $this->renderResponse($writer);
+ if(($url = $this->getResponse()->getAdapter()->getRedirectedUrl())===null)
+ $this->renderResponse($writer);
+ else
+ $this->redirect($url);
+ }
+
+ /**
+ * Redirect url on the client-side using javascript.
+ * @param string new url to load.
+ */
+ protected function redirect($url)
+ {
+ if(!$this->getApplication()->getRequestCompleted())
+ $this->getApplication()->onEndRequest();
+ $this->getResponse()->appendHeader(self::CALLBACK_REDIRECT.': '.$url);
}
/**
diff --git a/framework/Web/UI/ActiveControls/TAutoComplete.php b/framework/Web/UI/ActiveControls/TAutoComplete.php
index a886e732..07fa652b 100644
--- a/framework/Web/UI/ActiveControls/TAutoComplete.php
+++ b/framework/Web/UI/ActiveControls/TAutoComplete.php
@@ -36,18 +36,20 @@ Prado::using('System.Web.UI.ActiveControls.TActiveTextBox');
* other properties of the repeater can be access via the {@link getSuggestions Suggestions}
* property (e.g. they can be set in the .page templates).
*
- * To return the list of suggestions back to the browser, in your {@link onSuggestion OnSuggestion}
- * event handler, do
+ * To return the list of suggestions back to the browser, supply a non-empty data source
+ * and call databind. For example,
* <code>
* function autocomplete_suggestion($sender, $param)
* {
* $token = $param->getCallbackParameter(); //the partial word to match
* $sender->setDataSource($this->getSuggestionsFor($token)); //set suggestions
* $sender->dataBind();
- * $sender->render($param->getNewWriter()); //sends suggestion back to browser.
* }
* </code>
*
+ * The suggestion will be rendered when the {@link dataBind()} method is called
+ * <strong>during a callback request</strong>.
+ *
* TAutoComplete allows multiple suggestions within one textbox with each
* word or phrase separated by any characters specified in the
* {@link setSeparator Separator} property. The {@link setFrequency Frequency}
@@ -169,6 +171,17 @@ class TAutoComplete extends TActiveTextBox implements INamingContainer
}
/**
+ * Overrides parent implementation. Callback {@link renderSuggestions()} when
+ * page's IsCallback property is true.
+ */
+ public function dataBind()
+ {
+ parent::dataBind();
+ if($this->getPage()->getIsCallback())
+ $this->renderSuggestions($this->getResponse()->createHtmlWriter());
+ }
+
+ /**
* @return TPanel suggestion results panel.
*/
public function getResultPanel()
@@ -232,24 +245,21 @@ class TAutoComplete extends TActiveTextBox implements INamingContainer
}
/**
- * Flush and returns the suggestions content back to the browser client.
+ * Renders the suggestions during a callback respones.
* @param THtmlWriter the renderer.
*/
- public function render($writer)
+ public function renderCallback($writer)
{
- if(!$this->getPage()->getIsCallback())
- parent::render($writer);
- if($this->getActiveControl()->canUpdateClientSide())
- $this->renderSuggestions($writer);
+ $this->renderSuggestions($writer);
}
/**
* Renders the suggestions repeater.
* @param THtmlWriter the renderer.
*/
- protected function renderSuggestions($writer)
+ public function renderSuggestions($writer)
{
- if($this->getSuggestions()->getItems()->getCount() > 0)
+ if($this->getActiveControl()->canUpdateClientSide())
{
$this->getSuggestions()->render($writer);
$boundary = $writer->getWriter()->getBoundary();
diff --git a/framework/Web/UI/ActiveControls/TCallbackResponseAdapter.php b/framework/Web/UI/ActiveControls/TCallbackResponseAdapter.php
index 922e6cc6..6e3fb01e 100755
--- a/framework/Web/UI/ActiveControls/TCallbackResponseAdapter.php
+++ b/framework/Web/UI/ActiveControls/TCallbackResponseAdapter.php
@@ -37,6 +37,8 @@ class TCallbackResponseAdapter extends THttpResponseAdapter
*/
private $_data;
+ private $_redirectUrl=null;
+
/**
* Returns a new instance of THtmlWriter.
* An instance of TCallbackResponseWriter is created to hold the content.
@@ -75,6 +77,25 @@ class TCallbackResponseAdapter extends THttpResponseAdapter
{
return $this->_data;
}
+
+ /**
+ * Delay the redirect until we process the rest of the page.
+ * @param string new url to redirect to.
+ */
+ public function httpRedirect($url)
+ {
+ if($url[0]==='/')
+ $url=$this->getRequest()->getBaseUrl().$url;
+ $this->_redirectUrl=str_replace('&amp;','&',$url);
+ }
+
+ /**
+ * @return string new url for callback response to redirect to.
+ */
+ public function getRedirectedUrl()
+ {
+ return $this->_redirectUrl;
+ }
}
/**
diff --git a/framework/Web/UI/ActiveControls/TTimeTriggeredCallback.php b/framework/Web/UI/ActiveControls/TTimeTriggeredCallback.php
index 10923d03..45e33f81 100644
--- a/framework/Web/UI/ActiveControls/TTimeTriggeredCallback.php
+++ b/framework/Web/UI/ActiveControls/TTimeTriggeredCallback.php
@@ -25,11 +25,6 @@ Prado::using('System.Web.UI.ActiveControls.TCallback');
* {@link stopTimer()}. The timer can be automatically started when
* {@link setStartTimerOnLoad StartTimerOnLoad} is true.
*
- * The intervals between each request can be increased when the browser is inactive
- * 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'.
- *
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version $Id$
* @package System.Web.UI.ActiveControls
@@ -57,44 +52,6 @@ class TTimeTriggeredCallback extends TCallback
}
/**
- * 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);
- }
-
- /**
- * @param string Decay type, allows 'Exponential', 'Linear', 'Quadratic' and 'Cubic'. Default is 'Linear'.
- */
- public function setDecayType($value)
- {
- $this->setViewState('DecayType', TPropertyValue::ensureEnum($value,
- 'Exponential', 'Linear', 'Quadratic', 'Cubic'), 'Linear');
- }
-
- /**
- * @return string decay type, default is 'Linear', valid types are 'Exponential', 'Linear', 'Quadratic' and 'Cubic'.
- */
- public function getDecayType()
- {
- return $this->getViewState('DecayType', 'Linear');
- }
-
- /**
* Registers the javascript code to start the timer.
*/
public function startTimer()
@@ -121,7 +78,7 @@ class TTimeTriggeredCallback extends TCallback
*/
public function setStartTimerOnLoad($value)
{
- $this->setViewState('StartTimerOnLoad',
+ $this->setViewState('StartTimerOnLoad',
TPropertyValue::ensureBoolean($value), false);
}
@@ -141,8 +98,6 @@ class TTimeTriggeredCallback extends TCallback
$options['ID'] = $this->getClientID();
$options['EventTarget']= $this->getUniqueID();
$options['Interval'] = $this->getInterval();
- $options['DecayRate'] = $this->getDecayRate();
- $options['DecayType'] = $this->getDecayType();
return $options;
}
diff --git a/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php b/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php
index 3ec830b8..e0320c6b 100644
--- a/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php
+++ b/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php
@@ -15,10 +15,8 @@
*
* Observes the value with {@link setPropertyName PropertyName} of a
* control with {@link setControlID ControlID}. Changes to the observed
- * property value will trigger a new callback request. The values are
- * observed using a {@link setPollingInterval PollingInterval} (in seconds).
- * That is, the property is checked for changes every
- * {@link setPollingInterval PollingInterval} seconds.
+ * property value will trigger a new callback request. The property value is checked
+ * for changes every{@link setInterval Interval} seconds.
*
* A {@link setDecayRate DecayRate} can be set to increase the polling
* interval linearly if no changes are observed. Once a change is
@@ -53,12 +51,20 @@ class TValueTriggeredCallback extends TTriggeredCallback
* Default is 1 second.
* @param float polling interval in seconds.
*/
- public function setPollingInterval($value)
+ public function setInterval($value)
{
$this->setViewState('Interval', TPropertyValue::ensureFloat($value), 1);
}
/**
+ * @return float polling interval, 1 second default.
+ */
+ public function getInterval()
+ {
+ return $this->getViewState('Interval', 1);
+ }
+
+ /**
* Gets the decay rate between callbacks. Default is 0;
* @return float decay rate between callbacks.
*/
@@ -80,21 +86,13 @@ class TValueTriggeredCallback extends TTriggeredCallback
}
/**
- * @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['Interval'] = $this->getInterval();
$options['Decay'] = $this->getDecayRate();
return $options;
}