1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Adminhtml_Block_Catalog_Category_Tab_Attributes extends Mage_Adminhtml_Block_Catalog_Form
36: {
37: 38: 39: 40: 41:
42: public function getCategory()
43: {
44: return Mage::registry('current_category');
45: }
46:
47: 48: 49: 50:
51: public function __construct() {
52: parent::__construct();
53: $this->setShowGlobalIcon(true);
54: }
55:
56: 57: 58:
59: protected function _prepareLayout()
60: {
61: parent::_prepareLayout();
62: if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
63: $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
64: }
65: }
66:
67: 68: 69: 70: 71:
72: protected function _prepareForm() {
73: $group = $this->getGroup();
74: $attributes = $this->getAttributes();
75:
76: $form = new Varien_Data_Form();
77: $form->setHtmlIdPrefix('group_' . $group->getId());
78: $form->setDataObject($this->getCategory());
79:
80: $fieldset = $form->addFieldset('fieldset_group_' . $group->getId(), array(
81: 'legend' => Mage::helper('catalog')->__($group->getAttributeGroupName()),
82: 'class' => 'fieldset-wide',
83: ));
84:
85: if ($this->getAddHiddenFields()) {
86: if (!$this->getCategory()->getId()) {
87:
88: if ($this->getRequest()->getParam('parent')) {
89: $fieldset->addField('path', 'hidden', array(
90: 'name' => 'path',
91: 'value' => $this->getRequest()->getParam('parent')
92: ));
93: }
94: else {
95: $fieldset->addField('path', 'hidden', array(
96: 'name' => 'path',
97: 'value' => 1
98: ));
99: }
100: }
101: else {
102: $fieldset->addField('id', 'hidden', array(
103: 'name' => 'id',
104: 'value' => $this->getCategory()->getId()
105: ));
106: $fieldset->addField('path', 'hidden', array(
107: 'name' => 'path',
108: 'value' => $this->getCategory()->getPath()
109: ));
110: }
111: }
112:
113: $this->_setFieldset($attributes, $fieldset);
114:
115: foreach ($attributes as $attribute) {
116:
117: if ($attribute->getAttributeCode() == 'url_key') {
118: if ($this->getCategory()->getLevel() == 1) {
119: $fieldset->removeField('url_key');
120: $fieldset->addField('url_key', 'hidden', array(
121: 'name' => 'url_key',
122: 'value' => $this->getCategory()->getUrlKey()
123: ));
124: } else {
125: $form->getElement('url_key')->setRenderer(
126: $this->getLayout()->createBlock('adminhtml/catalog_form_renderer_attribute_urlkey')
127: );
128: }
129: }
130: }
131:
132: if ($this->getCategory()->getLevel() == 1) {
133: $fieldset->removeField('custom_use_parent_settings');
134: } else {
135: if ($this->getCategory()->getCustomUseParentSettings()) {
136: foreach ($this->getCategory()->getDesignAttributes() as $attribute) {
137: if ($element = $form->getElement($attribute->getAttributeCode())) {
138: $element->setDisabled(true);
139: }
140: }
141: }
142: if ($element = $form->getElement('custom_use_parent_settings')) {
143: $element->setData('onchange', 'onCustomUseParentChanged(this)');
144: }
145: }
146:
147: if ($this->getCategory()->hasLockedAttributes()) {
148: foreach ($this->getCategory()->getLockedAttributes() as $attribute) {
149: if ($element = $form->getElement($attribute)) {
150: $element->setReadonly(true, true);
151: }
152: }
153: }
154:
155: if (!$this->getCategory()->getId()){
156: $this->getCategory()->setIncludeInMenu(1);
157: }
158:
159: $form->addValues($this->getCategory()->getData());
160:
161: Mage::dispatchEvent('adminhtml_catalog_category_edit_prepare_form', array('form'=>$form));
162:
163: $form->setFieldNameSuffix('general');
164: $this->setForm($form);
165:
166: return parent::_prepareForm();
167: }
168:
169: 170: 171: 172: 173:
174: protected function _getAdditionalElementTypes()
175: {
176: return array(
177: 'image' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_category_helper_image'),
178: 'textarea' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_helper_form_wysiwyg')
179: );
180: }
181: }
182: