00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Text
00035 {
00036
00037
00038
00039
00040
00041
00042
00043 public function render(Varien_Object $row)
00044 {
00045 $actions = $this->getColumn()->getActions();
00046 if ( empty($actions) || !is_array($actions) ) {
00047 return ' ';
00048 }
00049
00050 if(sizeof($actions)==1 && !$this->getColumn()->getNoLink()) {
00051 foreach ($actions as $action){
00052 if ( is_array($action) ) {
00053 return $this->_toLinkHtml($action, $row);
00054 }
00055 }
00056 }
00057
00058 $out = '<select class="action-select" onchange="varienGridAction.execute(this);">'
00059 . '<option value=""></option>';
00060 $i = 0;
00061 foreach ($actions as $action){
00062 $i++;
00063 if ( is_array($action) ) {
00064 $out .= $this->_toOptionHtml($action, $row);
00065 }
00066 }
00067 $out .= '</select>';
00068 return $out;
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078 protected function _toOptionHtml($action, Varien_Object $row)
00079 {
00080 $actionAttributes = new Varien_Object();
00081
00082 $actionCaption = '';
00083 $this->_transformActionData($action, $actionCaption, $row);
00084
00085 $htmlAttibutes = array('value'=>$this->htmlEscape(Zend_Json::encode($action)));
00086 $actionAttributes->setData($htmlAttibutes);
00087 return '<option ' . $actionAttributes->serialize() . '>' . $actionCaption . '</option>';
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097 protected function _toLinkHtml($action, Varien_Object $row)
00098 {
00099 $actionAttributes = new Varien_Object();
00100
00101 $actionCaption = '';
00102 $this->_transformActionData($action, $actionCaption, $row);
00103
00104 if(isset($action['confirm'])) {
00105 $action['onclick'] = 'return window.confirm(\''
00106 . addslashes($this->htmlEscape($action['confirm']))
00107 . '\')';
00108 unset($action['confirm']);
00109 }
00110
00111 $actionAttributes->setData($action);
00112 return '<a ' . $actionAttributes->serialize() . '>' . $actionCaption . '</a>';
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 protected function _transformActionData(&$action, &$actionCaption, Varien_Object $row)
00124 {
00125 foreach ( $action as $attibute => $value ) {
00126 if(isset($action[$attibute]) && !is_array($action[$attibute])) {
00127 $this->getColumn()->setFormat($action[$attibute]);
00128 $action[$attibute] = parent::render($row);
00129 } else {
00130 $this->getColumn()->setFormat(null);
00131 }
00132
00133 switch ($attibute) {
00134 case 'caption':
00135 $actionCaption = $action['caption'];
00136 unset($action['caption']);
00137 break;
00138
00139 case 'url':
00140 if(is_array($action['url'])) {
00141 $params = array($action['field']=>$this->_getValue($row));
00142 if(isset($action['url']['params'])) {
00143 $params = array_merge($action['url']['params'], $params);
00144 }
00145 $action['href'] = $this->getUrl($action['url']['base'], $params);
00146 unset($action['field']);
00147 } else {
00148 $action['href'] = $action['url'];
00149 }
00150 unset($action['url']);
00151 break;
00152
00153 case 'popup':
00154 $action['onclick'] = 'popWin(this.href, \'windth=800,height=700,resizable=1,scrollbars=1\');return false;';
00155 break;
00156
00157 }
00158 }
00159 return $this;
00160 }
00161 }