BackupSwitchButton.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\MountPoint\Buttons;
  20. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  21. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  22. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  23. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\ResponseTemplates\DataJsonResponse;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Buttons\ButtonSwitchAjax;
  25. class BackupSwitchButton extends ButtonSwitchAjax implements ClientArea
  26. {
  27. use ApiService;
  28. use ProductService;
  29. protected $switchColumn = 'backup';
  30. protected $id = 'backupSwitchButton';
  31. protected $name = 'backupSwitchButton';
  32. protected $refreshActionIds = 'mountPointDataTable';
  33. public function initContent()
  34. {
  35. parent::initContent();
  36. $this->addHtmlAttribute(':disabled', 'dataRow.master == true');
  37. if (!$this->configuration()->isPermissionMountPointBackup())
  38. {
  39. $this->addHtmlAttribute('disabled', '');
  40. }
  41. }
  42. public function returnAjaxData()
  43. {
  44. try
  45. {
  46. $this->acl()->backup();
  47. $vm = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVm();
  48. $hdd = $vm->getMounPoints()->findMountPointById($this->getRequestValue('actionElementId'));
  49. $hdd->setBackup($this->getRequestValue("value") == "on" ? 1 : null);
  50. $hdd->update();
  51. }
  52. catch (\Exception $exc)
  53. {
  54. return (new DataJsonResponse())->setStatusError()->setMessage($exc->getMessage())->setCallBackFunction($this->callBackFunction)->addRefreshTargetId($this->refreshActionIds);
  55. }
  56. return (new DataJsonResponse())->setMessageAndTranslate('changesSaved')->setCallBackFunction($this->callBackFunction)->addRefreshTargetId($this->refreshActionIds);
  57. }
  58. }