summaryrefslogtreecommitdiff
path: root/framework/Web/UI
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/UI')
-rw-r--r--framework/Web/UI/ActiveControls/TActiveControl.php23
-rw-r--r--framework/Web/UI/ActiveControls/TActiveControlAdapter.php25
-rw-r--r--framework/Web/UI/ActiveControls/TActivePageAdapter.php219
-rw-r--r--framework/Web/UI/ActiveControls/TCallbackClientScript.php485
-rw-r--r--framework/Web/UI/ActiveControls/TCallbackResponse.php20
-rw-r--r--framework/Web/UI/TControl.php5
-rw-r--r--framework/Web/UI/TPage.php163
-rw-r--r--framework/Web/UI/TTemplateControl.php2
-rw-r--r--framework/Web/UI/WebControls/TWizard.php4
9 files changed, 936 insertions, 10 deletions
diff --git a/framework/Web/UI/ActiveControls/TActiveControl.php b/framework/Web/UI/ActiveControls/TActiveControl.php
new file mode 100644
index 00000000..d289bab9
--- /dev/null
+++ b/framework/Web/UI/ActiveControls/TActiveControl.php
@@ -0,0 +1,23 @@
+<?php
+
+/*
+ * Created on 25/04/2006
+ */
+
+class TActiveControl extends TControl implements ICallbackEventHandler, IActiveControl
+{
+ public function __construct()
+ {
+ parent::__construct();
+ $this->setAdapter(new TActiveControlAdapter($this));
+ }
+
+ public function raiseCallbackEvent($param)
+ {
+ var_dump($param);
+ $client = $this->getPage()->getCallbackClient();
+ $client->hide($this);
+ }
+}
+
+?>
diff --git a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php
new file mode 100644
index 00000000..187b2cac
--- /dev/null
+++ b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php
@@ -0,0 +1,25 @@
+<?php
+/*
+ * Created on 29/04/2006
+ */
+
+class TActiveControlAdapter extends TControlAdapter
+{
+ private static $_renderedPosts = false;
+
+ /**
+ * Render the callback request post data loaders once only.
+ */
+ public function render($writer)
+ {
+ if(!self::$_renderedPosts)
+ {
+ $options = TJavascript::encode($this->getPage()->getPostDataLoaders(),false);
+ $script = "Prado.Callback.PostDataLoaders.concat({$options});";
+ $this->getPage()->getClientScript()->registerEndScript(get_class($this), $script);
+ self::$_renderedPosts = true;
+ }
+ parent::render($writer);
+ }
+}
+?>
diff --git a/framework/Web/UI/ActiveControls/TActivePageAdapter.php b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
new file mode 100644
index 00000000..ab042d54
--- /dev/null
+++ b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
@@ -0,0 +1,219 @@
+<?php
+/**
+ * TActivePageAdapter class file
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * TActivePageAdapter class.
+ *
+ * Callback request page handler.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.ActiveControls
+ * @since 3.0
+ */
+class TActivePageAdapter extends TControlAdapter
+{
+ /**
+ * @var ICallbackEventHandler callback event handler.
+ */
+ private $_callbackEventTarget;
+ /**
+ * @var mixed callback event parameter.
+ */
+ private $_callbackEventParameter;
+ /**
+ * @var TCallbackClientScript callback client script handler
+ */
+ private $_callbackClient;
+ /**
+ * @var TCallbackResponse callback response handler.
+ */
+ private $_callbackResponse;
+
+ private $_callbackEventResult;
+
+ /**
+ * Constructor, trap errors and exception to let the callback response
+ * handle them.
+ */
+ public function __construct(TPage $control)
+ {
+ parent::__construct($control);
+ $this->trapCallbackErrorsExceptions();
+ }
+
+ /**
+ * Process the callback request.
+ */
+ public function processCallbackEvent($writer)
+ {
+ Prado::trace("ActivePage raiseCallbackEvent()",'System.Web.UI.ActiveControls.TActivePageAdapter');
+ $this->raiseCallbackEvent();
+ }
+
+ protected function trapCallbackErrorsExceptions()
+ {
+ //TODO: How to trap the errors and exceptions and return them
+ // as part of the response.
+ }
+
+ public function renderCallbackResponse($writer)
+ {
+ Prado::trace("ActivePage renderCallbackResponse()",'System.Web.UI.ActiveControls.TActivePageAdapter');
+ $this->renderResponse($writer);
+ }
+
+ protected function renderResponse($writer)
+ {
+ //var_dump(getallheaders());
+ //TODO: How to render the response, it will contain 3 pieces of data
+ // 1) The arbituary data returned to the client-side callback handler
+ // 2) client-side function call statements
+ // 3) Content body, which may need to be partitioned
+
+ /*
+ $response = $this->getCallbackResponseHandler();
+ $response->writeClientScriptResponse($this->getCallbackClientHandler());
+ $response->writeResponseData($this->getCallbackEventResult());
+ $response->flush();
+ */
+ }
+
+ /**
+ * Trys to find the callback event handler and raise its callback event.
+ * @throws TInvalidCallbackRequestException if call back target is not
+ * found.
+ * @throws TInvalidCallbackHandlerException if the requested target does not
+ * implement ICallbackEventHandler.
+ */
+ private function raiseCallbackEvent()
+ {
+ if(($callbackHandler=$this->getCallbackEventTarget())!==null)
+ {
+ if($callbackHandler instanceof ICallbackEventHandler)
+ $callbackHandler->raiseCallbackEvent($this->getCallbackEventParameter());
+ else
+ throw new TInvalidCallbackHandlerException($callbackHandler->getUniqueID());
+ }
+ else
+ {
+ $target = $this->getRequest()->itemAt(TPage::FIELD_CALLBACK_TARGET);
+ throw new TInvalidCallbackRequestException($target);
+ }
+ }
+
+ /**
+ * @return mixed callback event result.
+ */
+ public function getCallbackEventResult()
+ {
+ return $this->_callbackEventResult->getResult();
+ }
+
+ /**
+ * @return TControl the control responsible for the current callback event,
+ * null if nonexistent
+ */
+ public function getCallbackEventTarget()
+ {
+ if($this->_callbackEventTarget===null)
+ {
+ $eventTarget=$this->getRequest()->itemAt(TPage::FIELD_CALLBACK_TARGET);
+ if(!empty($eventTarget))
+ $this->_callbackEventTarget=$this->getPage()->findControl($eventTarget);
+ }
+ return $this->_callbackEventTarget;
+ }
+
+ /**
+ * Registers a control to raise callback event in the current request.
+ * @param TControl control registered to raise callback event.
+ */
+ public function setCallbackEventTarget(TControl $control)
+ {
+ $this->_callbackEventTarget=$control;
+ }
+
+ /**
+ * Callback parameter is decoded assuming JSON encoding.
+ * @return string postback event parameter
+ */
+ public function getCallbackEventParameter()
+ {
+ if($this->_callbackEventParameter===null)
+ {
+ $param = $this->getRequest()->itemAt(TPage::FIELD_CALLBACK_PARAMETER);
+ if(strlen($param) > 0)
+ $this->_callbackEventParameter=TJavascript::jsonDecode((string)$param);
+ var_dump($param);
+ }
+ return $this->_callbackEventParameter;
+ }
+
+ /**
+ * @param mixed postback event parameter
+ */
+ public function setCallbackEventParameter($value)
+ {
+ $this->_callbackEventParameter=$value;
+ }
+
+ /**
+ * Gets the callback client script handler that allows javascript functions
+ * to be executed during the callback response.
+ * @return TCallbackClientScript callback client handler.
+ */
+ public function getCallbackClientHandler()
+ {
+ if(is_null($this->_callbackClient))
+ $this->_callbackClient = new TCallbackClientScript;
+ return $this->_callbackClient;
+ }
+
+ /**
+ * @param TCallbackClientScript new callback client handler.
+ */
+ public function setCallbackClientHandler($handler)
+ {
+ $this->_callbackClient = $handler;
+ }
+
+ /**
+ * Gets the callback response handler.
+ * @return TCallbackResponse callback response
+ */
+ public function getCallbackResponseHandler()
+ {
+ if(is_null($this->_callbackResponse))
+ $this->_callbackResponse = new TCallbackResponse;
+ return $this->_callbackResponse;
+ }
+
+ /**
+ * @param TCallbackResponse new callback response handler.
+ */
+ public function setCallbackResponseHandler($handler)
+ {
+ $this->_callbackResponse = $handler;
+ }
+}
+
+class TInvalidCallbackHandlerException extends TException
+{
+
+}
+
+class TInvalidCallbackRequestException extends TException
+{
+}
+
+?>
diff --git a/framework/Web/UI/ActiveControls/TCallbackClientScript.php b/framework/Web/UI/ActiveControls/TCallbackClientScript.php
new file mode 100644
index 00000000..550c88b5
--- /dev/null
+++ b/framework/Web/UI/ActiveControls/TCallbackClientScript.php
@@ -0,0 +1,485 @@
+<?php
+/**
+ * TCallbackClientScript class file
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.ActiveControls
+ */
+
+/**
+ * TCallbackClientScript class.
+ *
+ * The TCallbackClientScript class provides corresponding methods that can be
+ * executed on the client-side (i.e. the browser client that is viewing
+ * the page) during a callback response.
+ *
+ * The avaiable methods includes setting/clicking input elements, changing Css
+ * styles, hiding/showing elements, and adding visual effects to elements on the
+ * page. The client-side methods can be access through the CallbackClient
+ * property available in TPage.
+ *
+ * For example, to hide "$myTextBox" element during callback response, do
+ * <code>
+ * $this->getPage()->getCallbackClient()->hide($myTextBox);
+ * </code>
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.ActiveControls
+ * @since 3.0
+ */
+class TCallbackClientScript
+{
+ /**
+ * @var TList list of client functions to execute.
+ */
+ private $_actions;
+
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ $this->_actions = new TList;
+ }
+
+ /**
+ * @return array list of client function to be executed during callback
+ * response.
+ */
+ public function getClientFunctionsToExecute()
+ {
+ return $this->_actions;
+ }
+
+ /**
+ * Executes a client-side statement.
+ * @param string javascript function name
+ * @param array list of arguments for the function
+ */
+ public function callClientFunction($function, $params=null)
+ {
+ if(!is_array($params) && $params !== null)
+ $params = array($params);
+ else
+ $params = array();
+
+ if(count($params) > 0)
+ {
+ if($params[0] instanceof TControl)
+ $params[0] = $params[0]->getID();
+ }
+ $this->_actions->add(array($function => $params));
+ }
+
+ /**
+ * Client script to set the value of a particular input element.
+ * @param TControl|string control element to set the new value
+ * @param string new value
+ */
+ public function setValue($input, $text)
+ {
+ $this->callClientFunction('Prado.Element.setValue', array($input, $text));
+ }
+
+ /**
+ * Client script to select/clear/check a drop down list, check box list,
+ * or radio button list.
+ * The second parameter determines the selection method. Valid methods are
+ * - <b>Value</b>, select or check by value
+ * - <b>Index</b>, select or check by list index (zero based index)
+ * - <b>All</b>, selects or checks all in the list
+ * - <b>Clear</b>, clears or selections or checks in the list
+ * - <b>Invert</b>, inverts the current selection or checks.
+ * @param TControl|string list control
+ * @param string selection method
+ * @param string|int the value or index to select/check.
+ */
+ public function select($listControl, $method="Value", $valueOrIndex=null)
+ {
+ $this->callClientFunction('Prado.Element.select', array($listControl, $method, $valueOrIndex));
+ }
+
+ /**
+ * Client script to click on an element. <b>This client-side function
+ * is unpredictable.</b>
+ * @param TControl|string control element or element id
+ */
+ public function click($control)
+ {
+ $this->callClientFunction('Prado.Element.click', $control);
+ }
+
+ /**
+ * Client script to check or uncheck a checkbox or radio button.
+ * @param TControl|string control element or element id
+ * @param boolean check or uncheck the checkbox or radio button.
+ */
+ public function check($checkbox, $checked=true)
+ {
+ $this->select($checkbox, "Value", $checked);
+ }
+
+ /**
+ * Sets the attribute of a particular control.
+ * @param TControl|string control element or element id
+ * @param string attribute name
+ * @param string attribute value
+ */
+ public function setAttribute($control, $name, $value)
+ {
+ $this->callClientFunction('Prado.Element.setAttribute',array($control, $name, $value));
+ }
+
+ /**
+ * Sets the options of a select input element.
+ * @param TControl|string control element or element id
+ * @param TCollection a list of new options
+ */
+ public function setOptions($control, $items)
+ {
+ $options = array();
+ foreach($items as $item)
+ $options[] = array($item->getText(),$item->getValue());
+ $this->callClientFunction('Prado.Element.setOptions', array($control, $options));
+ }
+
+ /**
+ * Shows an element by changing its CSS display style as empty.
+ * @param TControl|string control element or element id
+ */
+ public function show($element)
+ {
+ $this->callClientFunction('Element.show', $element);
+ }
+
+ /**
+ * Hides an element by changing its CSS display style to "none".
+ * @param TControl|string control element or element id
+ */
+ public function hide($element)
+ {
+ $this->callClientFunction('Element.hide', $element);
+ }
+
+ /**
+ * Toggles the visibility of the element.
+ * @param TControl|string control element or element id
+ */
+ public function toggle($element)
+ {
+ $this->callClientFunction('Element.toggle', $element);
+ }
+
+ /**
+ * Removes an element from the HTML page.
+ * @param TControl|string control element or element id
+ */
+ public function remove($element)
+ {
+ $this->callClientFunction('Element.remove', $element);
+ }
+
+ /**
+ * Update the element's innerHTML with new content.
+ * @param TControl|string control element or element id
+ * @param TControl|string new HTML content, if content is of a TControl, the
+ * controls render method is called.
+ */
+ public function update($element, $innerHTML)
+ {
+ if($innerHTML instanceof TControl)
+ $innerHTML = $innerHTML->render();
+ $this->callClientFunction('Element.update', array($element, $innerHTML));
+ }
+
+ /**
+ * Replace the innerHTML of a content with fragements of the response body.
+ * @param TControl|string control element or element id
+ */
+ public function replaceContent($element)
+ {
+ $this->callClientFunction('Prado.Element.replaceContent', $element);
+ }
+
+ /**
+ * Add a Css class name to the element.
+ * @param TControl|string control element or element id
+ * @param string CssClass name to add.
+ */
+ public function addCssClass($element, $cssClass)
+ {
+ $this->callClientFunction('Element.addClassName', array($element, $cssClass));
+ }
+
+ /**
+ * Remove a Css class name from the element.
+ * @param TControl|string control element or element id
+ * @param string CssClass name to remove.
+ */
+ public function removeCssClass($element, $cssClass)
+ {
+ $this->callClientFunction('Element.removeClassName', array($element, $cssClass));
+ }
+
+ /**
+ * Sets the CssClass of an element.
+ * @param TControl|string control element or element id
+ * @param string new CssClass name for the element.
+ */
+ public function setCssClass($element, $cssClass)
+ {
+ $this->callClientFunction('Prado.Element.CssClass.set', array($element, $cssClass));
+ }
+
+ /**
+ * Scroll the top of the browser viewing area to the location of the
+ * element.
+ * @param TControl|string control element or element id
+ */
+ public function scrollTo($element)
+ {
+ $this->callClientFunction('Element.scrollTo', $element);
+ }
+
+ /**
+ * Sets the style of element. The style must be a key-value array where the
+ * key is the style property and the value is the style value.
+ * @param TControl|string control element or element id
+ * @param array list of key-value pairs as style property and style value.
+ */
+ public function setStyle($element, $styles)
+ {
+ $this->callClientFunction('Element.setStyle', array($element, $styles));
+ }
+
+ /**
+ * Insert a HTML fragement after the element.
+ * @param TControl|string control element or element id
+ * @param TControl|string HTML fragement, otherwise if TControl, its render
+ * method will be called.
+ */
+ public function insertAfter($element, $innerHTML)
+ {
+ if($innerHTML instanceof TControl)
+ $innerHTML = $innerHTML->render();
+ $this->callClientFunction('Prado.Element.Insert.After', array($element, $innerHTML));
+ }
+
+ /**
+ * Insert a HTML fragement before the element.
+ * @param TControl|string control element or element id
+ * @param TControl|string HTML fragement, otherwise if TControl, its render
+ * method will be called.
+ */
+ public function insertBefore($element, $innerHTML)
+ {
+ if($innerHTML instanceof TControl)
+ $innerHTML = $innerHTML->render();
+ $this->callClientFunction('Prado.Element.Insert.Before', array($element, $innerHTML));
+ }
+
+ /**
+ * Insert a HTML fragement below the element.
+ * @param TControl|string control element or element id
+ * @param TControl|string HTML fragement, otherwise if TControl, its render
+ * method will be called.
+ */
+ public function insertBelow($element, $innerHTML)
+ {
+ if($innerHTML instanceof TControl)
+ $innerHTML = $innerHTML->render();
+ $this->callClientFunction('Prado.Element.Insert.Below', array($element, $innerHTML));
+ }
+
+ /**
+ * Insert a HTML fragement above the element.
+ * @param TControl|string control element or element id
+ * @param TControl|string HTML fragement, otherwise if TControl, its render
+ * method will be called.
+ */
+ public function insertAbove($element, $innerHTML)
+ {
+ if($innerHTML instanceof TControl)
+ $innerHTML = $innerHTML->render();
+ $this->callClientFunction('Prado.Element.Insert.Above', array($element, $innerHTML));
+ }
+
+ /**
+ * Add a visual effect the element.
+ * @param string visual effect function name.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function visualEffect($type, $element, $options=null)
+ {
+ $this->callClientFunction($type, is_array($options) ? array($element, $options) : $element);
+ }
+
+ /**
+ * Visual Effect: Gradually make the element appear.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function appear($element, $options=null)
+ {
+ $this->visualEffect('Effect.Appear', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Blind down.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function blindDown($element, $options=null)
+ {
+ $this->visualEffect('Effect.BlindDown', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Blind up.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function blindUp($element, $options=null)
+ {
+ $this->visualEffect('Effect.BlindUp', $element, $options);
+
+ }
+
+ /**
+ * Visual Effect: Drop out.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function dropOut($element, $options=null)
+ {
+ $this->visualEffect('Effect.DropOut', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Gradually fade the element.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function fade($element, $options=null)
+ {
+ $this->visualEffect('Effect.Fade', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Fold.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function fold($element, $options = null)
+ {
+ $this->visualEffect('Effect.Fold', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Gradually make an element grow to a predetermined size.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function grow($element, $options=null)
+ {
+ $this->visualEffect('Effect.Grow', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Gradually grow and fade the element.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function puff($element, $options=null)
+ {
+ $this->visualEffect('Effect.Puff', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Pulsate.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function pulsate($element, $options=null)
+ {
+ $this->visualEffect('Effect.Pulsate', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Shake the element.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function shake($element, $options=null)
+ {
+ $this->visualEffect('Effect.Shake', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Shrink the element.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function shrink($element, $options=null)
+ {
+ $this->visualEffect('Effect.Shrink', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Slide down.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function slideDown($element, $options=null)
+ {
+ $this->visualEffect('Effect.SlideDown', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Side up.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function slideUp($element, $options=null)
+ {
+ $this->visualEffect('Effect.SlideUp', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Squish the element.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function squish($element, $options=null)
+ {
+ $this->visualEffect('Effect.Squish', $element, $options);
+ }
+
+ /**
+ * Visual Effect: Switch Off effect.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function switchOff($element, $options=null)
+ {
+ $this->visualEffect('Effect.SwitchOff', $element, $options);
+ }
+
+ /**
+ * Visual Effect: High light the element for about 2 seconds.
+ * @param TControl|string control element or element id
+ * @param array visual effect key-value pair options.
+ */
+ public function highlight($element, $options=null)
+ {
+ $this->visualEffect('Effect.Highlight', $element, $options);
+ }
+}
+
+?>
diff --git a/framework/Web/UI/ActiveControls/TCallbackResponse.php b/framework/Web/UI/ActiveControls/TCallbackResponse.php
new file mode 100644
index 00000000..bda4e916
--- /dev/null
+++ b/framework/Web/UI/ActiveControls/TCallbackResponse.php
@@ -0,0 +1,20 @@
+<?php
+/*
+ * Created on 29/04/2006
+ */
+
+// See TActivePageAdapter::renderResponse()
+//TODO: How to render the response, it will contain 3 pieces of data
+// 1) The arbituary data returned to the client-side callback handler
+// 2) client-side function call statements
+// 3) Content body, which may need to be partitioned
+
+class TCallbackResponse extends THttpResponse
+{
+ const CALLBACK_DATA_HEADER = 'X-PRADO-DATA';
+ const CALLBACK_ACTION_HEADER = 'X-PRADO-ACTIONS';
+}
+
+
+
+?>
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index 1f1d6c4d..1b5394ba 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -867,7 +867,7 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable
* Do not call this method directly. Instead, call {@link ensureChildControls}
* to ensure child controls are created only once.
*/
- protected function createChildControls()
+ public function createChildControls()
{
}
@@ -1215,6 +1215,9 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable
protected function preRenderRecursive()
{
$this->autoDataBindProperties();
+
+ if($this->getEnabled() && $this instanceof IPostBackDataHandler)
+ $this->getPage()->registerPostDataLoader($this);
if($this->getVisible(false))
{
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php
index e34101d9..31c80320 100644
--- a/framework/Web/UI/TPage.php
+++ b/framework/Web/UI/TPage.php
@@ -36,7 +36,7 @@ class TPage extends TTemplateControl
const FIELD_PAGESTATE='PRADO_PAGESTATE';
const FIELD_CALLBACK_TARGET='PRADO_CALLBACK_TARGET';
const FIELD_CALLBACK_PARAMETER='PRADO_CALLBACK_PARAMETER';
- const FIELD_CALLBACK_ID='PRADO_CALLBACK_ID';
+// const FIELD_CALLBACK_ID='PRADO_CALLBACK_ID';
/**
* @var array system post fields
*/
@@ -46,8 +46,8 @@ class TPage extends TTemplateControl
'PRADO_LASTFOCUS'=>true,
'PRADO_PAGESTATE'=>true,
'PRADO_CALLBACK_TARGET'=>true,
- 'PRADO_CALLBACK_PARAMETER'=>true,
- 'PRADO_CALLBACK_ID'=>true
+ 'PRADO_CALLBACK_PARAMETER'=>true
+ //'PRADO_CALLBACK_ID'=>true
);
/**
* @var TForm form instance
@@ -149,7 +149,11 @@ class TPage extends TTemplateControl
* @var string state string to be stored on the client side
*/
private $_clientState='';
-
+ /**
+ * @var array post data loader IDs.
+ */
+ private $_postDataLoaders=array();
+
/**
* Constructor.
* Sets the page object to itself.
@@ -259,11 +263,159 @@ class TPage extends TTemplateControl
$this->unloadRecursive();
}
+ /**
+ * Sets Adapter to TActivePageAdapter and calls apter to process the
+ * callback request.
+ */
protected function processCallbackRequest($writer)
{
+ $this->setAdapter(new TActivePageAdapter($this));
+
+ Prado::trace("Page onPreInit()",'System.Web.UI.TPage');
+ $this->onPreInit(null);
+
+ Prado::trace("Page initRecursive()",'System.Web.UI.TPage');
+ $this->initRecursive();
+
+ Prado::trace("Page onInitComplete()",'System.Web.UI.TPage');
+ $this->onInitComplete(null);
+
+ $this->_restPostData=new TMap;
+ Prado::trace("Page loadPageState()",'System.Web.UI.TPage');
+ $this->loadPageState();
+ Prado::trace("Page processPostData()",'System.Web.UI.TPage');
+ $this->processPostData($this->_postData,true);
+ Prado::trace("Page onPreLoad()",'System.Web.UI.TPage');
+ $this->onPreLoad(null);
+ Prado::trace("Page loadRecursive()",'System.Web.UI.TPage');
+ $this->loadRecursive();
+ Prado::trace("Page processPostData()",'System.Web.UI.TPage');
+ $this->processPostData($this->_restPostData,false);
+ Prado::trace("Page raiseChangedEvents()",'System.Web.UI.TPage');
+ $this->raiseChangedEvents();
+
+ $this->getAdapter()->processCallbackEvent($writer);
+
+/*
+ Prado::trace("Page raisePostBackEvent()",'System.Web.UI.TPage');
+ $this->raisePostBackEvent();
+*/
+ Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage');
+ $this->onLoadComplete(null);
+
+ Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage');
+ $this->preRenderRecursive();
+ Prado::trace("Page onPreRenderComplete()",'System.Web.UI.TPage');
+ $this->onPreRenderComplete(null);
+
+/* Prado::trace("Page savePageState()",'System.Web.UI.TPage');
+ $this->savePageState();
+ Prado::trace("Page onSaveStateComplete()",'System.Web.UI.TPage');
+ $this->onSaveStateComplete(null);
+
+ Prado::trace("Page renderControl()",'System.Web.UI.TPage');
+ $this->renderControl($writer);
+*/
+ $this->getAdapter()->renderCallbackResponse($writer);
+
+ Prado::trace("Page unloadRecursive()",'System.Web.UI.TPage');
+ $this->unloadRecursive();
+ }
+
+ /**
+ * Gets the callback response handler that permits changing the callback
+ * response headers and contents.
+ * @return TCallbackResponse callback response handler.
+ */
+ public function getCallbackResponse()
+ {
+ return $this->getAdapter()->getCallbackResponseHandler();
+ }
+
+ /**
+ * Set a new callback respond handler.
+ * @param TCallbackResponse a different callback response handler.
+ */
+ public function setCallbackResponse($responder)
+ {
+ $this->getAdapter()->setCallbackResponseHandler($responder);
+ }
+
+ /**
+ * Gets the callback client script handler that allows javascript functions
+ * to be executed during the callback response.
+ * @return TCallbackClientScript interface to client-side javascript code.
+ */
+ public function getCallbackClient()
+ {
+ return $this->getAdapter()->getCallbackClientHandler();
+ }
+
+ /**
+ * Set a new callback client handler.
+ * @param TCallbackClientScript new callback client script handler.
+ */
+ public function setCallbackClient($client)
+ {
+ $this->getAdapter()->setCallbackClientHandler($client);
+ }
+
+ /**
+ * @return TControl the control responsible for the current callback event,
+ * null if nonexistent
+ */
+ public function getCallbackEventTarget()
+ {
+ return $this->getAdapter()->getCallbackEventTarget();
}
/**
+ * Registers a control to raise callback event in the current request.
+ * @param TControl control registered to raise callback event.
+ */
+ public function setCallbackEventTarget(TControl $control)
+ {
+ $this->getAdapter()->setCallbackEventTarget($control);
+ }
+
+ /**
+ * Callback parameter is decoded assuming JSON encoding.
+ * @return string callback event parameter
+ */
+ public function getCallbackEventParameter()
+ {
+ return $this->getAdapter()->getCallbackEventParameter();
+ }
+
+ /**
+ * @param mixed callback event parameter
+ */
+ public function setCallbackEventParameter($value)
+ {
+ $this->getAdapter()->setCallbackEventParameter($value);
+ }
+
+ /**
+ * Register post data loaders for Callback to collect post data.
+ * This method should only be called by framework developers.
+ * @param TControl control that requires post data.
+ * @see TControl::preRenderRecursive();
+ */
+ public function registerPostDataLoader($control)
+ {
+ $this->_postDataLoaders[] = $control->getUniqueID();
+ }
+
+ /**
+ * Get a list of IDs of controls that are enabled and require post data.
+ * @return array list of IDs implementing IPostBackDataHandler
+ */
+ public function getPostDataLoaders()
+ {
+ return $this->_postDataLoaders;
+ }
+
+ /**
* @return TForm the form on the page
*/
public function getForm()
@@ -541,12 +693,11 @@ class TPage extends TTemplateControl
}
/**
- * TBD
* @return boolean whether this is a callback request
*/
public function getIsCallback()
{
- return false;
+ return $this->getIsPostBack() && $this->getRequest()->contains(self::FIELD_CALLBACK_TARGET);
}
/**
diff --git a/framework/Web/UI/TTemplateControl.php b/framework/Web/UI/TTemplateControl.php
index 971f0288..f18678f1 100644
--- a/framework/Web/UI/TTemplateControl.php
+++ b/framework/Web/UI/TTemplateControl.php
@@ -123,7 +123,7 @@ class TTemplateControl extends TControl implements INamingContainer
* This method is overriden to load and instantiate control template.
* This method should only be used by framework and control developers.
*/
- protected function createChildControls()
+ public function createChildControls()
{
if($tpl=$this->getTemplate(true))
{
diff --git a/framework/Web/UI/WebControls/TWizard.php b/framework/Web/UI/WebControls/TWizard.php
index 9a2c4ce6..20e27f2b 100644
--- a/framework/Web/UI/WebControls/TWizard.php
+++ b/framework/Web/UI/WebControls/TWizard.php
@@ -1005,7 +1005,7 @@ class TWizard extends TWebControl implements INamingContainer
/**
* Creates child controls within the wizard
*/
- protected function createChildControls()
+ public function createChildControls()
{
$this->reset();
$this->createSideBar();
@@ -1650,7 +1650,7 @@ class TTemplatedWizardStep extends TWizardStep implements INamingContainer
* Creates child controls.
* This method mainly instantiates the content template, if any.
*/
- protected function createChildControls()
+ public function createChildControls()
{
$this->getControls()->clear();
if($this->_contentTemplate)