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: 35: 36: 37:
38: class Eabi_Postoffice_Block_Adminhtml_Config_Form_Field_Remove extends Mage_Adminhtml_Block_System_Config_Form_Field {
39:
40: protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
41: $divId = $element->getId();
42: $helper = Mage::helper('eabi_livehandler');
43: $res = '';
44: $dirName = Mage::getBaseDir('code') . '/local/Eabi/Postoffice';
45: if (is_dir($dirName) && file_exists($dirName.'/etc/config.xml')) {
46: $res .= <<<HTML
47: <button class="scalable" id="{$divId}_button" type="button" onclick="{$divId}make_request(); return false;">{$this->_getOfficeHelper()->__('Delete instance of this module from %s folder', 'app/code/local')}</button>
48:
49: HTML;
50: $res .= <<<HTML
51: <script type="text/javascript">
52: //<![CDATA[
53:
54: function {$divId}make_request(actionName) {
55: var confirmR = confirm({$this->_toJson($helper->__('Most probably you have older version of this module in the system. Do you want to remove the instance of this module from %s folder?', $dirName))});
56:
57: if (confirmR) {
58: new Ajax.Request(
59: '{$this->getUrl('eabi_postoffice/adminhtml_postoffice/remove', array())}',
60: {
61: method: 'post',
62: asynchronous: true,
63: parameters: {"remove": "true"},
64: onSuccess: function(transport) {
65: var json = transport.responseText.evalJSON(true);
66: if (json['status'] && json['status'] == 'success') {
67: alert({$this->_toJson($this->_getOfficeHelper()->__('Folder %s deleted!', $dirName))});
68: \$({$this->_toJson($divId . '_button')}).hide();
69: } else {
70: alert({$this->_toJson($this->_getOfficeHelper()->__('Folder %s delete failed!', $dirName))});
71: }
72: },
73: onFailure: function(transport) {
74: alert(transport.responseText);
75: }
76: });
77: }
78:
79: }
80: //]]>
81: </script>
82:
83: HTML;
84:
85: }
86: return $res;
87: }
88:
89: private function _toJson($input) {
90: return json_encode($input);
91: }
92:
93: 94: 95: 96:
97: protected function _getOfficeHelper() {
98: return Mage::helper('eabi_postoffice');
99: }
100:
101:
102:
103: }
104:
105: