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_Customer_Edit_Tab_Addresses extends Mage_Adminhtml_Block_Widget_Form
00035 {
00036 public function __construct()
00037 {
00038 parent::__construct();
00039 $this->setTemplate('customer/tab/addresses.phtml');
00040 }
00041
00042 public function getRegionsUrl()
00043 {
00044 return $this->getUrl('*/json/countryRegion');
00045 }
00046
00047 protected function _prepareLayout()
00048 {
00049 $this->setChild('delete_button',
00050 $this->getLayout()->createBlock('adminhtml/widget_button')
00051 ->setData(array(
00052 'label' => Mage::helper('customer')->__('Delete Address'),
00053 'name' => 'delete_address',
00054 'disabled' => $this->isReadonly(),
00055 'class' => 'delete' . ($this->isReadonly() ? ' disabled' : '')
00056 ))
00057 );
00058 $this->setChild('add_address_button',
00059 $this->getLayout()->createBlock('adminhtml/widget_button')
00060 ->setData(array(
00061 'label' => Mage::helper('customer')->__('Add New Address'),
00062 'id' => 'add_address_button',
00063 'name' => 'add_address_button',
00064 'disabled' => $this->isReadonly(),
00065 'class' => 'add' . ($this->isReadonly() ? ' disabled' : ''),
00066 'onclick'=> 'customerAddresses.addNewAddress()'
00067 ))
00068 );
00069 $this->setChild('cancel_button',
00070 $this->getLayout()->createBlock('adminhtml/widget_button')
00071 ->setData(array(
00072 'label' => Mage::helper('customer')->__('Cancel'),
00073 'id' => 'cancel_add_address'.$this->getTemplatePrefix(),
00074 'name' => 'cancel_address',
00075 'class' => 'cancel delete-address' . ($this->isReadonly() ? ' disabled' : ''),
00076 'disabled' => $this->isReadonly(),
00077 'onclick'=> 'customerAddresses.cancelAdd(this)',
00078 ))
00079 );
00080 return parent::_prepareLayout();
00081 }
00082
00083
00084
00085
00086
00087
00088 public function isReadonly()
00089 {
00090 $customer = Mage::registry('current_customer');
00091 return $customer->isReadonly();
00092 }
00093
00094 public function getDeleteButtonHtml()
00095 {
00096 return $this->getChildHtml('delete_button');
00097 }
00098
00099 public function initForm()
00100 {
00101 $customer = Mage::registry('current_customer');
00102
00103 $form = new Varien_Data_Form();
00104 $fieldset = $form->addFieldset('address_fieldset', array('legend'=>Mage::helper('customer')->__("Edit Customer's Address")));
00105
00106 $addressModel = Mage::getModel('customer/address');
00107
00108 $this->_setFieldset($addressModel->getAttributes(), $fieldset);
00109
00110 if ($streetElement = $form->getElement('street')) {
00111 $streetElement->setLineCount(Mage::helper('customer/address')->getStreetLines());
00112 }
00113
00114 if ($regionElement = $form->getElement('region')) {
00115 $regionElement->setRenderer(Mage::getModel('adminhtml/customer_renderer_region'));
00116 }
00117
00118 if ($regionElement = $form->getElement('region_id')) {
00119 $regionElement->setNoDisplay(true);
00120 }
00121
00122 if ($country = $form->getElement('country_id')) {
00123 $country->addClass('countries');
00124 }
00125
00126 if ($this->isReadonly()) {
00127 foreach ($addressModel->getAttributes() as $attribute) {
00128 $element = $form->getElement($attribute->getAttributeCode());
00129 if ($element) {
00130 $element->setReadonly(true, true);
00131 }
00132 }
00133 }
00134
00135 $addressCollection = $customer->getAddresses();
00136 $this->assign('customer', $customer);
00137 $this->assign('addressCollection', $addressCollection);
00138 $this->setForm($form);
00139
00140 return $this;
00141 }
00142
00143 public function getCancelButtonHtml()
00144 {
00145 return $this->getChildHtml('cancel_button');
00146 }
00147
00148 public function getAddNewButtonHtml()
00149 {
00150 return $this->getChildHtml('add_address_button');
00151 }
00152
00153 public function getTemplatePrefix()
00154 {
00155 return '_template_';
00156 }
00157 }