1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Config form fieldset renderer
30: *
31: * @category Mage
32: * @package Mage_Adminhtml
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Adminhtml_Block_System_Config_Form_Fieldset
36: extends Mage_Adminhtml_Block_Abstract
37: implements Varien_Data_Form_Element_Renderer_Interface
38: {
39:
40: /**
41: * Render fieldset html
42: *
43: * @param Varien_Data_Form_Element_Abstract $element
44: * @return string
45: */
46: public function render(Varien_Data_Form_Element_Abstract $element)
47: {
48: $this->setElement($element);
49: $html = $this->_getHeaderHtml($element);
50:
51: foreach ($element->getSortedElements() as $field) {
52: $html.= $field->toHtml();
53: }
54:
55: $html .= $this->_getFooterHtml($element);
56:
57: return $html;
58: }
59:
60: /**
61: * Return header html for fieldset
62: *
63: * @param Varien_Data_Form_Element_Abstract $element
64: * @return string
65: */
66: protected function _getHeaderHtml($element)
67: {
68: if ($element->getIsNested()) {
69: $html = '<tr class="nested"><td colspan="4"><div class="' . $this->_getFrontendClass($element) . '">';
70: } else {
71: $html = '<div class="' . $this->_getFrontendClass($element) . '">';
72: }
73:
74: $html .= $this->_getHeaderTitleHtml($element);
75:
76: $html .= '<input id="'.$element->getHtmlId() . '-state" name="config_state[' . $element->getId()
77: . ']" type="hidden" value="' . (int)$this->_getCollapseState($element) . '" />';
78: $html .= '<fieldset class="' . $this->_getFieldsetCss($element) . '" id="' . $element->getHtmlId() . '">';
79: $html .= '<legend>' . $element->getLegend() . '</legend>';
80:
81: $html .= $this->_getHeaderCommentHtml($element);
82:
83: // field label column
84: $html .= '<table cellspacing="0" class="form-list"><colgroup class="label" /><colgroup class="value" />';
85: if ($this->getRequest()->getParam('website') || $this->getRequest()->getParam('store')) {
86: $html .= '<colgroup class="use-default" />';
87: }
88: $html .= '<colgroup class="scope-label" /><colgroup class="" /><tbody>';
89:
90: return $html;
91: }
92:
93: /**
94: * Get frontend class
95: *
96: * @param Varien_Data_Form_Element_Abstract $element
97: * @return string
98: */
99: protected function _getFrontendClass($element)
100: {
101: $frontendClass = (string)$this->getGroup($element)->frontend_class;
102: return 'section-config' . (empty($frontendClass) ? '' : (' ' . $frontendClass));
103: }
104:
105: /**
106: * Get group xml data of the element
107: *
108: * @param null|Varien_Data_Form_Element_Abstract $element
109: * @return Mage_Core_Model_Config_Element
110: */
111: public function getGroup($element = null)
112: {
113: if (is_null($element)) {
114: $element = $this->getElement();
115: }
116: if ($element && $element->getGroup() instanceof Mage_Core_Model_Config_Element) {
117: return $element->getGroup();
118: }
119:
120: return new Mage_Core_Model_Config_Element('<config/>');
121: }
122:
123: /**
124: * Return header title part of html for fieldset
125: *
126: * @param Varien_Data_Form_Element_Abstract $element
127: * @return string
128: */
129: protected function _getHeaderTitleHtml($element)
130: {
131: return '<div class="entry-edit-head collapseable" ><a id="' . $element->getHtmlId()
132: . '-head" href="#" onclick="Fieldset.toggleCollapse(\'' . $element->getHtmlId() . '\', \''
133: . $this->getUrl('*/*/state') . '\'); return false;">' . $element->getLegend() . '</a></div>';
134: }
135:
136: /**
137: * Return header comment part of html for fieldset
138: *
139: * @param Varien_Data_Form_Element_Abstract $element
140: * @return string
141: */
142: protected function _getHeaderCommentHtml($element)
143: {
144: return $element->getComment()
145: ? '<div class="comment">' . $element->getComment() . '</div>'
146: : '';
147: }
148:
149: /**
150: * Return full css class name for form fieldset
151: *
152: * @param null|Varien_Data_Form_Element_Abstract $element
153: * @return string
154: */
155: protected function _getFieldsetCss($element = null)
156: {
157: $configCss = (string)$this->getGroup($element)->fieldset_css;
158: return 'config collapseable' . ($configCss ? ' ' . $configCss : '');
159: }
160:
161: /**
162: * Return footer html for fieldset
163: * Add extra tooltip comments to elements
164: *
165: * @param Varien_Data_Form_Element_Abstract $element
166: * @return string
167: */
168: protected function _getFooterHtml($element)
169: {
170: $tooltipsExist = false;
171: $html = '</tbody></table>';
172: $html .= '</fieldset>' . $this->_getExtraJs($element, $tooltipsExist);
173:
174: if ($element->getIsNested()) {
175: $html .= '</div></td></tr>';
176: } else {
177: $html .= '</div>';
178: }
179: return $html;
180: }
181:
182: /**
183: * Return js code for fieldset:
184: * - observe fieldset rows;
185: * - apply collapse;
186: *
187: * @param Varien_Data_Form_Element_Abstract $element
188: * @param bool $tooltipsExist Init tooltips observer or not
189: * @return string
190: */
191: protected function _getExtraJs($element, $tooltipsExist = false)
192: {
193: $id = $element->getHtmlId();
194: $js = "Fieldset.applyCollapse('{$id}');";
195: return Mage::helper('adminhtml/js')->getScript($js);
196: }
197:
198: /**
199: * Collapsed or expanded fieldset when page loaded?
200: *
201: * @param Varien_Data_Form_Element_Abstract $element
202: * @return bool
203: */
204: protected function _getCollapseState($element)
205: {
206: if ($element->getExpanded() !== null) {
207: return 1;
208: }
209: $extra = Mage::getSingleton('admin/session')->getUser()->getExtra();
210: if (isset($extra['configState'][$element->getId()])) {
211: return $extra['configState'][$element->getId()];
212: }
213: return false;
214: }
215: }
216: