LoginToPanelButton.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace ModulesGarden\Servers\KerioEmail\App\UI\Client\EmailAccount\Buttons;
  3. use ModulesGarden\Servers\KerioEmail\Core\Helper\BuildUrl;
  4. use ModulesGarden\Servers\KerioEmail\Core\UI\Interfaces\ClientArea;
  5. use ModulesGarden\Servers\KerioEmail\Core\UI\Widget\Buttons\ButtonDataTableModalAction;
  6. use ModulesGarden\Servers\KerioEmail\Core\UI\Widget\Buttons\ButtonRedirect;
  7. use ModulesGarden\Servers\KerioEmail\Core\UI\Widget\Buttons\DropdawnButtonWrappers\ButtonDropdownItem;
  8. /**
  9. *
  10. * Created by PhpStorm.
  11. * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
  12. * Date: 12.11.19
  13. * Time: 16:44
  14. * Class LoginToPanel
  15. */
  16. class LoginToPanelButton extends ButtonDropdownItem implements ClientArea
  17. {
  18. protected $icon = 'lu-dropdown__link-icon lu-btn__icon lu-zmdi lu-zmdi-email';
  19. protected $rawUrl = null;
  20. protected $redirectParams = [];
  21. public function initContent()
  22. {
  23. $this->htmlAttributes['@click.middle'] = 'redirect($event, ' . $this->parseCustomParams() . ', true)';
  24. $this->htmlAttributes['@click'] = 'redirect($event, ' . $this->parseCustomParams() . ', true)';
  25. }
  26. protected function parseCustomParams()
  27. {
  28. if (count($this->redirectParams) === 0 && $this->rawUrl === null)
  29. {
  30. return '{}';
  31. }
  32. return $this->parseListTOJsString($this->redirectParams);
  33. }
  34. protected function parseListTOJsString($params)
  35. {
  36. $jsString = '{';
  37. if ($this->rawUrl !== null)
  38. {
  39. $params['rawUrl'] = $this->rawUrl;
  40. }
  41. foreach ($params as $key => $value)
  42. {
  43. $jsString .= ' ' . str_replace('-', '__', $key) . ': ' . (is_array($value) ? ($this->parseListTOJsString($value) . ',') : ("'" . (string) $value) . "',");
  44. }
  45. $jsString = trim($jsString, ',') . ' } ';
  46. return $jsString;
  47. }
  48. public function setRawUrl($url)
  49. {
  50. $this->rawUrl = $url;
  51. return $this;
  52. }
  53. public function addRedirectParam($key, $value)
  54. {
  55. $this->redirectParams[$key] = $value;
  56. $this->updateHtmlAttributesByRedirectParams();
  57. return $this;
  58. }
  59. public function setRedirectParams($paramsList)
  60. {
  61. $this->redirectParams = $paramsList;
  62. $this->updateHtmlAttributesByRedirectParams();
  63. return $this;
  64. }
  65. protected function updateHtmlAttributesByRedirectParams()
  66. {
  67. foreach ($this->redirectParams as $key => $value)
  68. {
  69. $this->updateHtmlAttribute($key, $value);
  70. }
  71. }
  72. protected function updateHtmlAttribute($key, $value)
  73. {
  74. if (strpos($value, ':') === 0)
  75. {
  76. $this->addHtmlAttribute(':data-' . $key , 'dataRow.' . trim($value, ':'));
  77. }
  78. }
  79. }