00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Adminhtml_Block_Urlrewrite_Edit extends Mage_Adminhtml_Block_Widget_Container
00035 {
00036
00037
00038
00039
00040
00041 protected $_controller = 'urlrewrite';
00042
00043
00044
00045
00046
00047
00048 protected $_buttonsHtml;
00049
00050
00051
00052
00053
00054
00055
00056 protected function _prepareLayout()
00057 {
00058 $this->setTemplate('urlrewrite/edit.phtml');
00059 $this->_addButton('back', array(
00060 'label' => Mage::helper('adminhtml')->__('Back'),
00061 'onclick' => 'setLocation(\'' . Mage::helper('adminhtml')->getUrl('*/*/') . '\')',
00062 'class' => 'back',
00063 'level' => -1
00064 ));
00065
00066 // links to products/categories (if any) selectors
00067 if ($this->getProductId()) {
00068 $this->setChild('product_link', $this->getLayout()->createBlock('adminhtml/urlrewrite_link')
00069 ->setData(array(
00070 'item_url' => Mage::helper('adminhtml')->getUrl('*
00071
00072
00073
00074
00075
00076
00077 *
00078
00079 *
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 *
00111
00112
00113
00114
00115
00116
00117 */edit') . 'product\')');
00118 }
00119 }
00120
00121 elseif ($this->getCategoryId()) {
00122 $this->_headerText = Mage::helper('adminhtml')->__('Add Urlrewrite for a Category');
00123 $this->_setFormChild();
00124 }
00125
00126 else {
00127 $this->setChild('selector', $this->getLayout()->createBlock('adminhtml/urlrewrite_selector'));
00128
00129 if ($this->isMode('id')) {
00130 $this->updateModeLayout('id');
00131 }
00132 elseif ($this->isMode('product')) {
00133 $this->updateModeLayout('product');
00134 }
00135 elseif ($this->isMode('category')) {
00136 $this->updateModeLayout('category');
00137 }
00138 else {
00139 $this->updateModeLayout();
00140 }
00141 }
00142
00143 return parent::_prepareLayout();
00144 }
00145
00146
00147
00148
00149
00150
00151 protected function _setFormChild()
00152 {
00153 $this->setChild('form', Mage::getBlockSingleton('adminhtml/urlrewrite_edit_form'));
00154 if ($this->getUrlrewriteId()) {
00155 $this->_addButton('reset', array(
00156 'label' => Mage::helper('adminhtml')->__('Reset'),
00157 'onclick' => '$(\'edit_form\').reset()',
00158 'class' => 'scalable',
00159 'level' => -1
00160 ));
00161 $this->_addButton('delete', array(
00162 'label' => Mage::helper('adminhtml')->__('Delete'),
00163 'onclick' => 'deleteConfirm(\'' . Mage::helper('adminhtml')->__('Are you sure you want to do this?')
00164 . '\', \'' . Mage::helper('adminhtml')->getUrl('*/*/delete', array('id' => $this->getUrlrewriteId())) . '\')',
00165 'class' => 'scalable delete',
00166 'level' => -1
00167 ));
00168 }
00169 $this->_addButton('save', array(
00170 'label' => Mage::helper('adminhtml')->__('Save'),
00171 'onclick' => 'editForm.submit()',
00172 'class' => 'save',
00173 'level' => -1
00174 ));
00175
00176 // update back button link
00177 $params = array();
00178 $suffix = '';
00179 $action = '';
00180 if (!$this->getUrlrewriteId()) {
00181 $action = 'edit';
00182 if ($this->getProductId()) {
00183 $suffix = 'category';
00184 $params['product'] = $this->getProductId();
00185 }
00186 elseif ($this->getCategoryId()) {
00187 $suffix = 'category';
00188 }
00189 }
00190 $this->_updateButton('back', 'onclick', 'setLocation(\'' . Mage::helper('adminhtml')->getUrl('*/*/' . $action, $params) . $suffix . '\')');
00191
00192 return $this;
00193 }
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 public function getButtonsHtml($area = null)
00204 {
00205 if (null === $this->_buttonsHtml) {
00206 $this->_buttonsHtml = parent::getButtonsHtml();
00207 foreach ($this->_children as $alias => $child) {
00208 if (false !== strpos($alias, '_button')) {
00209 $this->unsetChild($alias);
00210 }
00211 }
00212 }
00213 return $this->_buttonsHtml;
00214 }
00215
00216
00217
00218
00219
00220
00221 public function getUrlrewriteId()
00222 {
00223 return Mage::registry('current_urlrewrite')->getId();
00224 }
00225
00226
00227
00228
00229
00230
00231 public function getProductId()
00232 {
00233 return Mage::registry('current_product')->getId();
00234 }
00235
00236
00237
00238
00239
00240
00241 public function getCategoryId()
00242 {
00243 return Mage::registry('current_category')->getId();
00244 }
00245
00246
00247
00248
00249
00250
00251
00252 public function isMode($mode)
00253 {
00254 return $this->getRequest()->has($mode);
00255 }
00256
00257
00258
00259
00260
00261
00262
00263
00264 public function updateModeLayout($mode = null)
00265 {
00266 if (!$mode) {
00267 $modes = array_keys(Mage::getBlockSingleton('adminhtml/urlrewrite_selector')->getModes());
00268 $mode = array_shift($modes);
00269 }
00270
00271 // edit form for new custom urlrewrite
00272 if ('id' === $mode) {
00273 $this->_setFormChild();
00274 }
00275 // products grid
00276 elseif ('product' === $mode) {
00277 $this->setChild('products_grid', $this->getLayout()->createBlock('adminhtml/urlrewrite_product_grid'));
00278 }
00279 // categories tree
00280 elseif ('category' === $mode) {
00281 $this->setChild('categories_tree', $this->getLayout()->createBlock('adminhtml/urlrewrite_category_tree'));
00282 }
00283 return $this;
00284 }
00285 }