Since: 1.0
Author: Kartik Visweswaran (kartikv2@gmail.com)
Inheritance: extends kartik\base\AssetBundle
Beispiel #1
0
 /**
  * @inheritdoc
  */
 protected function initDefaultButtons()
 {
     if (!isset($this->buttons['view'])) {
         $this->buttons['view'] = function ($url) {
             $options = $this->viewOptions;
             $title = Yii::t('kvgrid', 'View');
             $icon = '<span class="glyphicon glyphicon-eye-open"></span>';
             $label = ArrayHelper::remove($options, 'label', $this->_isDropdown ? $icon . ' ' . $title : $icon);
             $options = array_replace_recursive(['title' => $title, 'data-pjax' => '0'], $options);
             if ($this->_isDropdown) {
                 $options['tabindex'] = '-1';
                 return '<li>' . Html::a($label, $url, $options) . '</li>' . PHP_EOL;
             } else {
                 return Html::a($label, $url, $options);
             }
         };
     }
     if (!isset($this->buttons['update'])) {
         $this->buttons['update'] = function ($url) {
             $options = $this->updateOptions;
             $title = Yii::t('kvgrid', 'Update');
             $icon = '<span class="glyphicon glyphicon-pencil"></span>';
             $label = ArrayHelper::remove($options, 'label', $this->_isDropdown ? $icon . ' ' . $title : $icon);
             $options = array_replace_recursive(['title' => $title, 'data-pjax' => '0'], $options);
             if ($this->_isDropdown) {
                 $options['tabindex'] = '-1';
                 return '<li>' . Html::a($label, $url, $options) . '</li>' . PHP_EOL;
             } else {
                 return Html::a($label, $url, $options);
             }
         };
     }
     if (!isset($this->buttons['delete'])) {
         $this->buttons['delete'] = function ($url) {
             $options = $this->deleteOptions;
             $title = Yii::t('kvgrid', 'Delete');
             $icon = '<span class="glyphicon glyphicon-trash"></span>';
             $label = ArrayHelper::remove($options, 'label', $this->_isDropdown ? $icon . ' ' . $title : $icon);
             $msg = ArrayHelper::remove($options, 'message', Yii::t('kvgrid', 'Are you sure to delete this item?'));
             $defaults = ['title' => $title, 'data-pjax' => 'false'];
             $pjax = $this->grid->pjax ? true : false;
             $pjaxContainer = $pjax ? $this->grid->pjaxSettings['options']['id'] : '';
             if ($pjax) {
                 $defaults['data-pjax-container'] = $pjaxContainer;
             }
             $options = array_replace_recursive($defaults, $options);
             $css = $this->grid->options['id'] . '-action-del';
             Html::addCssClass($options, $css);
             $view = $this->grid->getView();
             $delOpts = Json::encode(['css' => $css, 'pjax' => $pjax, 'pjaxContainer' => $pjaxContainer, 'lib' => ArrayHelper::getValue($this->grid->krajeeDialogSettings, 'libName', 'krajeeDialog'), 'msg' => $msg]);
             ActionColumnAsset::register($view);
             $js = "kvActionDelete({$delOpts});";
             $view->registerJs($js);
             $this->initPjax($js);
             if ($this->_isDropdown) {
                 $options['tabindex'] = '-1';
                 return '<li>' . Html::a($label, $url, $options) . '</li>' . PHP_EOL;
             } else {
                 return Html::a($label, $url, $options);
             }
         };
     }
 }