InitAppearance.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Admin\Actions\Grid;
  3. use App\Admin\Forms\InquiryAssignment as InquiryAssignmentForm;
  4. use App\Admin\Repositories\DistAdminDistributor;
  5. use App\Admin\Repositories\DistAppearance;
  6. use Dcat\Admin\Grid\BatchAction;
  7. use Dcat\Admin\Widgets\Modal;
  8. use Illuminate\Http\Request;
  9. class InitAppearance extends BatchAction
  10. {
  11. /**
  12. * @return string
  13. */
  14. protected $title = '';
  15. public function __construct()
  16. {
  17. $this->title = admin_trans_label('init_appearance');
  18. }
  19. /**
  20. * 确认弹窗,如果不需要则返回空即可
  21. *
  22. * @return array|string|void
  23. */
  24. public function confirm()
  25. {
  26. // 只显示标题
  27. // return '您确定要发送新的提醒消息吗?';
  28. // 显示标题和内容
  29. return ['The data will be restored to its original version. Do you want to continue?', ''];
  30. }
  31. /**
  32. * 处理请求
  33. * 如果你的类中包含了此方法,则点击按钮后会自动向后端发起ajax请求,并且会通过此方法处理请求逻辑
  34. *
  35. * @param Request $request
  36. */
  37. public function handle(Request $request)
  38. {
  39. $keys = $request->input('_key');
  40. if (is_array($keys) && count($keys) > 0) {
  41. if (count($keys) > 1) {
  42. return $this->response()->error('Only one row at a time')->refresh();
  43. }
  44. $baseDistId = config('dictionary.base_dist_id');
  45. if ($baseDistId == $keys[0]) {
  46. return $this->response()->error('The base distribution cannot be initialized')->refresh();
  47. }
  48. //初始化
  49. $row = DistAdminDistributor::getOneById($keys[0]);
  50. if ($row) {
  51. DistAppearance::initTheme($row->appearance_id, $row->id);
  52. return $this->response()->success('Success')->refresh();
  53. }
  54. return $this->response()->error('Data does not exist')->refresh();
  55. } else {
  56. return $this->response()->error('No data selected!')->refresh();
  57. }
  58. }
  59. /**
  60. * 设置动作发起请求前的回调函数,返回false可以中断请求.
  61. *
  62. * @return string
  63. */
  64. public function getModalScript(){
  65. $warning = __('No data selected!');
  66. return <<<JS
  67. var key = {$this->getSelectedKeysScript()}
  68. $('#inquiryIds').val(key);
  69. JS;
  70. }
  71. public function getSelectedKeysScript()
  72. {
  73. return "Dcat.grid.selected('{$this->parent->getName()}')";
  74. }
  75. }