From 7944116201577b9650d249185fbd95f30f51f895 Mon Sep 17 00:00:00 2001 From: javalizard <> Date: Wed, 21 Apr 2010 01:11:06 +0000 Subject: Added Property to define if the templates in the decorator need to use the page state. Fixes Issue 262 --- .../Web/UI/WebControls/TWebControlDecorator.php | 92 +++++++++++++++++----- 1 file changed, 71 insertions(+), 21 deletions(-) (limited to 'framework/Web/UI/WebControls/TWebControlDecorator.php') diff --git a/framework/Web/UI/WebControls/TWebControlDecorator.php b/framework/Web/UI/WebControls/TWebControlDecorator.php index 6e8b2200..1db35df8 100644 --- a/framework/Web/UI/WebControls/TWebControlDecorator.php +++ b/framework/Web/UI/WebControls/TWebControlDecorator.php @@ -1,4 +1,4 @@ -_internalonly = $onlyinternal; } + /** + * @return boolean if the templates in this decoration need state. This defaults to false + */ + public function getUseState() + { + return $this->_usestate; + } + + /** + * @param boolean $value true to tell the decoration that the templates need state and should be + * placed in a control step before the state is saved. + */ + public function setUseState($value) + { + $this->_usestate = TPropertyValue::ensureBoolean($value); + } + /** * @return string gets the text before the open tag in the TWebControl */ @@ -257,49 +287,69 @@ class TWebControlDecorator extends TComponent { * This call attaches the ensureTemplateDecoration to the TPage onSaveStateComplete so * these controls don't have page states. This is as close to not influencing the page as possible. */ - public function instantiate() { - - $this->_addedTemplateDecoration = false; - + public function instantiate($outercontrol = null) { if($this->getPreTagTemplate() || $this->getPreContentsTemplate() || - $this->getPostContentsTemplate() || $this->getPostTagTemplate()) - $control->getPage()->onSaveStateComplete[] = array($this, 'ensureTemplateDecoration'); - // OnPreRenderComplete onSaveStateComplete + $this->getPostContentsTemplate() || $this->getPostTagTemplate()) { + + $this->_outercontrol = $outercontrol; + if($this->getUseState()) + $this->ensureTemplateDecoration(); + else + $this->_control->getPage()->onSaveStateComplete[] = array($this, 'ensureTemplateDecoration'); + } } /** - * This method places the templates around the open and close tag + * This method places the templates around the open and close tag. This takes a parameter which is + * to specify the control to get the outer template decoration. If no outer control is specified + * @param TComponent this indicates the component or control to get the outer tag elements, just in case it's + * different than attached TWebControl. If none is provided, the outer templates default to the attached + * control * @return boolean returns true if the template decorations have been added */ - public function ensureTemplateDecoration() { + public function ensureTemplateDecoration($sender=null, $param=null) { + $control = $this->_control; - if($this->_addedTemplateDecoration || !$control->Parent) return $this->_addedTemplateDecoration; + $outercontrol = $this->_outercontrol; + if($outercontrol === null) + $outercontrol = $control; + + if($this->_addedTemplateDecoration) + return $this->_addedTemplateDecoration; $this->_addedTemplateDecoration = true; - if($this->getPreTagTemplate()) { - $pretag = Prado::createComponent('TCompositeControl'); - $this->getPreTagTemplate()->instantiateIn($pretag); - $control->getParent()->getControls()->insertBefore($control, $pretag); - } - - if($this->getPreContentsTemplate()) { + if($this->getPreContentsTemplate()) + { $precontents = Prado::createComponent('TCompositeControl'); $this->getPreContentsTemplate()->instantiateIn($precontents); $control->getControls()->insertAt(0, $precontents); } - if($this->getPostContentsTemplate()) { + if($this->getPostContentsTemplate()) + { $postcontents = Prado::createComponent('TCompositeControl'); $this->getPostContentsTemplate()->instantiateIn($postcontents); $control->getControls()->add($postcontents); } - if($this->getPostTagTemplate()) { + if(!$outercontrol->getParent()) + return $this->_addedTemplateDecoration; + + + if($this->getPreTagTemplate()) + { + $pretag = Prado::createComponent('TCompositeControl'); + $this->getPreTagTemplate()->instantiateIn($pretag); + $outercontrol->getParent()->getControls()->insertBefore($outercontrol, $pretag); + } + + if($this->getPostTagTemplate()) + { $posttag = Prado::createComponent('TCompositeControl'); $this->getPostTagTemplate()->instantiateIn($posttag); - $control->getParent()->getControls()->insertAfter($control, $posttag); + $outercontrol->getParent()->getControls()->insertAfter($outercontrol, $posttag); } return true; } -- cgit v1.2.3