EditButton.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. class EditButton extends ButtonDataTableModalAction implements ClientArea
  26. {
  27. protected $icon = 'lu-zmdi lu-zmdi-edit';
  28. public function initContent()
  29. {
  30. $this->initIds('redirectButton');
  31. $this->setDisableByColumnValue("vmid", 0);
  32. $url ="clientarea.php?action=productdetails&id={$this->getWhmcsParamByKey('serviceid')}&modop=custom&a=management&mg-page=vm";
  33. $this->setRawUrl($url)
  34. ->setRedirectParams(['vm' => ':id']);
  35. }
  36. public function afterInitContent()
  37. {
  38. $this->htmlAttributes['@click.middle'] = 'redirect($event, ' . $this->parseCustomParams() . ', true)';
  39. $this->htmlAttributes['@click'] = 'redirect($event, ' . $this->parseCustomParams() . ')';
  40. }
  41. public function setRawUrl($url)
  42. {
  43. $this->rawUrl = $url;
  44. return $this;
  45. }
  46. protected function parseCustomParams()
  47. {
  48. if (count($this->redirectParams) === 0 && $this->rawUrl === null)
  49. {
  50. return '{}';
  51. }
  52. return $this->parseListTOJsString($this->redirectParams);
  53. }
  54. protected function parseListTOJsString($params)
  55. {
  56. $jsString = '{';
  57. if ($this->rawUrl !== null)
  58. {
  59. $params['rawUrl'] = $this->rawUrl;
  60. }
  61. foreach ($params as $key => $value)
  62. {
  63. $jsString .= ' ' . str_replace('-', '__', $key) . ': ' . (is_array($value) ? ($this->parseListTOJsString($value) . ',') : ("'" . (string) $value) . "',");
  64. }
  65. $jsString = trim($jsString, ',') . ' } ';
  66. return $jsString;
  67. }
  68. public function setRedirectParams($paramsList)
  69. {
  70. $this->redirectParams = $paramsList;
  71. $this->updateHtmlAttributesByRedirectParams();
  72. return $this;
  73. }
  74. protected function updateHtmlAttributesByRedirectParams()
  75. {
  76. foreach ($this->redirectParams as $key => $value)
  77. {
  78. $this->updateHtmlAttribute($key, $value);
  79. }
  80. }
  81. protected function updateHtmlAttribute($key, $value)
  82. {
  83. if (strpos($value, ':') === 0)
  84. {
  85. $this->addHtmlAttribute(':data-' . $key , 'dataRow.' . trim($value, ':'));
  86. }
  87. }
  88. }