DatatableActionButtons.php 1.3 KB

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