| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace ModulesGarden\Servers\KerioEmail\App\UI\Client\Ressource\Buttons;
- use ModulesGarden\Servers\KerioEmail\Core\Helper\BuildUrl;
- use ModulesGarden\Servers\KerioEmail\Core\UI\Interfaces\ClientArea;
- use ModulesGarden\Servers\KerioEmail\Core\UI\Widget\Buttons\ButtonDataTableModalAction;
- use ModulesGarden\Servers\KerioEmail\Core\UI\Widget\Buttons\ButtonRedirect;
- use ModulesGarden\Servers\KerioEmail\Core\UI\Widget\Buttons\DropdawnButtonWrappers\ButtonDropdownItem;
- /**
- *
- * Created by PhpStorm.
- * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
- * Date: 12.11.19
- * Time: 16:44
- * Class LoginToPanel
- */
- class LoginToPanelButton extends ButtonDropdownItem implements ClientArea
- {
- protected $icon = 'lu-dropdown__link-icon lu-btn__icon lu-zmdi lu-zmdi-email';
- protected $rawUrl = null;
- protected $redirectParams = [];
- public function initContent()
- {
- $this->htmlAttributes['@click.middle'] = 'redirect($event, ' . $this->parseCustomParams() . ', true)';
- $this->htmlAttributes['@click'] = 'redirect($event, ' . $this->parseCustomParams() . ', true)';
- }
- protected function parseCustomParams()
- {
- if (count($this->redirectParams) === 0 && $this->rawUrl === null)
- {
- return '{}';
- }
- return $this->parseListTOJsString($this->redirectParams);
- }
- protected function parseListTOJsString($params)
- {
- $jsString = '{';
- if ($this->rawUrl !== null)
- {
- $params['rawUrl'] = $this->rawUrl;
- }
- foreach ($params as $key => $value)
- {
- $jsString .= ' ' . str_replace('-', '__', $key) . ': ' . (is_array($value) ? ($this->parseListTOJsString($value) . ',') : ("'" . (string) $value) . "',");
- }
- $jsString = trim($jsString, ',') . ' } ';
- return $jsString;
- }
- public function setRawUrl($url)
- {
- $this->rawUrl = $url;
- return $this;
- }
- public function addRedirectParam($key, $value)
- {
- $this->redirectParams[$key] = $value;
- $this->updateHtmlAttributesByRedirectParams();
- return $this;
- }
- public function setRedirectParams($paramsList)
- {
- $this->redirectParams = $paramsList;
- $this->updateHtmlAttributesByRedirectParams();
- return $this;
- }
- protected function updateHtmlAttributesByRedirectParams()
- {
- foreach ($this->redirectParams as $key => $value)
- {
- $this->updateHtmlAttribute($key, $value);
- }
- }
- protected function updateHtmlAttribute($key, $value)
- {
- if (strpos($value, ':') === 0)
- {
- $this->addHtmlAttribute(':data-' . $key , 'dataRow.' . trim($value, ':'));
- }
- }
- }
|