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: class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
35: extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
36: {
37:
38: 39: 40: 41: 42: 43:
44: public function render(Varien_Object $row)
45: {
46: $actions = $this->getColumn()->getActions();
47: if ( empty($actions) || !is_array($actions) ) {
48: return ' ';
49: }
50:
51: if(sizeof($actions)==1 && !$this->getColumn()->getNoLink()) {
52: foreach ($actions as $action) {
53: if ( is_array($action) ) {
54: return $this->_toLinkHtml($action, $row);
55: }
56: }
57: }
58:
59: $out = '<select class="action-select" onchange="varienGridAction.execute(this);">'
60: . '<option value=""></option>';
61: $i = 0;
62: foreach ($actions as $action){
63: $i++;
64: if ( is_array($action) ) {
65: $out .= $this->_toOptionHtml($action, $row);
66: }
67: }
68: $out .= '</select>';
69: return $out;
70: }
71:
72: 73: 74: 75: 76: 77: 78:
79: protected function _toOptionHtml($action, Varien_Object $row)
80: {
81: $actionAttributes = new Varien_Object();
82:
83: $actionCaption = '';
84: $this->_transformActionData($action, $actionCaption, $row);
85:
86: $htmlAttibutes = array('value'=>$this->escapeHtml(Mage::helper('core')->jsonEncode($action)));
87: $actionAttributes->setData($htmlAttibutes);
88: return '<option ' . $actionAttributes->serialize() . '>' . $actionCaption . '</option>';
89: }
90:
91: 92: 93: 94: 95: 96: 97:
98: protected function _toLinkHtml($action, Varien_Object $row)
99: {
100: $actionAttributes = new Varien_Object();
101:
102: $actionCaption = '';
103: $this->_transformActionData($action, $actionCaption, $row);
104:
105: if(isset($action['confirm'])) {
106: $action['onclick'] = 'return window.confirm(\''
107: . addslashes($this->escapeHtml($action['confirm']))
108: . '\')';
109: unset($action['confirm']);
110: }
111:
112: $actionAttributes->setData($action);
113: return '<a ' . $actionAttributes->serialize() . '>' . $actionCaption . '</a>';
114: }
115:
116: 117: 118: 119: 120: 121: 122: 123:
124: protected function _transformActionData(&$action, &$actionCaption, Varien_Object $row)
125: {
126: foreach ( $action as $attribute => $value ) {
127: if(isset($action[$attribute]) && !is_array($action[$attribute])) {
128: $this->getColumn()->setFormat($action[$attribute]);
129: $action[$attribute] = parent::render($row);
130: } else {
131: $this->getColumn()->setFormat(null);
132: }
133:
134: switch ($attribute) {
135: case 'caption':
136: $actionCaption = $action['caption'];
137: unset($action['caption']);
138: break;
139:
140: case 'url':
141: if(is_array($action['url'])) {
142: $params = array($action['field']=>$this->_getValue($row));
143: if(isset($action['url']['params'])) {
144: $params = array_merge($action['url']['params'], $params);
145: }
146: $action['href'] = $this->getUrl($action['url']['base'], $params);
147: unset($action['field']);
148: } else {
149: $action['href'] = $action['url'];
150: }
151: unset($action['url']);
152: break;
153:
154: case 'popup':
155: $action['onclick'] =
156: 'popWin(this.href,\'_blank\',\'width=800,height=700,resizable=1,scrollbars=1\');return false;';
157: break;
158:
159: }
160: }
161: return $this;
162: }
163: }
164: