summaryrefslogtreecommitdiff
path: root/framework/Web/UI/ActiveControls/TActiveControlAdapter.php
diff options
context:
space:
mode:
authorwei <>2006-05-14 00:30:53 +0000
committerwei <>2006-05-14 00:30:53 +0000
commitae43fa72cdae13bace16a5b8250170e472bb2b87 (patch)
tree6efea16ae0773f5c739bff2cf643f54ba499e5c0 /framework/Web/UI/ActiveControls/TActiveControlAdapter.php
parentddc3ea15bbfd0235fe90f3b2211bf4cc605e25d6 (diff)
refactor active controls.
Diffstat (limited to 'framework/Web/UI/ActiveControls/TActiveControlAdapter.php')
-rw-r--r--framework/Web/UI/ActiveControls/TActiveControlAdapter.php171
1 files changed, 165 insertions, 6 deletions
diff --git a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php
index 1cdd5d73..af4131ea 100644
--- a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php
+++ b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php
@@ -2,28 +2,187 @@
/*
* Created on 29/04/2006
*/
+Prado::using('System.Web.UI.ActiveControls.TBaseActiveControl');
class TActiveControlAdapter extends TControlAdapter
{
private static $_renderedPosts = false;
+ private $_activeControlType;
+
+ private $_baseActiveControl;
+
+ private $_stateTracker;
+
+ public function __construct($control, $baseCallbackClass=null)
+ {
+ parent::__construct($control);
+ $this->setBaseControlType($baseCallbackClass);
+ }
+
+ private function setBaseControlType($type)
+ {
+ if(is_null($type))
+ {
+ if($this->getControl() instanceof ICallbackEventHandler)
+ $this->_activeControlType = 'TBaseActiveCallbackControl';
+ else
+ $this->_activeControlType = 'TBaseActiveControl';
+ }
+ else
+ {
+ $this->_activeControlType = $type;
+ }
+ }
+
/**
* Render the callback request post data loaders once only.
*/
public function render($writer)
{
- if(!self::$_renderedPosts)
+ $this->renderCallbackClientScripts();
+ parent::render($writer);
+ if($this->getPage()->getIsCallback())
+ $this->getPage()->getCallbackClient()->replace($this->getControl(), $writer);
+ }
+
+ protected function renderCallbackClientScripts()
+ {
+ $cs = $this->getPage()->getClientScript();
+ $key = get_class($this);
+ if(!$cs->isEndScriptRegistered($key))
{
- $cs = $this->getPage()->getClientScript();
$cs->registerPradoScript('ajax');
$options = TJavascript::encode($this->getPage()->getPostDataLoaders(),false);
$script = "Prado.CallbackRequest.PostDataLoaders = {$options};";
- $cs->registerEndScript(get_class($this), $script);
- self::$_renderedPosts = true;
+ $cs->registerEndScript($key, $script);
}
- parent::render($writer);
+ }
+
+ public function getActiveControl()
+ {
+ if(is_null($this->_baseActiveControl))
+ {
+ $type = $this->_activeControlType;
+ $this->_baseActiveControl = new $type($this->getControl());
+ }
+ return $this->_baseActiveControl;
+ }
+
+ protected function getIsTrackingPageState()
+ {
if($this->getPage()->getIsCallback())
- $this->getPage()->getCallbackClient()->replace($this->getControl(), $writer);
+ {
+ $target = $this->getPage()->getCallbackEventTarget();
+ if($target instanceof ICallbackEventHandler)
+ {
+ $client = $target->getActiveControl()->getClientSide();
+ return $client->getEnablePageStateUpdate();
+ }
+ }
+ return false;
+ }
+
+ public function loadState()
+ {
+ if($this->getIsTrackingPageState())
+ {
+ $this->_stateTracker = new TCallbackPageStateTracker($this->getControl());
+ $this->_stateTracker->trackChanges();
+ }
+ parent::loadState();
+ }
+
+ public function saveState()
+ {
+ if(!is_null($this->_stateTracker)
+ && $this->getControl()->getActiveControl()->canUpdateClientSide())
+ {
+ $this->_stateTracker->respondToChanges();
+ }
+ parent::saveState();
}
}
+
+class TCallbackPageStateTracker
+{
+ private $_states = array('Visible', 'Enabled', 'Attributes', 'Style', 'TabIndex', 'ToolTip', 'AccessKey');
+ private $_existingState;
+ private $_control;
+ private $_nullObject;
+
+ public function __construct($control)
+ {
+ $this->_control = $control;
+ $this->_existingState = new TMap;
+ $this->_nullObject = new stdClass;
+ }
+
+ public function trackChanges()
+ {
+ foreach($this->_states as $name)
+ $this->_existingState[$name] = $this->_control->getViewState($name);
+ }
+
+ protected function getChanges()
+ {
+ $diff = array();
+ foreach($this->_states as $name)
+ {
+ $state = $this->_control->getViewState($name);
+ // echo " $name ";
+ $changes = $this->difference($state, $this->_existingState[$name]);
+ // echo " \n ";
+ if($changes !== $this->_nullObject)
+ $diff[$name] = $changes;
+ }
+ return $diff;
+ }
+
+ protected function difference($value1, $value2)
+ {
+// var_dump($value1, $value2);
+ if(gettype($value1) === gettype($value2)
+ && $value1 === $value2) return $this->_nullObject;
+ return $value1;
+ }
+
+ public function respondToChanges()
+ {
+ foreach($this->getChanges() as $property => $value)
+ {
+ $this->{'update'.$property}($value);
+ }
+ }
+
+ protected function client()
+ {
+ return $this->_control->getPage()->getCallbackClient();
+ }
+
+ protected function updateToolTip($value)
+ {
+ $this->client()->setAttribute($this->_control, 'title', $value);
+ }
+
+ protected function updateVisible($visible)
+ {
+ var_dump($visible);
+ if($visible === false)
+ $this->client()->hide($this->_control);
+ else
+ $this->client()->show($this->_control);
+ }
+
+ protected function updateEnabled($enable)
+ {
+ $this->client()->setAttribute($this->_control, 'disabled', $enable===false);
+ }
+
+ protected function updateStyle($style)
+ {
+ var_dump($style);
+ }
+}
+
?> \ No newline at end of file