Options.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <?php
  2. namespace Dcat\Admin\Grid\Concerns;
  3. trait Options
  4. {
  5. /**
  6. * Options for grid.
  7. *
  8. * @var array
  9. */
  10. protected $options = [
  11. 'show_pagination' => true,
  12. 'show_filter' => true,
  13. 'show_exporter' => false,
  14. 'show_export_all' => true,
  15. 'show_actions' => true,
  16. 'show_quick_edit_button' => true,
  17. 'show_edit_button' => true,
  18. 'show_view_button' => true,
  19. 'show_delete_button' => true,
  20. 'show_row_selector' => true,
  21. 'show_create_btn' => true,
  22. 'show_quick_create_btn' => true,
  23. 'show_bordered' => false,
  24. 'show_toolbar' => true,
  25. 'row_selector_style' => 'primary',
  26. 'row_selector_circle' => true,
  27. 'row_selector_clicktr' => false,
  28. 'row_selector_label_name' => null,
  29. 'row_selector_bg' => 'var(--20)',
  30. 'export_limit' => 50000,
  31. 'dialog_form_area' => ['700px', '670px'],
  32. 'table_header_style' => 'table-header-default',
  33. ];
  34. /**
  35. * Get or set option for grid.
  36. *
  37. * @param string $key
  38. * @param mixed $value
  39. *
  40. * @return $this|mixed
  41. */
  42. public function option($key, $value = null)
  43. {
  44. if (is_null($value)) {
  45. return $this->options[$key];
  46. }
  47. $this->options[$key] = $value;
  48. return $this;
  49. }
  50. /**
  51. * Disable grid pagination.
  52. *
  53. * @return $this
  54. */
  55. public function disablePagination(bool $disable = true)
  56. {
  57. $this->model->usePaginate(!$disable);
  58. return $this->option('show_pagination', !$disable);
  59. }
  60. /**
  61. * Show grid pagination.
  62. *
  63. * @param bool $val
  64. * @return $this
  65. */
  66. public function showPagination(bool $val = true)
  67. {
  68. return $this->disablePagination(!$val);
  69. }
  70. /**
  71. * Disable all actions.
  72. *
  73. * @return $this
  74. */
  75. public function disableActions(bool $disable = true)
  76. {
  77. return $this->option('show_actions', !$disable);
  78. }
  79. /**
  80. * Show all actions.
  81. *
  82. * @return $this
  83. */
  84. public function showActions(bool $val = true)
  85. {
  86. return $this->disableActions(!$val);
  87. }
  88. /**
  89. * Disable row selector.
  90. *
  91. * @return $this
  92. */
  93. public function disableRowSelector(bool $disable = true)
  94. {
  95. $this->tools->disableBatchActions($disable);
  96. return $this->option('show_row_selector', !$disable);
  97. }
  98. /**
  99. * Show row selector.
  100. *
  101. * @return $this
  102. */
  103. public function showRowSelector(bool $val = true)
  104. {
  105. return $this->disableRowSelector(!$val);
  106. }
  107. /**
  108. * Disable grid filter.
  109. *
  110. * @return $this
  111. */
  112. public function disableFilter(bool $disable = true)
  113. {
  114. // $this->tools->disableFilterButton($disable);
  115. $this->filter->disableCollapse($disable);
  116. return $this->option('show_filter', !$disable);
  117. }
  118. /**
  119. * Show grid filter.
  120. *
  121. * @param bool $val
  122. * @return $this
  123. */
  124. public function showFilter(bool $val = true)
  125. {
  126. return $this->disableFilter(!$val);
  127. }
  128. /**
  129. * Disable refresh button.
  130. *
  131. * @param bool $disable
  132. * @return $this
  133. */
  134. public function disableRefreshButton(bool $disable = true)
  135. {
  136. $this->tools->disableRefreshButton($disable);
  137. return $this;
  138. }
  139. /**
  140. * Show refresh button.
  141. *
  142. * @param bool $val
  143. * @return $this
  144. */
  145. public function showRefreshButton(bool $val = true)
  146. {
  147. return $this->disableRefreshButton(!$val);
  148. }
  149. /**
  150. * Disable filter button.
  151. *
  152. * @param bool $disable
  153. * @return $this
  154. */
  155. public function disableFilterButton(bool $disable = true)
  156. {
  157. $this->tools->disableFilterButton($disable);
  158. return $this;
  159. }
  160. /**
  161. * Show filter button.
  162. *
  163. * @param bool $val
  164. * @return $this
  165. */
  166. public function showFilterButton(bool $val = true)
  167. {
  168. return $this->disableFilterButton(!$val);
  169. }
  170. /**
  171. * Disable batch actions.
  172. *
  173. * @param bool $disable
  174. * @return $this
  175. */
  176. public function disableBatchActions(bool $disable = true)
  177. {
  178. $this->tools->disableBatchActions($disable);
  179. return $this;
  180. }
  181. /**
  182. * Show batch actions.
  183. *
  184. * @param bool $val
  185. * @return $this
  186. */
  187. public function showBatchActions(bool $val = true)
  188. {
  189. return $this->disableBatchActions(!$val);
  190. }
  191. /**
  192. * Disable batch delete.
  193. *
  194. * @param bool $disable
  195. * @return $this
  196. */
  197. public function disableBatchDelete(bool $disable = true)
  198. {
  199. $this->tools->batch(function ($action) use ($disable) {
  200. $action->disableDelete($disable);
  201. });
  202. return $this;
  203. }
  204. /**
  205. * Show batch delete.
  206. *
  207. * @param bool $val
  208. * @return $this
  209. */
  210. public function showBatchDelete(bool $val = true)
  211. {
  212. return $this->disableBatchDelete(!$val);
  213. }
  214. /**
  215. * Disable edit.
  216. *
  217. * @param bool $disable
  218. * @return $this
  219. */
  220. public function disableEditButton(bool $disable = true)
  221. {
  222. $this->options['show_edit_button'] = !$disable;
  223. return $this;
  224. }
  225. /**
  226. * Show edit.
  227. *
  228. * @param bool $val
  229. * @return $this
  230. */
  231. public function showEditButton(bool $val = true)
  232. {
  233. return $this->disableEditButton(!$val);
  234. }
  235. /**
  236. * Disable quick edit.
  237. *
  238. * @return $this.
  239. */
  240. public function disableQuickEditButton(bool $disable = true)
  241. {
  242. $this->options['show_quick_edit_button'] = !$disable;
  243. return $this;
  244. }
  245. /**
  246. * Show quick edit button.
  247. *
  248. * @return $this.
  249. */
  250. public function showQuickEditButton(bool $val = true)
  251. {
  252. return $this->disableQuickEditButton(!$val);
  253. }
  254. /**
  255. * Disable view action.
  256. *
  257. * @param bool $disable
  258. * @return $this
  259. */
  260. public function disableViewButton(bool $disable = true)
  261. {
  262. $this->options['show_view_button'] = !$disable;
  263. return $this;
  264. }
  265. /**
  266. * Show view action.
  267. *
  268. * @param bool $disable
  269. * @return $this
  270. */
  271. public function showViewButton(bool $val = true)
  272. {
  273. return $this->disableViewButton(!$val);
  274. }
  275. /**
  276. * Disable delete.
  277. *
  278. * @param bool $disable
  279. * @return $this
  280. */
  281. public function disableDeleteButton(bool $disable = true)
  282. {
  283. $this->options['show_delete_button'] = !$disable;
  284. return $this;
  285. }
  286. /**
  287. * Show delete button.
  288. *
  289. * @param bool $disable
  290. * @return $this
  291. */
  292. public function showDeleteButton(bool $val = true)
  293. {
  294. return $this->disableDeleteButton(!$val);
  295. }
  296. /**
  297. * Disable export.
  298. *
  299. * @return $this
  300. */
  301. public function disableExport(bool $disable = true)
  302. {
  303. return $this->option('show_exporter', !$disable);
  304. }
  305. /**
  306. * Show export button.
  307. *
  308. * @return $this
  309. */
  310. public function showExport(bool $val = true)
  311. {
  312. return $this->disableExport(!$val);
  313. }
  314. /**
  315. * Disable export all.
  316. *
  317. * @return $this
  318. */
  319. public function disableExportAll(bool $disable = true)
  320. {
  321. return $this->option('show_export_all', !$disable);
  322. }
  323. /**
  324. * Show export all option.
  325. *
  326. * @return $this
  327. */
  328. public function showExportAll(bool $val = true)
  329. {
  330. return $this->disableExportAll(!$val);
  331. }
  332. /**
  333. * Remove create button on grid.
  334. *
  335. * @return $this
  336. */
  337. public function disableCreateButton(bool $disable = true)
  338. {
  339. return $this->option('show_create_btn', !$disable);
  340. }
  341. /**
  342. * Show create button.
  343. *
  344. * @return $this
  345. */
  346. public function showCreateButton(bool $val = true)
  347. {
  348. return $this->disableCreateButton(!$val);
  349. }
  350. public function disableQuickCreateButton(bool $disable = true)
  351. {
  352. return $this->option('show_quick_create_btn', !$disable);
  353. }
  354. public function showQuickCreateButton(bool $val = true)
  355. {
  356. return $this->disableQuickCreateButton(!$val);
  357. }
  358. public function disableToolbar(bool $val = true)
  359. {
  360. return $this->option('show_toolbar', !$val);
  361. }
  362. public function showToolbar(bool $val = true)
  363. {
  364. return $this->disableToolbar(!$val);
  365. }
  366. }