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>Base class for operating in Magento admin Grids</p>
35: *
36: * @author matishalmann
37: */
38: class Eabi_Livehandler_Model_Adminhtml_Gridmanager extends Eabi_Livehandler_Model_Abstract {
39:
40: protected $_actionButtons = array();
41: //put your code here
42: public function _construct() {
43: parent::_construct();
44: $this->_init('eabi_livehandler/adminhtml_gridmanager');
45: }
46:
47: /**
48: * <p>Adds action button to top right of the grid or its edit view.</p>
49: * @param string $id buttons HTML id attribute
50: * @param string $title buttons printed label
51: * @param string $onclick buttons HTML onclick attribute
52: * @return Eabi_Livehandler_Model_Adminhtml_Gridmanager
53: */
54: public function addActionButton($id, $title, $onclick) {
55: $this->_actionButtons[$id] = array(
56: 'title' => $title,
57: 'onclick' => $onclick,
58: );
59: return $this;
60: }
61:
62: /**
63: * <p>Removes previusly entered actionbutton by its HTML id</p>
64: * @param string $id buttons HTML id attribute
65: * @return Eabi_Livehandler_Model_Adminhtml_Gridmanager
66: */
67: public function removeActionButton($id) {
68: if (isset($this->_actionButtons[$id])) {
69: unset($this->_actionButtons[$id]);
70: }
71: return $this;
72: }
73:
74: /**
75: * Encodes input to JSON
76: * @param mixed $input
77: * @return string
78: */
79: protected function _encode($input) {
80: return json_encode($input);
81:
82: }
83:
84: /**
85: * <p>Renders javascript, which adds declared action buttons to the top right of the page next to others.</p>
86: * @return string
87: */
88: public function getJs() {
89: $js = '';
90:
91: foreach ($this->_actionButtons as $id => $actionButton) {
92: $onclick = json_encode($actionButton['onclick']);
93: $title = json_encode($actionButton['title']);
94: $js .= <<<EOT
95: var button_{$id} = new Element('button');
96: button_{$id}.writeAttribute('id', '{$id}');
97: button_{$id}.writeAttribute('type', 'button');
98: button_{$id}.writeAttribute('class', 'scalable');
99: button_{$id}.writeAttribute('onclick', {$onclick});
100: button_{$id}.update('<span>' + {$title} + '</span>');
101:
102: $$('.form-buttons').first().insert(button_{$id}, { position: 'bottom'});
103:
104: EOT;
105: }
106:
107: $js .= $this->_getAdditionalJs($js);
108:
109: return $js;
110: }
111:
112: /**
113: * <p>Subclasses should add their javascript by overriding this function</p>
114: * @param string $currentJs currently generated javascript so far
115: * @return string resulting javascript
116: */
117: protected function _getAdditionalJs($currentJs) {
118: return '';
119: }
120:
121:
122: /**
123: * <p>This function is called, when this class outputs javascript and ajax data is sent to its generated URL.</p>
124: * <p>Contained POST parameters are passed as assoc array</p>
125: * @param array $postData
126: * @return array
127: */
128: public function service($postData) {
129: return array();
130: }
131: }
132:
133: