| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- namespace ThurData\Servers\KerioEmail\Core\UI\Traits;
- use \ThurData\Servers\KerioEmail\Core\DependencyInjection;
- use \ThurData\Servers\KerioEmail\Core\UI\Widget\Buttons\ModalActionButtons\BaseAcceptButton;
- use \ThurData\Servers\KerioEmail\Core\UI\Widget\Buttons\ModalActionButtons\BaseCancelButton;
- /**
- * Modal Action Buttons related functions
- *
- * @autor ThurData <info@thrudata.ch>
- */
- trait ModalActionButtons
- {
- protected $actionButtons = [];
- public function addActionButton($button)
- {
- $this->addButtonToList($button);
- return $this;
- }
- protected function addButtonToList($button)
- {
- if (is_string($button))
- {
- $button = DependencyInjection::create($button);
- }
- $button->setMainContainer($this->mainContainer);
- $id = $button->getId();
- if (!isset($this->actionButtons[$id]))
- {
- $this->actionButtons[$id] = $button;
- if ($button instanceof \ThurData\Servers\KerioEmail\Core\UI\Interfaces\AjaxElementInterface)
- {
- $this->mainContainer->addAjaxElement($this->actionButtons[$id]);
- }
- }
- return $button;
- }
- public function insertActionButton($buttonId)
- {
- if (!$this->actionButtons[$buttonId])
- {
- //add exception
- }
- else
- {
- $button = $this->actionButtons[$buttonId];
- return $button->getHtml();
- }
- return '';
- }
- public function getActionButtons()
- {
- $this->initActionButtons();
- return $this->actionButtons;
- }
- protected function initActionButtons()
- {
- if (!empty($this->actionButtons))
- {
- return $this;
- }
- $this->addActionButton(new BaseAcceptButton);
- $this->addActionButton(new BaseCancelButton);
- return $this;
- }
- public function replaceSubmitButton($button)
- {
- $this->initActionButtons();
- $added = $this->addButtonToList($button);
- if (isset($this->actionButtons[$added->getId()]) &&
- isset($this->actionButtons['baseAcceptButton']))
- {
- $this->actionButtons['baseAcceptButton'] = $this->actionButtons[$added->getId()];
- unset($this->actionButtons[$added->getId()]);
- }
- return $this;
- }
- public function replaceSubmitButtonClasses($classes)
- {
- $this->initActionButtons();
- if (isset($this->actionButtons['baseAcceptButton']))
- {
- $this->actionButtons['baseAcceptButton']->replaceClasses($classes);
- }
-
- return $this;
- }
- public function setSubmitButtonClassesDanger()
- {
- $this->replaceSubmitButtonClasses(['lu-btn lu-btn--danger submitForm']);
- return $this;
- }
- /**
- * Remove action button using action button object
- * @param $button
- * @return bool
- */
- public function removeActionButton($button)
- {
- foreach($this->actionButtons as $key => $obj)
- {
- if($obj === $button)
- {
- unset($this->actionButtons[$key]);
- return true;
- }
- }
- return false;
- }
- /**
- * Remove action button using index
- * @param $index
- * @return bool
- */
- public function removeActionButtonByIndex($index)
- {
- if(array_key_exists($index, $this->actionButtons))
- {
- unset($this->actionButtons[$index]);
- return true;
- }
- return false;
- }
- }
|