TitleButtons.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Traits;
  3. // to do disable title
  4. /**
  5. * Title elements related functions
  6. *
  7. * @author Sławomir Miśkowicz <slawomir@modulesgarden.com>
  8. */
  9. trait TitleButtons
  10. {
  11. protected $titleButtons = [];
  12. public function removeTitleButtons()
  13. {
  14. $this->titleButtons = [];
  15. return $this;
  16. }
  17. public function addTitleButton($button)
  18. {
  19. if (is_string($button))
  20. {
  21. $button = DependencyInjection::create($button);
  22. }
  23. $button->setMainContainer($this->mainContainer);
  24. $id = $button->getId();
  25. if (!isset($this->titleButtons[$id]))
  26. {
  27. $this->titleButtons[$id] = $button;
  28. if ($button instanceof \ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AjaxElementInterface)
  29. {
  30. $this->mainContainer->addAjaxElement($this->titleButtons[$id]);
  31. }
  32. }
  33. return $this;
  34. }
  35. public function titleButtonIsExist()
  36. {
  37. return (count($this->titleButtons) > 0);
  38. }
  39. public function insertTitleButton($buttonId)
  40. {
  41. if (!$this->titleButtons[$buttonId])
  42. {
  43. //add exception
  44. }
  45. else
  46. {
  47. $button = $this->titleButtons[$buttonId];
  48. return $button->getHtml();
  49. }
  50. return '';
  51. }
  52. public function getTitleButtons()
  53. {
  54. return $this->titleButtons;
  55. }
  56. }