RowAction.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. protected function getKey()
  24. {
  25. return $this->row->get($this->parent->getKeyName());
  26. }
  27. /**
  28. * Set row model.
  29. *
  30. * @param mixed $key
  31. *
  32. * @return \Illuminate\Database\Eloquent\Model|mixed
  33. */
  34. public function row($key = null)
  35. {
  36. if (func_num_args() == 0) {
  37. return $this->row;
  38. }
  39. return $this->row->{$key};
  40. }
  41. /**
  42. * Set row model.
  43. *
  44. * @param Fluent $row
  45. *
  46. * @return $this
  47. */
  48. public function setRow($row)
  49. {
  50. $this->row = $row;
  51. return $this;
  52. }
  53. public function getRow()
  54. {
  55. return $this->row;
  56. }
  57. /**
  58. * @param Column $column
  59. *
  60. * @return $this
  61. */
  62. public function setColumn(Column $column)
  63. {
  64. $this->column = $column;
  65. return $this;
  66. }
  67. /**
  68. * @return string
  69. */
  70. public function href()
  71. {
  72. }
  73. /**
  74. * Render row action.
  75. *
  76. * @return string
  77. */
  78. public function render()
  79. {
  80. $this->addScript();
  81. if (! $href = $this->href()) {
  82. $href = 'javascript:void(0);';
  83. }
  84. $attributes = $this->formatHtmlAttributes();
  85. return sprintf(
  86. "<a data-_key='%s' href='%s' class='%s' {$attributes}>%s</a>",
  87. $this->getKey(),
  88. $href,
  89. $this->getElementClass(),
  90. $this->name()
  91. );
  92. }
  93. }