Editable.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Dcat\Admin\Grid\Displayers;
  3. use Dcat\Admin\Admin;
  4. use Dcat\Admin\Support\Helper;
  5. abstract class Editable extends AbstractDisplayer
  6. {
  7. protected $type;
  8. protected $view;
  9. protected $options = [
  10. // 是否刷新页面
  11. 'refresh' => false,
  12. ];
  13. public function display($options = [])
  14. {
  15. if (is_bool($options)) {
  16. $options = ['refresh' => $options];
  17. }
  18. $this->options = array_merge($this->options, $options);
  19. return admin_view($this->view, array_merge($this->variables(), $this->defaultOptions() + $this->options));
  20. }
  21. protected function defaultOptions()
  22. {
  23. return [];
  24. }
  25. public function variables()
  26. {
  27. return [
  28. 'key' => $this->getKey(),
  29. 'class' => $this->getSelector(),
  30. 'type' => $this->type,
  31. 'display' => Helper::render($this->value),
  32. 'value' => $this->column->getOriginal(),
  33. 'name' => $this->column->getName(),
  34. 'url' => $this->getUrl(),
  35. ];
  36. }
  37. protected function getSelector()
  38. {
  39. return 'grid-editable-'.$this->type;
  40. }
  41. protected function getUrl()
  42. {
  43. return $this->resource().'/'.$this->getKey();
  44. }
  45. }