| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- namespace Dcat\Admin\Grid\Concerns;
- use Closure;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Grid\Displayers;
- trait HasActions
- {
- /**
- * Callback for grid actions.
- *
- * @var Closure[]
- */
- protected $actionsCallback = [];
- /**
- * Actions column display class.
- *
- * @var string
- */
- protected $actionsClass;
- /**
- * @param string $actionClass
- *
- * @return $this
- */
- public function setActionClass(string $actionClass)
- {
- if (is_subclass_of($actionClass, Grid\Displayers\Actions::class)) {
- $this->actionsClass = $actionClass;
- }
- return $this;
- }
- /**
- * Get action display class.
- *
- * @return \Illuminate\Config\Repository|mixed|string
- */
- public function getActionClass()
- {
- if ($this->actionsClass) {
- return $this->actionsClass;
- }
- if ($class = config('admin.grid.grid_action_class')) {
- return $class;
- }
- return Grid\Displayers\Actions::class;
- }
- /**
- * Set grid action callback.
- *
- * @param Closure $callback
- *
- * @return $this
- */
- public function actions(Closure $callback)
- {
- $this->actionsCallback[] = $callback;
- return $this;
- }
- /**
- * Add `actions` column for grid.
- *
- * @return void
- */
- protected function appendActionsColumn()
- {
- if (!$this->options['show_actions']) {
- return;
- }
- $this->addColumn('__actions__', trans('admin.action'))
- ->displayUsing($this->getActionClass(), [$this->actionsCallback]);
- }
- /**
- * Disable all actions.
- *
- * @return $this
- */
- public function disableActions(bool $disable = true)
- {
- return $this->option('show_actions', !$disable);
- }
- /**
- * Show all actions.
- *
- * @return $this
- */
- public function showActions(bool $val = true)
- {
- return $this->disableActions(!$val);
- }
- /**
- * Disable edit.
- *
- * @param bool $disable
- * @return $this
- */
- public function disableEditButton(bool $disable = true)
- {
- $this->options['show_edit_button'] = !$disable;
- return $this;
- }
- /**
- * Show edit.
- *
- * @param bool $val
- * @return $this
- */
- public function showEditButton(bool $val = true)
- {
- return $this->disableEditButton(!$val);
- }
- /**
- * Disable quick edit.
- *
- * @return $this.
- */
- public function disableQuickEditButton(bool $disable = true)
- {
- $this->options['show_quick_edit_button'] = !$disable;
- return $this;
- }
- /**
- * Show quick edit button.
- *
- * @return $this.
- */
- public function showQuickEditButton(bool $val = true)
- {
- return $this->disableQuickEditButton(!$val);
- }
- /**
- * Disable view action.
- *
- * @param bool $disable
- * @return $this
- */
- public function disableViewButton(bool $disable = true)
- {
- $this->options['show_view_button'] = !$disable;
- return $this;
- }
- /**
- * Show view action.
- *
- * @param bool $disable
- * @return $this
- */
- public function showViewButton(bool $val = true)
- {
- return $this->disableViewButton(!$val);
- }
- /**
- * Disable delete.
- *
- * @param bool $disable
- * @return $this
- */
- public function disableDeleteButton(bool $disable = true)
- {
- $this->options['show_delete_button'] = !$disable;
- return $this;
- }
- /**
- * Show delete button.
- *
- * @param bool $disable
- * @return $this
- */
- public function showDeleteButton(bool $val = true)
- {
- return $this->disableDeleteButton(!$val);
- }
- }
|