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_Catalog_Category_Tab_General extends Mage_Adminhtml_Block_Catalog_Form
00035 {
00036
00037 protected $_category;
00038
00039 public function __construct()
00040 {
00041 parent::__construct();
00042 $this->setShowGlobalIcon(true);
00043 }
00044
00045 public function getCategory()
00046 {
00047 if (!$this->_category) {
00048 $this->_category = Mage::registry('category');
00049 }
00050 return $this->_category;
00051 }
00052
00053 public function _prepareLayout()
00054 {
00055 parent::_prepareLayout();
00056 $form = new Varien_Data_Form();
00057 $form->setHtmlIdPrefix('_general');
00058 $form->setDataObject($this->getCategory());
00059
00060 $fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('catalog')->__('General Information')));
00061
00062 if (!$this->getCategory()->getId()) {
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 if ($this->getRequest()->getParam('parent')) {
00074 $fieldset->addField('path', 'hidden', array(
00075 'name' => 'path',
00076 'value' => $this->getRequest()->getParam('parent')
00077 ));
00078 } else {
00079 $storeId = (int) $this->getRequest()->getParam('store');
00080 $fieldset->addField('path', 'hidden', array(
00081 'name' => 'path',
00082 'value' => 1
00083 ));
00084 }
00085 } else {
00086 $fieldset->addField('id', 'hidden', array(
00087 'name' => 'id',
00088 'value' => $this->getCategory()->getId()
00089 ));
00090 $fieldset->addField('path', 'hidden', array(
00091 'name' => 'path',
00092 'value' => $this->getCategory()->getPath()
00093 ));
00094 }
00095
00096 $this->_setFieldset($this->getCategory()->getAttributes(true), $fieldset);
00097
00098 if ($this->getCategory()->getId()) {
00099 if ($this->getCategory()->getLevel() == 1) {
00100 $fieldset->removeField('url_key');
00101 $fieldset->addField('url_key', 'hidden', array(
00102 'name' => 'url_key',
00103 'value' => $this->getCategory()->getUrlKey()
00104 ));
00105 }
00106 }
00107
00108 $form->addValues($this->getCategory()->getData());
00109
00110 $form->setFieldNameSuffix('general');
00111 $this->setForm($form);
00112 }
00113
00114 protected function _getAdditionalElementTypes()
00115 {
00116 return array(
00117 'image' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_category_helper_image')
00118 );
00119 }
00120
00121 protected function _getParentCategoryOptions($node=null, &$options=array())
00122 {
00123 if (is_null($node)) {
00124 $node = $this->getRoot();
00125 }
00126
00127 if ($node) {
00128 $options[] = array(
00129 'value' => $node->getPathId(),
00130 'label' => str_repeat(' ', max(0, 3*($node->getLevel()))) . $this->htmlEscape($node->getName()),
00131 );
00132
00133 foreach ($node->getChildren() as $child) {
00134 $this->_getParentCategoryOptions($child, $options);
00135 }
00136 }
00137 return $options;
00138 }
00139
00140 }
00141