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 action buttons, which are displayed at Magento Administrators Sales Order Grid.</p>
35: * <p>Buttons are shown when clicking on 'Show Order Info' button.</p>
36: * <p>Buttons can have onclick handler and desired action bound to it, when it is clicked.</p>
37: *
38: * @author Matis
39: */
40: abstract class Eabi_Livehandler_Model_Action_Abstract {
41: /**
42: * <p>Buttons are sorted by position in ascending order</p>
43: * @var int
44: */
45: protected $_position;
46:
47: /**
48: * <p>name of the button relative to eabi_livehandler/action_<button-name> or full magento model name</p>
49: * @var string
50: */
51: protected $_code;
52: protected $_label;
53: protected $_onClick;
54: protected $_longOnClick;
55: protected $_cssClass;
56:
57: /**
58: * Decides whether the button can be displayed for the current order
59: * @return bool true, when this button can be displayed for current order.
60: */
61: abstract public function canDisplay(Mage_Sales_Model_Order $order);
62:
63: /**
64: * <p>This function is called when current button is clicked and data along with it is sent to server.</p>
65: * <p>Returned data should be in following format:</p>
66: * <pre>
67: $result = array(
68: 'messages' => array of messages, which are displayed as success messages to the user,
69: 'errors' => array of error, which are displayed as errors to the user,
70: 'needs_reload' => when set to true, whole page is reloaded when Order Manager is closed,
71: 'is_action_error' => when set to true whole page is reloaded immediately,
72: );
73: * </pre>
74: * @param Mage_Sales_Model_Order $order current order that is being displayed
75: * @param array $params assoc array of POST params
76: * @return bool|array when action failed, return false, otherwise return array.
77: */
78: abstract public function performDesiredAction(Mage_Sales_Model_Order $order, array $params);
79:
80: /**
81: *
82: * <p>Buttons are sorted by position in ascending order</p>
83: * @param int $position desired position
84: */
85: public function setPosition($position) {
86: $this->_position = $position;
87: }
88:
89: /**
90: * <p>Buttons are sorted by position in ascending order</p>
91: * @return int current position
92: */
93: public function getPosition() {
94: return $this->_position;
95: }
96:
97:
98: /**
99: * <p>name of the button relative to eabi_livehandler/action_<button-name> or full magento model name</p>
100: * @return string
101: */
102: public function getCode() {
103: return $this->_code;
104: }
105:
106: /**
107: * <p>Label printed on the action button</p>
108: * @return string
109: */
110: public function getLabel() {
111: return $this->_label;
112: }
113:
114: /**
115: * <p>Gets the onclick parameter for the current action button</p>
116: * @return string javascript
117: */
118: public function getOnClick() {
119: return $this->_onClick;
120: }
121:
122:
123: /**
124: * <p>Gets the class parameter for the current action button</p>
125: * @return string
126: */
127: public function getCssClass() {
128: return $this->_cssClass;
129: }
130:
131: /**
132: * <p>Gets the Event.observe('click') javascript for current action button.</p>
133: * @return string javascript
134: */
135: public function getLongOnClick() {
136: return $this->_longOnClick;
137: }
138:
139: /**
140: * <p>Wrapper function for json_encode for usage in heredoc</p>
141: * @param mixed $input
142: * @return string json encoded string
143: */
144: protected function _toJson($input) {
145: return json_encode($input);
146: }
147:
148: }
149:
150: