*/
class Mage_Adminhtml_Block_System_Config_Form_Fieldset
extends Mage_Adminhtml_Block_Abstract
implements Varien_Data_Form_Element_Renderer_Interface
{
/**
* Render fieldset html
*
* @param Varien_Data_Form_Element_Abstract $element
* @return string
*/
public function render(Varien_Data_Form_Element_Abstract $element)
{
$this->setElement($element);
$html = $this->_getHeaderHtml($element);
foreach ($element->getSortedElements() as $field) {
$html.= $field->toHtml();
}
$html .= $this->_getFooterHtml($element);
return $html;
}
/**
* Return header html for fieldset
*
* @param Varien_Data_Form_Element_Abstract $element
* @return string
*/
protected function _getHeaderHtml($element)
{
if ($element->getIsNested()) {
$html = '
';
} else {
$html = ' ';
}
$html .= $this->_getHeaderTitleHtml($element);
$html .= ' ';
$html .= ' ' . $this->_getExtraJs($element, $tooltipsExist);
if ($element->getIsNested()) {
$html .= ' |
';
} else {
$html .= '';
}
return $html;
}
/**
* Return js code for fieldset:
* - observe fieldset rows;
* - apply collapse;
*
* @param Varien_Data_Form_Element_Abstract $element
* @param bool $tooltipsExist Init tooltips observer or not
* @return string
*/
protected function _getExtraJs($element, $tooltipsExist = false)
{
$id = $element->getHtmlId();
$js = "Fieldset.applyCollapse('{$id}');";
return Mage::helper('adminhtml/js')->getScript($js);
}
/**
* Collapsed or expanded fieldset when page loaded?
*
* @param Varien_Data_Form_Element_Abstract $element
* @return bool
*/
protected function _getCollapseState($element)
{
if ($element->getExpanded() !== null) {
return 1;
}
$extra = Mage::getSingleton('admin/session')->getUser()->getExtra();
if (isset($extra['configState'][$element->getId()])) {
return $extra['configState'][$element->getId()];
}
return false;
}
}