1: <?php
2: /*
3:
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * or OpenGPL v3 license (GNU Public License V3.0)
9: * that is bundled with this package in the file LICENSE.txt.
10: * It is also available through the world-wide-web at this URL:
11: * http://opensource.org/licenses/osl-3.0.php
12: * or
13: * http://www.gnu.org/licenses/gpl-3.0.txt
14: * If you did not receive a copy of the license and are unable to
15: * obtain it through the world-wide-web, please send an email
16: * to info@e-abi.ee so we can send you a copy immediately.
17: *
18: * DISCLAIMER
19: *
20: * Do not edit or add to this file if you wish to upgrade this module to newer
21: * versions in the future.
22: *
23: * @category Eabi
24: * @package Eabi_Dpd
25: * @copyright Copyright (c) 2014 Aktsiamaailm LLC (http://en.e-abi.ee/)
26: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27: * @license http://www.gnu.org/licenses/gpl-3.0.txt GNU Public License V3.0
28: * @author Matis Halmann
29: *
30:
31: */
32:
33: /**
34: * <p>Renders button, which allows to delete old instance of Eabi_Livehandler from app/code/local folder in Magento admin > System > Configuration > Eabi Livehandler > Admin Order Grid Helper configuration menu, if such old instance exists</p>
35: * <p>Use following system.xml struct to include this button:</p>
36: * <pre>
37: * <removal translate="">
38: <label></label>
39: <frontend_model>eabi_postoffice/adminhtml_config_form_field_remove</frontend_model>
40: <sort_order>1000001</sort_order>
41: <show_in_default>1</show_in_default>
42: <show_in_website>0</show_in_website>
43: <show_in_store>0</show_in_store>
44: </removal>
45:
46: * </pre>
47: * @author Matis
48: */
49: class Eabi_Livehandler_Block_Adminhtml_Config_Form_Field_Remove extends Mage_Adminhtml_Block_System_Config_Form_Field {
50:
51: protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
52: $divId = $element->getId();
53: $helper = Mage::helper('eabi_livehandler');
54: $res = '';
55: $dirName = Mage::getBaseDir('code') . '/local/Eabi/Livehandler';
56: if (is_dir($dirName) && file_exists($dirName.'/etc/config.xml')) {
57: $res .= <<<HTML
58: <button class="scalable" id="{$divId}_button" type="button" onclick="{$divId}make_request(); return false;">{$helper->__('Delete instance of this module from %s folder', 'app/code/local')}</button>
59:
60: HTML;
61: $res .= <<<HTML
62: <script type="text/javascript">
63: //<![CDATA[
64:
65: function {$divId}make_request(actionName) {
66: 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))});
67:
68: if (confirmR) {
69: new Ajax.Request(
70: '{$this->getUrl('eabi_livehandler/adminhtml_remove/remove', array())}',
71: {
72: method: 'post',
73: asynchronous: true,
74: parameters: {"remove": "true"},
75: onSuccess: function(transport) {
76: var json = transport.responseText.evalJSON(true);
77: if (json['status'] && json['status'] == 'success') {
78: alert({$this->_toJson($helper->__('Folder %s deleted!', $dirName))});
79: \$({$this->_toJson($divId . '_button')}).hide();
80: } else {
81: alert({$this->_toJson($helper->__('Folder %s delete failed!', $dirName))});
82: }
83: },
84: onFailure: function(transport) {
85: alert(transport.responseText);
86: }
87: });
88: }
89:
90: }
91: //]]>
92: </script>
93:
94: HTML;
95:
96: }
97: return $res;
98: }
99:
100: private function _toJson($input) {
101: return json_encode($input);
102: }
103:
104: }
105:
106: