DatatableMassActionButtons.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\Core\UI\Traits;
  3. trait DatatableMassActionButtons
  4. {
  5. protected $massActionButtons = [];
  6. public function addMassActionButton($button)
  7. {
  8. if (is_string($button))
  9. {
  10. $button = ServiceLocator::call($button);
  11. }
  12. $button->setMainContainer($this->mainContainer);
  13. $id = $button->getId();
  14. if (!isset($this->massActionButtons[$id]))
  15. {
  16. $this->massActionButtons[$id] = $button;
  17. if ($button instanceof \ModulesGarden\ProxmoxAddon\Core\UI\Interfaces\AjaxElementInterface)
  18. {
  19. $this->mainContainer->addAjaxElement($this->massActionButtons[$id]);
  20. }
  21. }
  22. return $this;
  23. }
  24. public function insertMassActionButton($buttonId)
  25. {
  26. if (!$this->massActionButtons[$buttonId])
  27. {
  28. //add exception
  29. }
  30. else
  31. {
  32. $button = $this->massActionButtons[$buttonId];
  33. return $button->getHtml();
  34. }
  35. return '';
  36. }
  37. public function hasMassActionButtons()
  38. {
  39. return (count($this->massActionButtons) > 0) ? true : false;
  40. }
  41. public function getMassActionButtons()
  42. {
  43. return $this->massActionButtons;
  44. }
  45. }