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 abstract class Mage_Adminhtml_Block_Widget_Grid_Massaction_Abstract extends Mage_Adminhtml_Block_Widget
00035 {
00036
00037
00038
00039
00040
00041 protected $_items = array();
00042
00043 public function __construct()
00044 {
00045 parent::__construct();
00046 $this->setTemplate('widget/grid/massaction.phtml');
00047 $this->setErrorText(Mage::helper('catalog')->jsQuoteEscape(Mage::helper('catalog')->__('Please select items')));
00048 }
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 public function addItem($itemId, array $item)
00066 {
00067 $this->_items[$itemId] = $this->getLayout()->createBlock('adminhtml/widget_grid_massaction_item')
00068 ->setData($item)
00069 ->setMassaction($this)
00070 ->setId($itemId);
00071
00072 if($this->_items[$itemId]->getAdditional()) {
00073 $this->_items[$itemId]->setAdditionalActionBlock($this->_items[$itemId]->getAdditional());
00074 $this->_items[$itemId]->unsAdditional();
00075 }
00076
00077 return $this;
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 public function getItem($itemId)
00087 {
00088 if(isset($this->_items[$itemId])) {
00089 return $this->_items[$itemId];
00090 }
00091
00092 return null;
00093 }
00094
00095
00096
00097
00098
00099
00100 public function getItems()
00101 {
00102 return $this->_items;
00103 }
00104
00105
00106
00107
00108
00109
00110 public function getItemsJson()
00111 {
00112 $result = array();
00113 foreach ($this->getItems() as $itemId=>$item) {
00114 $result[$itemId] = $item->toArray();
00115 }
00116
00117 return Zend_Json::encode($result);
00118 }
00119
00120
00121
00122
00123
00124
00125 public function getCount()
00126 {
00127 return sizeof($this->_items);
00128 }
00129
00130
00131
00132
00133
00134
00135 public function isAvailable()
00136 {
00137 return $this->getCount() > 0 && $this->getParentBlock()->getMassactionIdField();
00138 }
00139
00140
00141
00142
00143
00144
00145 public function getFormFieldName()
00146 {
00147 return ($this->getData('form_field_name') ? $this->getData('form_field_name') : 'massaction');
00148 }
00149
00150
00151
00152
00153
00154
00155 public function getFormFieldNameInternal()
00156 {
00157 return 'internal_' . $this->getFormFieldName();
00158 }
00159
00160
00161
00162
00163
00164
00165 public function getJsObjectName()
00166 {
00167 return $this->getHtmlId() . 'JsObject';
00168 }
00169
00170
00171
00172
00173
00174
00175 public function getGridJsObjectName()
00176 {
00177 return $this->getParentBlock()->getJsObjectName();
00178 }
00179
00180
00181
00182
00183
00184
00185 public function getSelectedJson()
00186 {
00187 if($selected = $this->getRequest()->getParam($this->getFormFieldNameInternal())) {
00188 $selected = explode(',', $selected);
00189 return join(',', $selected);
00190
00191 } else {
00192 return '';
00193
00194 }
00195 }
00196
00197
00198
00199
00200
00201
00202 public function getSelected()
00203 {
00204 if($selected = $this->getRequest()->getParam($this->getFormFieldNameInternal())) {
00205 $selected = explode(',', $selected);
00206 return $selected;
00207 } else {
00208 return array();
00209 }
00210 }
00211
00212
00213
00214
00215
00216
00217 public function getApplyButtonHtml()
00218 {
00219 return $this->getButtonHtml($this->__('Submit'), $this->getJsObjectName() . ".apply()");
00220 }
00221
00222 public function getJavaScript()
00223 {
00224 return "
00225 var {$this->getJsObjectName()} = new varienGridMassaction('{$this->getHtmlId()}', {$this->getGridJsObjectName()}, '{$this->getSelectedJson()}', '{$this->getFormFieldNameInternal()}', '{$this->getFormFieldName()}');
00226 {$this->getJsObjectName()}.setItems({$this->getItemsJson()});
00227 {$this->getJsObjectName()}.setGridIds('{$this->getGridIdsJson()}');
00228 ". ($this->getUseAjax() ? "{$this->getJsObjectName()}.setUseAjax(true);" : '') .
00229 "{$this->getJsObjectName()}.errorText = '{$this->getErrorText()}';";
00230 }
00231
00232 public function getGridIdsJson()
00233 {
00234 $gridIds = $this->getParentBlock()->getCollection()->getAllIds();
00235
00236 if(!empty($gridIds)) {
00237 return join(",", $gridIds);
00238
00239 }
00240 return '';
00241
00242 }
00243
00244 public function getHtmlId()
00245 {
00246 return $this->getParentBlock()->getHtmlId() . '_massaction';
00247 }
00248
00249 }
00250