From: <gem...@li...> - 2011-11-02 11:36:03
|
Revision: 164 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=164&view=rev Author: mennodekker Date: 2011-11-02 11:35:57 +0000 (Wed, 02 Nov 2011) Log Message: ----------- Hopefully transparent fix for huge tabform performance ->removes the duplicate steps in htmlElementsToTabs Modified Paths: -------------- trunk/library/classes/Gems/Form/TableForm.php trunk/library/classes/Gems/TabForm.php trunk/library/classes/MUtil/Model/FormBridge.php Modified: trunk/library/classes/Gems/Form/TableForm.php =================================================================== --- trunk/library/classes/Gems/Form/TableForm.php 2011-11-02 08:14:50 UTC (rev 163) +++ trunk/library/classes/Gems/Form/TableForm.php 2011-11-02 11:35:57 UTC (rev 164) @@ -120,7 +120,7 @@ $group->setDecorators( array('FormElements', array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')), array(array('labelCellClose' => 'HtmlTag'), array('tag' => 'td', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'closeOnly'=>true)), - array('Tooltip'), + 'Tooltip', array('Description', array('tag'=>'label', 'class'=>'optional', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'escape'=>false)), array(array('labelCellOpen' => 'HtmlTag'), array('tag' => 'td', 'class'=>'label', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'openOnly'=>true)), array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $this->_alternate . ' ' . $group->getName(). ' ' . $group->getAttrib('class'))) @@ -133,7 +133,7 @@ $decorators = array( array('Description', array('class'=>'description')), 'Errors', - array('Tooltip'), + 'Tooltip', ); //If we want to see the individual fields labels, do so: @@ -179,7 +179,7 @@ $decorators = array( array('Description', array('class'=>'description')), 'Errors', - array('Tooltip'), + 'Tooltip', array('Label', array('escape'=>false)), array(array('labelCell' => 'HtmlTag'), array('tag' => 'td', 'class'=>'label', 'colspan'=>2)), array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $element->getName())) @@ -192,7 +192,7 @@ 'Errors', array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')), array(array('labelCellClose' => 'HtmlTag'), array('tag' => 'td', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'closeOnly'=>true)), - array('Tooltip'), + 'Tooltip', array(array('labelCellOpen' => 'HtmlTag'), array('tag' => 'td', 'class'=>'label', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'openOnly'=>true)), array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $element->getName())) ); @@ -202,7 +202,7 @@ 'Errors', array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')), array(array('labelCellClose' => 'HtmlTag'), array('tag' => 'td', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'closeOnly'=>true)), - array('Tooltip'), + 'Tooltip', array('Label', array('escape'=>false)), array(array('labelCellOpen' => 'HtmlTag'), array('tag' => 'td', 'class'=>'label', 'placement'=> Zend_Form_Decorator_Abstract::PREPEND, 'openOnly'=>true)), array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => $element->getName())) @@ -222,7 +222,7 @@ $decorator->setOption('class', $this->_alternate . ' ' . $element->getName()); } - return parent::addElement($element); + return $this; } /** Modified: trunk/library/classes/Gems/TabForm.php =================================================================== --- trunk/library/classes/Gems/TabForm.php 2011-11-02 08:14:50 UTC (rev 163) +++ trunk/library/classes/Gems/TabForm.php 2011-11-02 11:35:57 UTC (rev 164) @@ -42,6 +42,75 @@ class Gems_TabForm extends Gems_Form { /** + * @var Gems_Form_TabSubForm + */ + private $currentTab = null; + + public function addElement($element, $name = null, $options = null) + { + if ($this->currentTab) { + return $this->currentTab->addElement($element, $name, $options); + } else { + return parent::addElement($element, $name, $options); + } + } + + public function addTab($name, $title) + { + if ($title instanceof MUtil_Html_Sequence) $title = $title->render($form->getView()); + $tab = new Gems_Form_TabSubForm(array('name' => $name, 'title' => strip_tags($title))); + $this->currentTab = $tab; + $this->addSubForm($tab, $name); + return $tab; + } + + public function addDisplayGroup(array $elements, $name, $options = null) { + if ($this->currentTab) { + return $this->currentTab->addDisplayGroup($elements, $name, $options); + } else { + //Add the group as usual + parent::addDisplayGroup($elements, $name, $options); + + //Retrieve it and set decorators + $group = $this->getDisplayGroup($name); + $group->setDecorators( array('FormElements', + array('HtmlTag', array('tag' => 'div', 'class' => $group->getName(). ' ' . $group->getAttrib('class'))) + )); + return $this; + } + } + + public function getDisplayGroup($name) + { + if ($group = parent::getDisplayGroup($name)) { + return $group; + } else { + $subforms = $this->getSubForms(); + foreach($subforms as $subform) { + if ($group = $subform->getDisplayGroup($name)) { + return $group; + } + } + return; + } + } + + public function getElement($name) + { + if ($element = parent::getElement($name)) { + return $element; + } else { + $subforms = $this->getSubForms(); + foreach($subforms as $subform) { + if ($element = $subform->getElement($name)) { + return $element; + } + } + return; + } + } + + /** * Create tabs from MUtil_Form_Element_Tab elements * * All elements following an element of type MUtil_Form_Element_Tab will be in tabs @@ -51,12 +120,6 @@ */ public static function htmlElementsToTabs($form) { foreach ($form as $element) { - //Make sure error decorator is the last one! (not really needed inside the tabs, but just to make sure) - $error = $element->getDecorator('Errors'); - if ($error instanceof Zend_Form_Decorator_Errors) { - $element->removeDecorator('Errors'); - $element->addDecorator($error); - } switch (get_class($element)) { case 'MUtil_Form_Element_Tab': //Start a new tab @@ -75,6 +138,7 @@ //zorg dat er geen display is voor hidden fields $element->removeDecorator('htmlTag'); $element->removeDecorator('Label'); + case 'Gems_Form_TabSubForm': case 'Zend_Form_Element_Submit': //Just leave this one out of the tabs break; @@ -103,7 +167,12 @@ $remove[] = $element->getName(); } } else { - unset($tab); + //Make sure error decorator is the last one! (not really needed inside the tabs, but just to make sure) + $error = $element->getDecorator('Errors'); + if ($error instanceof Zend_Form_Decorator_Errors) { + $element->removeDecorator('Errors'); + $element->addDecorator($error); + } } break; } @@ -218,15 +287,4 @@ return $form; } - - public function addDisplayGroup(array $elements, $name, $options = null) { - //Add the group as usual - parent::addDisplayGroup($elements, $name, $options); - - //Retrieve it and set decorators - $group = $this->getDisplayGroup($name); - $group->setDecorators( array('FormElements', - array('HtmlTag', array('tag' => 'div', 'class' => $group->getName(). ' ' . $group->getAttrib('class'))) - )); - } } \ No newline at end of file Modified: trunk/library/classes/MUtil/Model/FormBridge.php =================================================================== --- trunk/library/classes/MUtil/Model/FormBridge.php 2011-11-02 08:14:50 UTC (rev 163) +++ trunk/library/classes/MUtil/Model/FormBridge.php 2011-11-02 11:35:57 UTC (rev 164) @@ -618,10 +618,13 @@ $options = $this->_mergeOptions($name, $options, self::DISPLAY_OPTIONS, self::TAB_OPTIONS); - $element = new MUtil_Form_Element_Tab($name, $options); + if (method_exists($this->form, 'addTab')) { + return $this->form->addTab($name, $options['value']); + } else { + $element = new MUtil_Form_Element_Tab($name, $options); + $this->form->addElement($element); + } - $this->form->addElement($element); - return $element; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |