10 Yii::import(
'zii.widgets.grid.CCheckBoxColumn');
11 Yii::import(
'booster.widgets.TbButton');
80 public function getId($autoGenerate =
true) {
82 if ($this->_id !== null) {
84 }
else if ($autoGenerate) {
85 return $this->_id =
'egw' . self::$_counter++;
125 $this->align = $this->align ==
'left' ?
'pull-left' :
'pull-right';
137 if (!is_array($this->checkBoxColumnConfig)) {
138 $this->checkBoxColumnConfig = array();
141 if (empty($this->grid->columns)) {
145 $columns = $this->grid->columns;
147 foreach ($columns as $idx => $column) {
148 if (!is_array($column) || !isset($column[
'class'])) {
151 if (preg_match(
'/ccheckboxcolumn/i', $column[
'class'])) {
152 if (isset($column[
'checkBoxHtmlOptions']) && isset($column[
'checkBoxHtmlOptions'][
'name'])) {
153 $this->columnName = strtr(
154 $column[
'checkBoxHtmlOptions'][
'name'],
155 array(
'[' =>
"\\[",
']' =>
"\\]")
158 $this->columnName = $this->grid->id .
'_c' . $idx .
'\[\]';
175 if (empty($this->columnName) || empty($this->actionButtons))
178 $this->buttons = array();
179 foreach ($this->actionButtons as $action)
190 if ($this->buttons === array())
195 array(
'id' => $this->
getId(),
'style' =>
'position:relative',
'class' => $this->align)
198 foreach ($this->buttons as $actionButton)
201 echo
'<div style="position:absolute;top:0;left:0;height:100%;width:100%;display:block;" class="bulk-actions-blocker"></div>';
203 echo CHtml::closeTag(
'div');
215 $id = $this->grid->id;
217 $js .=
"$.fn.yiiGridView.initBulkActions('{$id}');";
219 foreach ($this->events as $buttonId => $handler) {
221 $(document).on('click','#{$buttonId}', function() {
222 var checked = $.fn.yiiGridView.getCheckedRowsIds('$id');
223 if (!checked.length) {
224 alert('".$this->noCheckedMessage.
"');
228 if ($.isFunction(fn)){ fn(checked); } \n
233 Yii::app()->getClientScript()->registerScript(__CLASS__ .
'#' . $this->
getId(), $js);
245 if (isset($actionButton[
'htmlOptions'][
'class']))
246 $actionButton[
'htmlOptions'][
'class'] .=
' disabled bulk-actions-btn';
248 $actionButton[
'htmlOptions'][
'class'] =
'disabled bulk-actions-btn';
251 if (isset($actionButton[
'click'])) {
252 $action = CJavaScript::encode($actionButton[
'click']);
253 unset($actionButton[
'click']);
256 $button = Yii::createComponent($actionButton);
261 if ($action !== null) {
262 $this->events[$button->id] = $action;
273 $dataProvider = $this->grid->dataProvider;
276 if (!isset($this->checkBoxColumnConfig[
'name'])) {
278 if ($dataProvider instanceof CActiveDataProvider) {
280 if (is_string($dataProvider->modelClass)) {
281 $modelClass = $dataProvider->modelClass;
282 $model = CActiveRecord::model($modelClass);
284 $model = $dataProvider->modelClass;
287 $table = $model->tableSchema;
288 if (is_string($table->primaryKey)) {
290 }
else if (is_array($table->primaryKey)) {
294 if ($dataProvider instanceof CArrayDataProvider || $dataProvider instanceof CSqlDataProvider) {
299 $column = CMap::mergeArray(
301 'class' =>
'CCheckBoxColumn',
304 $this->checkBoxColumnConfig
308 array_unshift($this->grid->columns, $column);
309 $this->columnName = $this->grid->id .
'_c0\[\]';
320 if (!isset($action[
'id'])) {
321 throw new CException(Yii::t(
323 'Each bulk action button should have its "id" attribute set to ensure its functionality among ajax updates'
327 $buttonConfig = array(
328 'class' =>
'booster.widgets.TbButton',
329 'id' => $action[
'id'],
331 'context' => isset($action[
'context']) ? $action[
'context'] :
'',
333 'icon' => isset($action[
'icon']) ? $action[
'icon'] : null,
334 'label' => isset($action[
'label']) ? $action[
'label'] : null,
335 'url' => isset($action[
'url']) ? $action[
'url'] : null,
336 'active' => isset($action[
'active']) ? $action[
'active'] :
false,
337 'items' => isset($action[
'items']) ? $action[
'items'] : array(),
338 'ajaxOptions' => isset($action[
'ajaxOptions']) ? $action[
'ajaxOptions'] : array(),
339 'htmlOptions' => isset($action[
'htmlOptions']) ? $action[
'htmlOptions'] : array(),
340 'encodeLabel' => isset($action[
'encodeLabel']) ? $action[
'encodeLabel'] :
true,
341 'click' => isset($action[
'click']) ? $action[
'click'] :
false
343 return $buttonConfig;