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_Urlrewrite_Edit extends Mage_Adminhtml_Block_Widget_Container
35: {
36: 37: 38: 39: 40:
41: protected $_controller = 'urlrewrite';
42:
43: 44: 45: 46: 47:
48: protected $_buttonsHtml;
49:
50: 51: 52: 53: 54: 55:
56: protected function _prepareLayout()
57: {
58: $this->setTemplate('urlrewrite/edit.phtml');
59: $this->_addButton('back', array(
60: 'label' => Mage::helper('adminhtml')->__('Back'),
61: 'onclick' => 'setLocation(\'' . Mage::helper('adminhtml')->getUrl('*/*/') . '\')',
62: 'class' => 'back',
63: 'level' => -1
64: ));
65:
66:
67: if ($this->getProductId()) {
68: $this->setChild('product_link', $this->getLayout()->createBlock('adminhtml/urlrewrite_link')
69: ->setData(array(
70: 'item_url' => Mage::helper('adminhtml')->getUrl('*/*/*') . 'product',
71: 'item' => Mage::registry('current_product'),
72: 'label' => Mage::helper('adminhtml')->__('Product:')
73: ))
74: );
75: }
76: if ($this->getCategoryId()) {
77: $itemUrl = Mage::helper('adminhtml')->getUrl('*/*/*') . 'category';
78: if ($this->getProductId()) {
79: $itemUrl = Mage::helper('adminhtml')->getUrl('*/*/*', array('product' => $this->getProductId())) . 'category';
80: }
81: $this->setChild('category_link', $this->getLayout()->createBlock('adminhtml/urlrewrite_link')
82: ->setData(array(
83: 'item_url' => $itemUrl,
84: 'item' => Mage::registry('current_category'),
85: 'label' => Mage::helper('adminhtml')->__('Category:')
86: ))
87: );
88: }
89:
90: $this->_headerText = Mage::helper('adminhtml')->__('Add New URL Rewrite');
91:
92:
93: if ($this->getUrlrewriteId()) {
94: $this->_headerText = Mage::helper('adminhtml')->__('Edit URL Rewrite');
95: $this->_setFormChild();
96: }
97: elseif ($this->getProductId()) {
98: $this->_headerText = Mage::helper('adminhtml')->__('Add URL Rewrite for a Product');
99:
100:
101: if ($this->getCategoryId() || !$this->isMode('category')) {
102: $this->_setFormChild();
103: }
104:
105: else {
106: $this->setChild('categories_tree', $this->getLayout()->createBlock('adminhtml/urlrewrite_category_tree'));
107: $this->setChild('skip_categories',
108: $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
109: 'label' => Mage::helper('adminhtml')->__('Skip Category Selection'),
110: 'onclick' => 'window.location = \'' . Mage::helper('adminhtml')->getUrl('*/*/*', array(
111: 'product' => $this->getProductId()
112: )) . '\'',
113: 'class' => 'save',
114: 'level' => -1
115: ))
116: );
117: $this->_updateButton('back', 'onclick', 'setLocation(\'' . Mage::helper('adminhtml')->getUrl('*/*/edit') . 'product\')');
118: }
119: }
120:
121: elseif ($this->getCategoryId()) {
122: $this->_headerText = Mage::helper('adminhtml')->__('Add URL Rewrite for a Category');
123: $this->_setFormChild();
124: }
125:
126: else {
127: $this->setChild('selector', $this->getLayout()->createBlock('adminhtml/urlrewrite_selector'));
128:
129: if ($this->isMode('id')) {
130: $this->updateModeLayout('id');
131: }
132: elseif ($this->isMode('product')) {
133: $this->updateModeLayout('product');
134: }
135: elseif ($this->isMode('category')) {
136: $this->updateModeLayout('category');
137: }
138: else {
139: $this->updateModeLayout();
140: }
141: }
142:
143: return parent::_prepareLayout();
144: }
145:
146: 147: 148: 149: 150:
151: protected function _setFormChild()
152: {
153: $this->setChild('form', Mage::getBlockSingleton('adminhtml/urlrewrite_edit_form'));
154: if ($this->getUrlrewriteId()) {
155: $this->_addButton('reset', array(
156: 'label' => Mage::helper('adminhtml')->__('Reset'),
157: 'onclick' => '$(\'edit_form\').reset()',
158: 'class' => 'scalable',
159: 'level' => -1
160: ));
161: $this->_addButton('delete', array(
162: 'label' => Mage::helper('adminhtml')->__('Delete'),
163: 'onclick' => 'deleteConfirm(\'' . Mage::helper('adminhtml')->__('Are you sure you want to do this?')
164: . '\', \'' . Mage::helper('adminhtml')->getUrl('*/*/delete', array('id' => $this->getUrlrewriteId())) . '\')',
165: 'class' => 'scalable delete',
166: 'level' => -1
167: ));
168: }
169: $this->_addButton('save', array(
170: 'label' => Mage::helper('adminhtml')->__('Save'),
171: 'onclick' => 'editForm.submit()',
172: 'class' => 'save',
173: 'level' => -1
174: ));
175:
176:
177: $params = array();
178: $suffix = '';
179: $action = '';
180: if (!$this->getUrlrewriteId()) {
181: $action = 'edit';
182: if ($this->getProductId()) {
183: $suffix = 'category';
184: $params['product'] = $this->getProductId();
185: }
186: elseif ($this->getCategoryId()) {
187: $suffix = 'category';
188: }
189: }
190: $this->_updateButton('back', 'onclick', 'setLocation(\'' . Mage::helper('adminhtml')->getUrl('*/*/' . $action, $params) . $suffix . '\')');
191:
192: return $this;
193: }
194:
195: 196: 197: 198: 199: 200: 201: 202:
203: public function getButtonsHtml($area = null)
204: {
205: if (null === $this->_buttonsHtml) {
206: $this->_buttonsHtml = parent::getButtonsHtml();
207: foreach ($this->_children as $alias => $child) {
208: if (false !== strpos($alias, '_button')) {
209: $this->unsetChild($alias);
210: }
211: }
212: }
213: return $this->_buttonsHtml;
214: }
215:
216: 217: 218: 219: 220:
221: public function getUrlrewriteId()
222: {
223: return Mage::registry('current_urlrewrite')->getId();
224: }
225:
226: 227: 228: 229: 230:
231: public function getProductId()
232: {
233: return Mage::registry('current_product')->getId();
234: }
235:
236: 237: 238: 239: 240:
241: public function getCategoryId()
242: {
243: return Mage::registry('current_category')->getId();
244: }
245:
246: 247: 248: 249: 250: 251:
252: public function isMode($mode)
253: {
254: return $this->getRequest()->has($mode);
255: }
256:
257: 258: 259: 260: 261: 262: 263:
264: public function updateModeLayout($mode = null)
265: {
266: if (!$mode) {
267: $modes = array_keys(Mage::getBlockSingleton('adminhtml/urlrewrite_selector')->getModes());
268: $mode = array_shift($modes);
269: }
270:
271:
272: if ('id' === $mode) {
273: $this->_setFormChild();
274: }
275:
276: elseif ('product' === $mode) {
277: $this->setChild('products_grid', $this->getLayout()->createBlock('adminhtml/urlrewrite_product_grid'));
278: }
279:
280: elseif ('category' === $mode) {
281: $this->setChild('categories_tree', $this->getLayout()->createBlock('adminhtml/urlrewrite_category_tree'));
282: }
283: return $this;
284: }
285: }
286: