Used to set buttons to use Glyphicons instead of the defaults images.
Inheritance: extends CButtonColumn
 protected function initDefaultButtons()
 {
     parent::initDefaultButtons();
     /* Кнопка просмотра на фронте */
     if ($this->frontViewButtonLabel === null) {
         $this->frontViewButtonLabel = Yii::t('zii', 'View');
     }
     $button = array('label' => $this->frontViewButtonLabel, 'url' => $this->frontViewButtonUrl ?: function ($data) {
         try {
             return $data->{$this->frontViewGetUrlMethodName}();
         } catch (\Exception $e) {
             return null;
         }
     }, 'options' => $this->frontViewButtonOptions, 'icon' => $this->frontViewButtonIcon);
     if (isset($this->buttons['front_view'])) {
         $this->buttons['front_view'] = array_merge($button, $this->buttons['front_view']);
     } else {
         /* показывать кнопку только если задали ей свой url, или модель имеет метод для получения url*/
         $button['visible'] = function ($row, $data) {
             // todo: найти нормальный способ узнавания есть ли у модели метод
             try {
                 return $this->frontViewButtonUrl || method_exists($data, $this->frontViewGetUrlMethodName) || (bool) $data->{$this->frontViewGetUrlMethodName}();
             } catch (\Exception $e) {
                 return false;
             }
         };
         $this->buttons['front_view'] = $button;
     }
 }
 protected function renderDataCellContent($row, $data)
 {
     ob_start();
     parent::renderDataCellContent($row, $data);
     $cellContent = ob_get_contents();
     ob_clean();
     ob_end_clean();
     if ($this->id === false && $this->dataAttr === false) {
         echo $cellContent;
     } else {
         if (isset($this->id) || isset($this->dataAttr)) {
             $containerHtmlOptions = array();
             if (is_string($this->id)) {
                 $id = $this->evaluateExpression($this->id, array('row' => $row, 'data' => $data));
                 $containerHtmlOptions['id'] = $id;
             }
             if (is_array($this->dataAttr)) {
                 foreach ($this->dataAttr as $name => $value) {
                     $containerHtmlOptions[$name] = $this->evaluateExpression($value, array('row' => $row, 'data' => $data));
                 }
             }
             echo CHtml::tag('div', $containerHtmlOptions, $cellContent, true);
         }
     }
 }
 /**
  * Initializes the default buttons (view, update and delete).
  */
 protected function initDefaultButtons()
 {
     parent::initDefaultButtons();
     /**
      * add custom with msgbox instead
      */
     $this->buttons['delete']['click'] = strtr($this->buttons['delete']['click'], array('yiiGridView' => 'yiiJsonGridView'));
 }
Beispiel #4
0
 protected function renderButton($id, $button, $row, $data)
 {
     $options = isset($button['options']) ? $button['options'] : array();
     if (isset($options['visible']) && !$this->evaluateExpression($options['visible'], array('row' => $row, 'data' => $data))) {
         return;
     }
     return parent::renderButton($id, $button, $row, $data);
 }
 /**
  *### .initDefaultButtons()
  *
  * Initializes the default buttons (view, update and delete).
  */
 protected function initDefaultButtons()
 {
     parent::initDefaultButtons();
     if ($this->viewButtonType !== false && !isset($this->buttons['view']['type'])) {
         $this->buttons['view']['type'] = $this->viewButtonType;
     }
     if ($this->updateButtonType !== false && !isset($this->buttons['update']['type'])) {
         $this->buttons['update']['type'] = $this->updateButtonType;
     }
     if ($this->deleteButtonType !== false && !isset($this->buttons['delete']['type'])) {
         $this->buttons['delete']['type'] = $this->deleteButtonType;
     }
 }
 protected function initDefaultButtons()
 {
     $this->template = '{audit} {view} {update} {delete}';
     parent::initDefaultButtons();
     if ($this->auditButtonLabel === null) {
         $this->auditButtonLabel = Yii::t("AudittrailModule.main", "Auditrail");
     }
     $button = array('label' => $this->auditButtonLabel, 'url' => $this->auditButtonUrl, 'imageUrl' => $this->auditButtonImageUrl, 'options' => $this->auditButtonOptions, 'icon' => $this->auditButtonIcon);
     if (isset($this->buttons['audit'])) {
         $this->buttons['audit'] = array_merge($button, $this->buttons['audit']);
     } else {
         $this->buttons['audit'] = $button;
     }
 }
Beispiel #7
0
    /**
     *
     */
    protected function initDefaultButtons()
    {
        parent::initDefaultButtons();
        $this->template = '<div class="btn-group">' . $this->template . '</div>';
        if ($this->frontViewButtonLabel === null) {
            $this->frontViewButtonLabel = Yii::t('zii', 'View');
        }
        if ($this->frontViewButtonUrl) {
            $this->buttons['front_view'] = ['label' => $this->frontViewButtonLabel, 'url' => $this->frontViewButtonUrl, 'options' => $this->frontViewButtonOptions, 'icon' => $this->frontViewButtonIcon];
        } else {
            $this->buttons['front_view'] = ['visible' => function () {
                return false;
            }];
        }
        if (is_string($this->deleteConfirmation)) {
            $confirmation = "if(!confirm(" . \CJavaScript::encode($this->deleteConfirmation) . ")) return false;";
        } else {
            $confirmation = '';
        }
        if (Yii::app()->request->enableCsrfValidation) {
            $csrfTokenName = Yii::app()->getRequest()->csrfTokenName;
            $csrfToken = Yii::app()->getRequest()->csrfToken;
            $csrf = "\n\t\tdata:{ '{$csrfTokenName}':'{$csrfToken}' },";
        } else {
            $csrf = '';
        }
        if ($this->afterDelete === null) {
            $this->afterDelete = 'function(){}';
        }
        $this->buttons['delete']['click'] = <<<EOD
function() {
\t{$confirmation}
\tvar th = this,
\t\tafterDelete = {$this->afterDelete};
\tjQuery('#{$this->grid->id}').yiiGridView('update', {
\t\ttype: 'POST',
\t\turl: jQuery(this).attr('href'),{$csrf}
\t\tsuccess: function(data) {
\t\t\tjQuery('#{$this->grid->id}').yiiGridView('update', {url: document.location.href });
\t\t\tafterDelete(th, true, data);
\t\t},
\t\terror: function(XHR) {
\t\t\treturn afterDelete(th, false, XHR);
\t\t}
\t});
\treturn false;
}
EOD;
    }
 /**
  *
  */
 protected function initDefaultButtons()
 {
     parent::initDefaultButtons();
     $this->template = '<div class="btn-group">' . $this->template . '</div>';
     if ($this->frontViewButtonLabel === null) {
         $this->frontViewButtonLabel = Yii::t('zii', 'View');
     }
     if ($this->frontViewButtonUrl) {
         $this->buttons['front_view'] = ['label' => $this->frontViewButtonLabel, 'url' => $this->frontViewButtonUrl, 'options' => $this->frontViewButtonOptions, 'icon' => $this->frontViewButtonIcon];
     } else {
         $this->buttons['front_view'] = ['visible' => function () {
             return false;
         }];
     }
 }