1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * New attribute panel on product edit page
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes_Create extends Mage_Adminhtml_Block_Widget_Button
35: {
36: /**
37: * Config of create new attribute
38: *
39: * @var Varien_Object
40: */
41: protected $_config = null;
42:
43: /**
44: * Retrive config of new attribute creation
45: *
46: * @return Varien_Object
47: */
48: public function getConfig()
49: {
50: if (is_null($this->_config)) {
51: $this->_config = new Varien_Object();
52: }
53:
54: return $this->_config;
55: }
56:
57: protected function _beforeToHtml()
58: {
59: $this->setId('create_attribute_' . $this->getConfig()->getGroupId())
60: ->setOnClick($this->getJsObjectName() . '.create();')
61: ->setType('button')
62: ->setClass('add')
63: ->setLabel(Mage::helper('adminhtml')->__('Create New Attribute'));
64:
65: $this->getConfig()
66: ->setUrl($this->getUrl(
67: '*/catalog_product_attribute/new',
68: array(
69: 'group' => $this->getConfig()->getGroupId(),
70: 'tab' => $this->getConfig()->getTabId(),
71: 'store' => $this->getConfig()->getStoreId(),
72: 'product' => $this->getConfig()->getProductId(),
73: 'set' => $this->getConfig()->getAttributeSetId(),
74: 'type' => $this->getConfig()->getTypeId(),
75: 'popup' => 1
76: )
77: ));
78:
79: return parent::_beforeToHtml();
80: }
81:
82: protected function _toHtml()
83: {
84: $this->setCanShow(true);
85: Mage::dispatchEvent('adminhtml_catalog_product_edit_tab_attributes_create_html_before', array('block' => $this));
86: if (!$this->getCanShow()) {
87: return '';
88: }
89:
90: $html = parent::_toHtml();
91: $html .= Mage::helper('adminhtml/js')->getScript(
92: "var {$this->getJsObjectName()} = new Product.Attributes('{$this->getId()}');\n"
93: . "{$this->getJsObjectName()}.setConfig(" . Mage::helper('core')->jsonEncode($this->getConfig()->getData()) . ");\n"
94: );
95:
96: return $html;
97: }
98:
99: public function getJsObjectName()
100: {
101: return $this->getId() . 'JsObject';
102: }
103: } // Class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes_Create End
104: