| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- <?php
- namespace Dcat\Admin\Grid\Concerns;
- trait Options
- {
- /**
- * Options for grid.
- *
- * @var array
- */
- protected $options = [
- 'show_pagination' => true,
- 'show_filter' => true,
- 'show_exporter' => false,
- 'show_export_all' => true,
- 'show_actions' => true,
- 'show_quick_edit_button' => true,
- 'show_edit_button' => true,
- 'show_view_button' => true,
- 'show_delete_button' => true,
- 'show_row_selector' => true,
- 'show_create_btn' => true,
- 'show_quick_create_btn' => true,
- 'show_bordered' => false,
- 'show_toolbar' => true,
- 'row_selector_style' => 'primary',
- 'row_selector_circle' => true,
- 'row_selector_clicktr' => false,
- 'row_selector_label_name' => null,
- 'row_selector_bg' => 'var(--20)',
- 'export_limit' => 50000,
- 'dialog_form_area' => ['700px', '670px'],
- 'table_header_style' => 'table-header-default',
- ];
- /**
- * Get or set option for grid.
- *
- * @param string $key
- * @param mixed $value
- *
- * @return $this|mixed
- */
- public function option($key, $value = null)
- {
- if (is_null($value)) {
- return $this->options[$key];
- }
- $this->options[$key] = $value;
- return $this;
- }
- /**
- * Disable grid pagination.
- *
- * @return $this
- */
- public function disablePagination(bool $disable = true)
- {
- $this->model->usePaginate(!$disable);
- return $this->option('show_pagination', !$disable);
- }
- /**
- * Show grid pagination.
- *
- * @param bool $val
- * @return $this
- */
- public function showPagination(bool $val = true)
- {
- return $this->disablePagination(!$val);
- }
- /**
- * 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 row selector.
- *
- * @return $this
- */
- public function disableRowSelector(bool $disable = true)
- {
- $this->tools->disableBatchActions($disable);
- return $this->option('show_row_selector', !$disable);
- }
- /**
- * Show row selector.
- *
- * @return $this
- */
- public function showRowSelector(bool $val = true)
- {
- return $this->disableRowSelector(!$val);
- }
- /**
- * Disable grid filter.
- *
- * @return $this
- */
- public function disableFilter(bool $disable = true)
- {
- // $this->tools->disableFilterButton($disable);
- $this->filter->disableCollapse($disable);
- return $this->option('show_filter', !$disable);
- }
- /**
- * Show grid filter.
- *
- * @param bool $val
- * @return $this
- */
- public function showFilter(bool $val = true)
- {
- return $this->disableFilter(!$val);
- }
- /**
- * Disable refresh button.
- *
- * @param bool $disable
- * @return $this
- */
- public function disableRefreshButton(bool $disable = true)
- {
- $this->tools->disableRefreshButton($disable);
- return $this;
- }
- /**
- * Show refresh button.
- *
- * @param bool $val
- * @return $this
- */
- public function showRefreshButton(bool $val = true)
- {
- return $this->disableRefreshButton(!$val);
- }
- /**
- * Disable filter button.
- *
- * @param bool $disable
- * @return $this
- */
- public function disableFilterButton(bool $disable = true)
- {
- $this->tools->disableFilterButton($disable);
- return $this;
- }
- /**
- * Show filter button.
- *
- * @param bool $val
- * @return $this
- */
- public function showFilterButton(bool $val = true)
- {
- return $this->disableFilterButton(!$val);
- }
- /**
- * Disable batch actions.
- *
- * @param bool $disable
- * @return $this
- */
- public function disableBatchActions(bool $disable = true)
- {
- $this->tools->disableBatchActions($disable);
- return $this;
- }
- /**
- * Show batch actions.
- *
- * @param bool $val
- * @return $this
- */
- public function showBatchActions(bool $val = true)
- {
- return $this->disableBatchActions(!$val);
- }
- /**
- * Disable batch delete.
- *
- * @param bool $disable
- * @return $this
- */
- public function disableBatchDelete(bool $disable = true)
- {
- $this->tools->batch(function ($action) use ($disable) {
- $action->disableDelete($disable);
- });
- return $this;
- }
- /**
- * Show batch delete.
- *
- * @param bool $val
- * @return $this
- */
- public function showBatchDelete(bool $val = true)
- {
- return $this->disableBatchDelete(!$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);
- }
- /**
- * Disable export.
- *
- * @return $this
- */
- public function disableExport(bool $disable = true)
- {
- return $this->option('show_exporter', !$disable);
- }
- /**
- * Show export button.
- *
- * @return $this
- */
- public function showExport(bool $val = true)
- {
- return $this->disableExport(!$val);
- }
- /**
- * Disable export all.
- *
- * @return $this
- */
- public function disableExportAll(bool $disable = true)
- {
- return $this->option('show_export_all', !$disable);
- }
- /**
- * Show export all option.
- *
- * @return $this
- */
- public function showExportAll(bool $val = true)
- {
- return $this->disableExportAll(!$val);
- }
- /**
- * Remove create button on grid.
- *
- * @return $this
- */
- public function disableCreateButton(bool $disable = true)
- {
- return $this->option('show_create_btn', !$disable);
- }
- /**
- * Show create button.
- *
- * @return $this
- */
- public function showCreateButton(bool $val = true)
- {
- return $this->disableCreateButton(!$val);
- }
- public function disableQuickCreateButton(bool $disable = true)
- {
- return $this->option('show_quick_create_btn', !$disable);
- }
- public function showQuickCreateButton(bool $val = true)
- {
- return $this->disableQuickCreateButton(!$val);
- }
- public function disableToolbar(bool $val = true)
- {
- return $this->option('show_toolbar', !$val);
- }
- public function showToolbar(bool $val = true)
- {
- return $this->disableToolbar(!$val);
- }
- }
|