Footer.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace Encore\Admin\Form;
  3. use Encore\Admin\Admin;
  4. use Illuminate\Contracts\Support\Renderable;
  5. class Footer implements Renderable
  6. {
  7. /**
  8. * Footer view.
  9. *
  10. * @var string
  11. */
  12. protected $view = 'admin::form.footer';
  13. /**
  14. * Form builder instance.
  15. *
  16. * @var Builder
  17. */
  18. protected $builder;
  19. /**
  20. * Available buttons.
  21. *
  22. * @var array
  23. */
  24. protected $buttons = ['reset', 'submit'];
  25. /**
  26. * Available checkboxes.
  27. *
  28. * @var array
  29. */
  30. protected $checkboxes = ['view', 'continue_editing', 'continue_creating'];
  31. /**
  32. * Footer constructor.
  33. *
  34. * @param Builder $builder
  35. */
  36. public function __construct(Builder $builder)
  37. {
  38. $this->builder = $builder;
  39. }
  40. /**
  41. * Disable reset button.
  42. *
  43. * @return $this
  44. */
  45. public function disableReset(bool $disable = true)
  46. {
  47. if ($disable) {
  48. array_delete($this->buttons, 'reset');
  49. } elseif (!in_array('reset', $this->buttons)) {
  50. array_push($this->buttons, 'reset');
  51. }
  52. return $this;
  53. }
  54. /**
  55. * Disable submit button.
  56. *
  57. * @return $this
  58. */
  59. public function disableSubmit(bool $disable = true)
  60. {
  61. if ($disable) {
  62. array_delete($this->buttons, 'submit');
  63. } elseif (!in_array('submit', $this->buttons)) {
  64. array_push($this->buttons, 'submit');
  65. }
  66. return $this;
  67. }
  68. /**
  69. * Disable View Checkbox.
  70. *
  71. * @return $this
  72. */
  73. public function disableViewCheck(bool $disable = true)
  74. {
  75. if ($disable) {
  76. array_delete($this->checkboxes, 'view');
  77. } elseif (!in_array('view', $this->checkboxes)) {
  78. array_push($this->checkboxes, 'view');
  79. }
  80. return $this;
  81. }
  82. /**
  83. * Disable Editing Checkbox.
  84. *
  85. * @return $this
  86. */
  87. public function disableEditingCheck(bool $disable = true)
  88. {
  89. if ($disable) {
  90. array_delete($this->checkboxes, 'continue_editing');
  91. } elseif (!in_array('continue_editing', $this->checkboxes)) {
  92. array_push($this->checkboxes, 'continue_editing');
  93. }
  94. return $this;
  95. }
  96. /**
  97. * Disable Creating Checkbox.
  98. *
  99. * @return $this
  100. */
  101. public function disableCreatingCheck(bool $disable = true)
  102. {
  103. if ($disable) {
  104. array_delete($this->checkboxes, 'continue_creating');
  105. } elseif (!in_array('continue_creating', $this->checkboxes)) {
  106. array_push($this->checkboxes, 'continue_creating');
  107. }
  108. return $this;
  109. }
  110. /**
  111. * Setup scripts.
  112. */
  113. protected function setupScript()
  114. {
  115. $script = <<<'EOT'
  116. $('.after-submit').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChecked', function () {
  117. $('.after-submit').not(this).iCheck('uncheck');
  118. });
  119. EOT;
  120. Admin::script($script);
  121. }
  122. /**
  123. * Render footer.
  124. *
  125. * @return string
  126. */
  127. public function render()
  128. {
  129. $this->setupScript();
  130. $data = [
  131. 'buttons' => $this->buttons,
  132. 'checkboxes' => $this->checkboxes,
  133. 'width' => $this->builder->getWidth(),
  134. ];
  135. return view($this->view, $data)->render();
  136. }
  137. }