Modal.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Dcat\Admin\Grid\Displayers;
  3. use Dcat\Admin\Support\Helper;
  4. class Modal extends AbstractDisplayer
  5. {
  6. protected $title;
  7. public function title(string $title)
  8. {
  9. $this->title = $title;
  10. }
  11. public function display($callback = null)
  12. {
  13. $title = $this->trans('title');
  14. if (func_num_args() == 2) {
  15. [$title, $callback] = func_get_args();
  16. }
  17. $html = $this->value;
  18. if ($callback instanceof \Closure) {
  19. $html = Helper::render(
  20. $callback->call($this->row, $this)
  21. );
  22. }
  23. $title = $this->title ?: $title;
  24. $key = $this->grid->getName().$this->key();
  25. return <<<EOT
  26. <span class="grid-expand" data-toggle="modal" data-target="#grid-modal-{$key}">
  27. <a href="javascript:void(0)"><i class="fa fa-clone"></i>&nbsp;&nbsp;{$this->value}</a>
  28. </span>
  29. <div class="modal fade" id="grid-modal-{$key}" tabindex="-1" role="dialog">
  30. <div class="modal-dialog modal-lg" role="document">
  31. <div class="modal-content">
  32. <div class="modal-header">
  33. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  34. <h4 class="modal-title">{$title}</h4>
  35. </div>
  36. <div class="modal-body">
  37. {$html}
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. EOT;
  43. }
  44. }