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. --- HISTORY | 1 + framework/Web/UI/TTemplateManager.php | 34 ++++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/HISTORY b/HISTORY index 97bc0800..43f11657 100644 --- a/HISTORY +++ b/HISTORY @@ -22,6 +22,7 @@ ENH: added TTheme.BaseUrl and TTheme.BasePath property (Qiang) ENH: added TListControl.SelectedValues property (Qiang) ENH: added TThemeManager.AvailableThemes property (Qiang) ENH: refactored TUserManager and TAuthManager so that they are easier to be extended (Qiang) +ENH: template syntax now supports setting event handler via subproperties (Qiang) CHG: Ticket#151 - URL format is modified to handle empty GET values (Qiang) CHG: Ticket#153 - TAssetManager now ignores .svn directories (Qiang) NEW: TTableHeaderRow, TTableFooterRow and table section support (Qiang) 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