RowAction.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace Dcat\Admin\Grid;
  3. use Illuminate\Support\Fluent;
  4. abstract class RowAction extends GridAction
  5. {
  6. /**
  7. * @var Fluent
  8. */
  9. protected $row;
  10. /**
  11. * @var Column
  12. */
  13. protected $column;
  14. /**
  15. * @var string
  16. */
  17. public $selectorPrefix = '.grid-row-action-';
  18. /**
  19. * Get primary key value of current row.
  20. *
  21. * @return mixed
  22. */
  23. public function key()
  24. {
  25. if ($this->row) {
  26. return $this->row->get($this->parent->keyName());
  27. }
  28. return parent::key();
  29. }
  30. /**
  31. * Set row model.
  32. *
  33. * @param mixed $key
  34. *
  35. * @return \Illuminate\Database\Eloquent\Model|mixed
  36. */
  37. public function row($key = null)
  38. {
  39. if (func_num_args() == 0) {
  40. return $this->row;
  41. }
  42. return $this->row->{$key};
  43. }
  44. /**
  45. * Set row model.
  46. *
  47. * @param Fluent $row
  48. *
  49. * @return $this
  50. */
  51. public function setRow($row)
  52. {
  53. $this->row = $row;
  54. return $this;
  55. }
  56. public function getRow()
  57. {
  58. return $this->row;
  59. }
  60. /**
  61. * @param Column $column
  62. *
  63. * @return $this
  64. */
  65. public function setColumn(Column $column)
  66. {
  67. $this->column = $column;
  68. return $this;
  69. }
  70. /**
  71. * @return string
  72. */
  73. public function href()
  74. {
  75. }
  76. /**
  77. * Render row action.
  78. *
  79. * @return string
  80. */
  81. public function html()
  82. {
  83. if (! $href = $this->href()) {
  84. $href = 'javascript:void(0);';
  85. }
  86. $attributes = $this->formatHtmlAttributes();
  87. return sprintf(
  88. "<a data-_key='%s' href='%s' class='%s' {$attributes}>%s</a>",
  89. $this->key(),
  90. $href,
  91. $this->elementClass(),
  92. $this->title()
  93. );
  94. }
  95. }