UpdateForm.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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\Disk\Forms;
  20. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  21. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ResourceManager;
  22. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Disk\Providers\DiskProvider;
  23. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Disk\Validators\DiskSizeValidator;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\NumberValidator;
  25. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  26. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\BaseForm;
  27. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Hidden;
  28. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Switcher;
  29. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Text;
  30. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Range;
  31. class UpdateForm extends BaseForm implements ClientArea
  32. {
  33. use ProductService;
  34. protected $diskSize;
  35. public function initContent()
  36. {
  37. $this->resourceManager = new ResourceManager();
  38. $this->initIds('updateDiskForm');
  39. $this->setFormType('update');
  40. $this->setProvider(new DiskProvider());
  41. $this->initFields();
  42. $this->loadDataToForm();
  43. $diskSize = parent::getFormData()['size'];
  44. $rangeField = $this->getField('additionalDiskSize');
  45. $rangeField->setMinValue($diskSize);
  46. $rangeField->setDefaultValue($diskSize);
  47. if ($this->configuration()->serverDiskSize->max > ($this->resourceManager->disk()->free() + $diskSize)) {
  48. // $rangeField->setMaxValue($this->resourceManager->disk()->free() + $diskSize);
  49. $rangeField->setMaxValue(200);
  50. } else {
  51. // $rangeField->setMaxValue($this->configuration()->serverDiskSize->max);
  52. $rangeField->setMaxValue(300);
  53. }
  54. $backupSwitcher = $this->getField('backup');
  55. if ( parent::getFormData()['id'] == 'scsi0') {
  56. $backupSwitcher->addClass('hidden');
  57. }
  58. }
  59. public function getAllowedActions()
  60. {
  61. return ['update'];
  62. }
  63. private function initFields()
  64. {
  65. //entity id
  66. $this->addField(new Hidden("id"));
  67. //size
  68. logModuleCall(
  69. 'proxmoxCloud',
  70. __FUNCTION__,
  71. $diskSize,
  72. 'Debug',
  73. $this->configuration()
  74. );
  75. $field = new Range('additionalDiskSize', 0, 200);
  76. // $field->addValidator(new DiskSizeValidator('additionalDiskSize',true));
  77. $this->addField($field);
  78. //backup
  79. if ($this->configuration()->isPermissionAdditionalDiskBackup())
  80. {
  81. $field = new Switcher('backup');
  82. $this->addField($field);
  83. }
  84. }
  85. }