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: class Mage_Adminhtml_Block_Catalog_Category_Edit_Form extends Mage_Adminhtml_Block_Catalog_Category_Abstract
35: {
36: 37: 38: 39: 40:
41: protected $_additionalButtons = array();
42:
43: public function __construct()
44: {
45: parent::__construct();
46: $this->setTemplate('catalog/category/edit/form.phtml');
47: }
48:
49: protected function _prepareLayout()
50: {
51: $category = $this->getCategory();
52: $categoryId = (int) $category->getId();
53:
54: $this->setChild('tabs',
55: $this->getLayout()->createBlock('adminhtml/catalog_category_tabs', 'tabs')
56: );
57:
58:
59: if (!$category->isReadonly()) {
60: $this->setChild('save_button',
61: $this->getLayout()->createBlock('adminhtml/widget_button')
62: ->setData(array(
63: 'label' => Mage::helper('catalog')->__('Save Category'),
64: 'onclick' => "categorySubmit('" . $this->getSaveUrl() . "', true)",
65: 'class' => 'save'
66: ))
67: );
68: }
69:
70:
71: if (!in_array($categoryId, $this->getRootIds()) && $category->isDeleteable()) {
72: $this->setChild('delete_button',
73: $this->getLayout()->createBlock('adminhtml/widget_button')
74: ->setData(array(
75: 'label' => Mage::helper('catalog')->__('Delete Category'),
76: 'onclick' => "categoryDelete('" . $this->getUrl('*/*/delete', array('_current' => true)) . "', true, {$categoryId})",
77: 'class' => 'delete'
78: ))
79: );
80: }
81:
82:
83: if (!$category->isReadonly()) {
84: $resetPath = $categoryId ? '*/*/edit' : '*/*/add';
85: $this->setChild('reset_button',
86: $this->getLayout()->createBlock('adminhtml/widget_button')
87: ->setData(array(
88: 'label' => Mage::helper('catalog')->__('Reset'),
89: 'onclick' => "categoryReset('".$this->getUrl($resetPath, array('_current'=>true))."',true)"
90: ))
91: );
92: }
93:
94: return parent::_prepareLayout();
95: }
96:
97: public function getStoreConfigurationUrl()
98: {
99: $storeId = (int) $this->getRequest()->getParam('store');
100: $params = array();
101:
102: if ($storeId) {
103: $store = Mage::app()->getStore($storeId);
104: $params['website'] = $store->getWebsite()->getCode();
105: $params['store'] = $store->getCode();
106: }
107: return $this->getUrl('*/system_store', $params);
108: }
109:
110: public function getDeleteButtonHtml()
111: {
112: return $this->getChildHtml('delete_button');
113: }
114:
115: public function getSaveButtonHtml()
116: {
117: if ($this->hasStoreRootCategory()) {
118: return $this->getChildHtml('save_button');
119: }
120: return '';
121: }
122:
123: public function getResetButtonHtml()
124: {
125: if ($this->hasStoreRootCategory()) {
126: return $this->getChildHtml('reset_button');
127: }
128: return '';
129: }
130:
131: 132: 133: 134: 135:
136: public function getAdditionalButtonsHtml()
137: {
138: $html = '';
139: foreach ($this->_additionalButtons as $childName) {
140: $html .= $this->getChildHtml($childName);
141: }
142: return $html;
143: }
144:
145: 146: 147: 148: 149: 150: 151:
152: public function addAdditionalButton($alias, $config)
153: {
154: if (isset($config['name'])) {
155: $config['element_name'] = $config['name'];
156: }
157: $this->setChild($alias . '_button',
158: $this->getLayout()->createBlock('adminhtml/widget_button')->addData($config));
159: $this->_additionalButtons[$alias] = $alias . '_button';
160: return $this;
161: }
162:
163: 164: 165: 166: 167: 168:
169: public function removeAdditionalButton($alias)
170: {
171: if (isset($this->_additionalButtons[$alias])) {
172: $this->unsetChild($this->_additionalButtons[$alias]);
173: unset($this->_additionalButtons[$alias]);
174: }
175:
176: return $this;
177: }
178:
179: public function getTabsHtml()
180: {
181: return $this->getChildHtml('tabs');
182: }
183:
184: public function ()
185: {
186: if ($this->hasStoreRootCategory()) {
187: if ($this->getCategoryId()) {
188: return $this->getCategoryName();
189: } else {
190: $parentId = (int) $this->getRequest()->getParam('parent');
191: if ($parentId && ($parentId != Mage_Catalog_Model_Category::TREE_ROOT_ID)) {
192: return Mage::helper('catalog')->__('New Subcategory');
193: } else {
194: return Mage::helper('catalog')->__('New Root Category');
195: }
196: }
197: }
198: return Mage::helper('catalog')->__('Set Root Category for Store');
199: }
200:
201: public function getDeleteUrl(array $args = array())
202: {
203: $params = array('_current'=>true);
204: $params = array_merge($params, $args);
205: return $this->getUrl('*/*/delete', $params);
206: }
207:
208: 209: 210: 211: 212: 213:
214: public function getRefreshPathUrl(array $args = array())
215: {
216: $params = array('_current'=>true);
217: $params = array_merge($params, $args);
218: return $this->getUrl('*/*/refreshPath', $params);
219: }
220:
221: public function getProductsJson()
222: {
223: $products = $this->getCategory()->getProductsPosition();
224: if (!empty($products)) {
225: return Mage::helper('core')->jsonEncode($products);
226: }
227: return '{}';
228: }
229:
230: public function isAjax()
231: {
232: return Mage::app()->getRequest()->isXmlHttpRequest() || Mage::app()->getRequest()->getParam('isAjax');
233: }
234: }
235: