Ejemplo n.º 1
0
 public function init()
 {
     $this->registerTranslations();
     if (!is_null($this->autoQuery)) {
         $auto = $this->autoQuery->roots();
         if ($this->rootable) {
             $this->query = $auto;
         } else {
             $this->query = $auto->one() ? $auto->one()->children(1) : null;
         }
     }
     if (is_null($this->modelOptions)) {
         $this->modelOptions = ['name' => function ($data) {
             return $this->prepareRow($data);
         }];
     }
     if (count($this->columns) == 1 && !$this->hideButtons) {
         $this->columns['url'] = function ($data) {
             return Url::toRoute([$this->driveController . 'update', 'id' => $data->primaryKey]);
         };
     }
     if (is_null($this->buttons)) {
         $model = new $this->query->modelClass();
         $this->buttons = [['label' => Icon::show('pencil', [], Icon::FA), 'url' => function ($data) {
             return Url::toRoute([$this->driveController . 'update', 'id' => $data->primaryKey]);
         }, 'options' => ['title' => self::t('messages', 'Edit'), 'data-pjax' => 0]], ['label' => Icon::show('lock', [], Icon::FA), 'url' => function ($data) {
             return Url::toRoute([$this->driveController . 'lock', 'id' => $data->primaryKey]);
         }, 'options' => ['title' => self::t('messages', 'Lock'), 'data-method' => 'POST', 'data-pjax' => '0'], 'visible' => function ($data) {
             return $data->hasAttribute('locked') && !$data->locked;
         }], ['label' => Icon::show('unlock', [], Icon::FA), 'url' => function ($data) {
             return Url::toRoute([$this->driveController . 'unlock', 'id' => $data->primaryKey]);
         }, 'options' => ['title' => self::t('messages', 'Unlock'), 'data-method' => 'POST', 'data-pjax' => '0'], 'visible' => function ($data) {
             return $data->hasAttribute('locked') && $data->locked;
         }], ['label' => Icon::show('trash', [], Icon::FA), 'url' => function ($data) {
             return Url::toRoute([$this->driveController . 'delete', 'id' => $data->primaryKey]);
         }, 'options' => ['title' => self::t('messages', 'To trash'), 'data-method' => 'POST', 'data-pjax' => '0', 'data-confirm' => "Вы действительно хотите удалить этот элемент?"], 'visible' => function ($data) {
             return $data->hasAttribute('removed') && !$data->removed;
         }], ['label' => Icon::show('share-square-o', [], Icon::FA), 'url' => function ($data) {
             return Url::toRoute([$this->driveController . 'restore', 'id' => $data->primaryKey]);
         }, 'options' => ['title' => self::t('messages', 'Restore')], 'visible' => function ($data) {
             return $data->hasAttribute('removed') && $data->removed;
         }], ['label' => Icon::show('remove', [], Icon::FA), 'url' => function ($data) {
             return Url::toRoute([$this->driveController . 'delete', 'id' => $data->primaryKey]);
         }, 'options' => ['title' => self::t('messages', 'Delete'), 'data-method' => 'POST', 'data-pjax' => '0', 'data-confirm' => "Вы действительно хотите удалить этот элемент?"], 'visible' => function ($data) {
             if ($data->hasAttribute('removed')) {
                 if (is_bool($data->removed)) {
                     return $data->removed;
                 }
                 return !is_null($data->removed);
             }
             return true;
         }]];
     }
     $this->options['class'] = 'nestable' . (isset($this->options['class']) ? ' ' . $this->options['class'] : '');
     parent::init();
 }