From 33698666dd7ed5b852c57235b49fa1999d0db46f Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 2 Jun 2006 18:05:47 +0000 Subject: Added support to subproperty-style event binding. --- framework/Web/UI/TTemplateManager.php | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'framework') diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php index 379eec2f..97a2c020 100644 --- a/framework/Web/UI/TTemplateManager.php +++ b/framework/Web/UI/TTemplateManager.php @@ -356,16 +356,37 @@ class TTemplate extends TApplicationComponent implements ITemplate * @param string property name * @param mixed property initial value */ + protected function configureControl2($control,$name,$value) + { + if(strncasecmp($name,'on',2)===0) // is an event + $this->configureEvent($control,$name,$value,$control); + else if(($pos=strrpos($name,'.'))===false) // is a simple property or custom attribute + $this->configureProperty($control,$name,$value); + else // is a subproperty + { + $subName=substr($name,$pos+1); + if(strncasecmp($subName,'on',2)===0) // is an event: XXX.YYY.OnZZZ + { + $object=$control->getSubProperty(substr($name,0,$pos)); + if(($object instanceof TControl)) + $this->configureEvent($object,$subName,$value,$control); + else + $this->configureSubProperty($control,$name,$value); + } + else + $this->configureSubProperty($control,$name,$value); + } + } + protected function configureControl($control,$name,$value) { if(strncasecmp($name,'on',2)===0) // is an event - $this->configureEvent($control,$name,$value); - else if(strpos($name,'.')===false) // is a simple property or custom attribute + $this->configureEvent($control,$name,$value,$control); + else if(($pos=strrpos($name,'.'))===false) // is a simple property or custom attribute $this->configureProperty($control,$name,$value); else // is a subproperty $this->configureSubProperty($control,$name,$value); } - /** * Configures a property of a non-control component. * @param TComponent component to be configured @@ -385,13 +406,14 @@ class TTemplate extends TApplicationComponent implements ITemplate * @param TControl control to be configured * @param string event name * @param string event handler + * @param TControl context control */ - protected function configureEvent($component,$name,$value) + protected function configureEvent($control,$name,$value,$contextControl) { if(strpos($value,'.')===false) - $component->attachEventHandler($name,array($component,'TemplateControl.'.$value)); + $control->attachEventHandler($name,array($contextControl,'TemplateControl.'.$value)); else - $component->attachEventHandler($name,array($component,$value)); + $control->attachEventHandler($name,array($contextControl,$value)); } /** -- cgit v1.2.3