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_GoogleBase_Block_Adminhtml_Types_Edit_Attributes extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element
35: {
36: public function __construct()
37: {
38: $this->setTemplate('googlebase/types/edit/attributes.phtml');
39: }
40:
41: protected function _prepareLayout()
42: {
43: $this->setChild('add_button',
44: $this->getLayout()->createBlock('adminhtml/widget_button')
45: ->setData(array(
46: 'label' => Mage::helper('googlebase')->__('Add New Attribute'),
47: 'class' => 'add',
48: 'id' => 'add_new_attribute',
49: 'on_click' => 'gBaseAttribute.add()'
50: ))
51: );
52: $this->setChild('delete_button',
53: $this->getLayout()->createBlock('adminhtml/widget_button')
54: ->setData(array(
55: 'label' => Mage::helper('googlebase')->__('Remove'),
56: 'class' => 'delete delete-product-option',
57: 'on_click' => 'gBaseAttribute.remove(event)'
58: ))
59: );
60:
61: parent::_prepareLayout();
62: }
63:
64: public function getFieldId()
65: {
66: return 'gbase_attribute';
67: }
68:
69: public function getFieldName ()
70: {
71: return 'attributes';
72: }
73:
74: public function getGbaseAttributesSelectHtml()
75: {
76: $options = array('' => $this->__('Custom attribute, no mapping'));
77:
78: $attributes = Mage::getModel('googlebase/service_feed')
79: ->getAttributes($this->getGbaseItemtype(), $this->getTargetCountry());
80: foreach ($attributes as $attr) {
81: $options[$attr->getId()] = $attr->getName();
82: }
83:
84: $select = $this->getLayout()->createBlock('adminhtml/html_select')
85: ->setId($this->getFieldId() . '_{{index}}_gattribute')
86: ->setName($this->getFieldName() . '[{{index}}][gbase_attribute]')
87: ->setOptions($options);
88: return $select->getHtml();
89: }
90:
91: 92: 93: 94: 95: 96:
97: public function getAttributesSelectHtml($escapeJsQuotes = false)
98: {
99: $select = $this->getLayout()->createBlock('adminhtml/html_select')
100: ->setId($this->getFieldId() . '_{{index}}_attribute')
101: ->setName($this->getFieldName() . '[{{index}}][attribute_id]')
102: ->setOptions($this->_getAttributes($this->getAttributeSetId(), $escapeJsQuotes));
103: return $select->getHtml();
104: }
105:
106: public function getAddButtonHtml()
107: {
108: return $this->getChildHtml('add_button');
109: }
110:
111: public function getDeleteButtonHtml()
112: {
113: return $this->getChildHtml('delete_button');
114: }
115:
116: 117: 118: 119: 120: 121: 122: 123:
124: public function _getAttributes($setId, $escapeJsQuotes = false)
125: {
126: $attributes = Mage::getModel('googlebase/attribute')->getAllowedAttributes($setId);
127: $result = array();
128:
129: foreach ($attributes as $attribute) {
130:
131: $result[$attribute->getAttributeId()] = $escapeJsQuotes ? $this->jsQuoteEscape($attribute->getFrontendLabel()) : $attribute->getFrontendLabel();
132: }
133: return $result;
134: }
135:
136: protected function _toJson($data)
137: {
138: return Mage::helper('core')->jsonEncode($data);
139: }
140: }
141: