JobForm.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxVps\App\UI\Snapshot\Forms;
  3. use MGProvision\Proxmox\v2\models\Kvm;
  4. use ModulesGarden\Servers\ProxmoxVps\App\Enum\ConfigurableOption;
  5. use ModulesGarden\Servers\ProxmoxVps\App\Enum\JobPeriod;
  6. use ModulesGarden\Servers\ProxmoxVps\App\UI\Validators\SnapshotValidator;
  7. use ModulesGarden\Servers\ProxmoxVps\App\UI\Validators\StartTimeValidator;
  8. use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\sl;
  9. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Hidden;
  10. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Number;
  11. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Select;
  12. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Switcher;
  13. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Text;
  14. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Textarea;
  15. trait JobForm
  16. {
  17. public function setJobConfirmMessage(){
  18. $limit = $this->getWhmcsConfigOption(ConfigurableOption::SNAPSHOTS, $this->configuration()->getSnapshotMaxFiles());
  19. if ($limit && $limit != "-1") {
  20. sl("lang")->addReplacementConstant("snapshotFilesLimit" , $limit);
  21. $this->setInternalAlertMessage( sl("lang")->tr('Your snapshot limit is :snapshotFilesLimit:. When you exceed this limit, the last snapshot will be replaced with a new one.'));
  22. $this->setInternalAlertMessageRaw(true);
  23. }
  24. }
  25. protected function initFields() {
  26. $formData = $this->getRequestValue("formData");
  27. //id
  28. $id = false;
  29. if(is_numeric($this->getRequestValue("actionElementId"))){
  30. $id = $this->getRequestValue("actionElementId");
  31. }
  32. if ($formData && $formData['id']){
  33. $id = $formData['id'];
  34. }
  35. //hourly
  36. $isHourly = true;
  37. if($formData && $formData['period'] ){
  38. $isHourly = $formData['period'] == JobPeriod::HOURLY;
  39. } elseif (!$formData && $id) {
  40. $this->loadProvider();
  41. $this->dataProvider->read();
  42. $isHourly = $this->dataProvider->getValueById('period') == JobPeriod::HOURLY ;
  43. } elseif (!$formData && !$id) {
  44. $period = $this->configuration()->getPermissionSnapshotJobPeriod();
  45. if($period && in_array(JobPeriod::HOURLY, $period)){
  46. $isHourly = true;
  47. }elseif ($period ){
  48. $isHourly = false;
  49. }
  50. }
  51. //id
  52. if(is_numeric($this->getRequestValue("actionElementId"))) {
  53. $this->addField(new Hidden("id"));
  54. }
  55. //period
  56. $field = new Select('period');
  57. $field->addHtmlAttribute('bi-event-change', "reloadVueModal");
  58. $this->addField($field);
  59. //run_every
  60. if($isHourly){
  61. $field = new Number('run_every',1,48);
  62. $field->setPlaceholder("1");
  63. $this->addField($field);
  64. }
  65. //days
  66. if(!$isHourly){
  67. $field = new Select('days');
  68. $field->enableMultiple();
  69. $this->addField($field);
  70. }
  71. //start_time
  72. if(!$isHourly){
  73. $field = new Text('start_time');
  74. $field->setPlaceholder("00:00");
  75. $field->addValidator(new StartTimeValidator(false));
  76. $this->addField($field);
  77. }
  78. //name
  79. $field = new Text('name');
  80. $field->notEmpty();
  81. $field->addValidator(new SnapshotValidator(true));
  82. $this->addField($field);
  83. //vmstate
  84. if ($this->vm() instanceof Kvm) {
  85. $field = new Switcher("vmstate");
  86. $field->addHtmlAttribute("disabled",true);
  87. $field->addClass("disabled");
  88. $this->addField($field);
  89. }
  90. //description
  91. $field = new Textarea("description");
  92. $this->addField($field);
  93. }
  94. }