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_GoogleBase_Block_Adminhtml_Types_Edit_Attributes extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element
00035 {
00036 public function __construct()
00037 {
00038 $this->setTemplate('googlebase/types/edit/attributes.phtml');
00039 }
00040
00041 protected function _prepareLayout()
00042 {
00043 $this->setChild('add_button',
00044 $this->getLayout()->createBlock('adminhtml/widget_button')
00045 ->setData(array(
00046 'label' => Mage::helper('googlebase')->__('Add New Attribute'),
00047 'class' => 'add',
00048 'id' => 'add_new_attribute',
00049 'on_click' => 'gBaseAttribute.add()'
00050 ))
00051 );
00052 $this->setChild('delete_button',
00053 $this->getLayout()->createBlock('adminhtml/widget_button')
00054 ->setData(array(
00055 'label' => Mage::helper('googlebase')->__('Remove'),
00056 'class' => 'delete delete-product-option',
00057 'on_click' => 'gBaseAttribute.remove(event)'
00058 ))
00059 );
00060
00061 parent::_prepareLayout();
00062 }
00063
00064 public function getFieldId()
00065 {
00066 return 'gbase_attribute';
00067 }
00068
00069 public function getFieldName ()
00070 {
00071 return 'attributes';
00072 }
00073
00074 public function getGbaseAttributesSelectHtml()
00075 {
00076 $options = array('' => $this->__('Custom attribute, no mapping'));
00077
00078 $attributes = Mage::getModel('googlebase/service_feed')
00079 ->getAttributes($this->getGbaseItemtype(), $this->getTargetCountry());
00080 foreach ($attributes as $attr) {
00081 $options[$attr->getId()] = $attr->getName();
00082 }
00083
00084 $select = $this->getLayout()->createBlock('adminhtml/html_select')
00085 ->setId($this->getFieldId().'_{{index}}_gattribute')
00086 ->setName($this->getFieldName().'[{{index}}][gbase_attribute]')
00087 ->setOptions($options);
00088 return $select->getHtml();
00089 }
00090
00091
00092
00093
00094
00095
00096
00097 public function getAttributesSelectHtml($escapeJsQuotes = false)
00098 {
00099 $select = $this->getLayout()->createBlock('adminhtml/html_select')
00100 ->setId($this->getFieldId().'_{{index}}_attribute')
00101 ->setName($this->getFieldName().'[{{index}}][attribute_id]')
00102 ->setOptions($this->_getAttributes($this->getAttributeSetId(), $escapeJsQuotes));
00103 return $select->getHtml();
00104 }
00105
00106 public function getAddButtonHtml()
00107 {
00108 return $this->getChildHtml('add_button');
00109 }
00110
00111 public function getDeleteButtonHtml()
00112 {
00113 return $this->getChildHtml('delete_button');
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 public function _getAttributes($setId, $escapeJsQuotes = false)
00125 {
00126 $attributes = Mage::getModel('googlebase/attribute')->getAllowedAttributes($setId);
00127 $result = array();
00128
00129 foreach ($attributes as $attribute) {
00130
00131 $result[$attribute->getAttributeId()] = $escapeJsQuotes ? $this->jsQuoteEscape($attribute->getFrontendLabel()) : $attribute->getFrontendLabel();
00132 }
00133 return $result;
00134 }
00135
00136 protected function _toJson($data)
00137 {
00138 return Zend_Json::encode($data);
00139 }
00140 }