ConsoleButton.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS Product developed. (27.03.19)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Vms\Buttons;
  20. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Vms\Modals\MigrateModal;
  21. use ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\BuildUrl;
  22. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AdminArea;
  23. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Buttons\ButtonDataTableModalAction;
  25. use ModulesGarden\Servers\ProxmoxCloudVps\App\Helpers\UrlServiceHelper;
  26. class ConsoleButton extends ButtonDataTableModalAction implements ClientArea
  27. {
  28. protected $icon = 'lu-zmdi lu-zmdi-desktop-windows';
  29. public function initContent()
  30. {
  31. if (isAdmin() || $this->configuration()->isPermissionNovnc())
  32. {
  33. $redirectButton = new RedirectButton('novnc');
  34. $redirectButton->setImageUrl(BuildUrl::getAppAssetsURL() . DS . 'img' . DS . 'buttons' . DS . 'novnc.png');
  35. $redirectButton->setHref("#");
  36. $redirectButton->setIcon('lu-zmdi lu-zmdi-fullscreen');
  37. $this->addButton($redirectButton);
  38. }
  39. $this->initIds('consoleButton');
  40. $this->setDisableByColumnValue("vmid", 0);
  41. $url ="clientarea.php?action=productdetails&id={$this->getWhmcsParamByKey('serviceid')}&modop=custom&a=management&mg-page=vm";
  42. $this->setRawUrl($url)
  43. ->setRedirectParams(['vm' => ':id']);
  44. }
  45. public function afterInitContent()
  46. {
  47. $this->htmlAttributes['@click.middle'] = 'redirect($event, ' . $this->parseCustomParams() . ', true)';
  48. $this->htmlAttributes['@click'] = 'redirect($event, ' . $this->parseCustomParams() . ')';
  49. }
  50. public function setRawUrl($url)
  51. {
  52. $this->rawUrl = $url;
  53. return $this;
  54. }
  55. protected function parseCustomParams()
  56. {
  57. if (count($this->redirectParams) === 0 && $this->rawUrl === null)
  58. {
  59. return '{}';
  60. }
  61. return $this->parseListTOJsString($this->redirectParams);
  62. }
  63. protected function parseListTOJsString($params)
  64. {
  65. $jsString = '{';
  66. if ($this->rawUrl !== null)
  67. {
  68. $params['rawUrl'] = $this->rawUrl;
  69. }
  70. foreach ($params as $key => $value)
  71. {
  72. $jsString .= ' ' . str_replace('-', '__', $key) . ': ' . (is_array($value) ? ($this->parseListTOJsString($value) . ',') : ("'" . (string) $value) . "',");
  73. }
  74. $jsString = trim($jsString, ',') . ' } ';
  75. return $jsString;
  76. }
  77. public function setRedirectParams($paramsList)
  78. {
  79. $this->redirectParams = $paramsList;
  80. $this->updateHtmlAttributesByRedirectParams();
  81. return $this;
  82. }
  83. protected function updateHtmlAttributesByRedirectParams()
  84. {
  85. foreach ($this->redirectParams as $key => $value)
  86. {
  87. $this->updateHtmlAttribute($key, $value);
  88. }
  89. }
  90. protected function updateHtmlAttribute($key, $value)
  91. {
  92. if (strpos($value, ':') === 0)
  93. {
  94. $this->addHtmlAttribute(':data-' . $key , 'dataRow.' . trim($value, ':'));
  95. }
  96. }
  97. }