| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace ModulesGarden\Servers\ProxmoxVps\App\UI\Snapshot\Forms;
- use MGProvision\Proxmox\v2\models\Kvm;
- use ModulesGarden\Servers\ProxmoxVps\App\Enum\ConfigurableOption;
- use ModulesGarden\Servers\ProxmoxVps\App\Enum\JobPeriod;
- use ModulesGarden\Servers\ProxmoxVps\App\UI\Validators\SnapshotValidator;
- use ModulesGarden\Servers\ProxmoxVps\App\UI\Validators\StartTimeValidator;
- use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\sl;
- use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Hidden;
- use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Number;
- use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Select;
- use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Switcher;
- use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Text;
- use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Textarea;
- trait JobForm
- {
- public function setJobConfirmMessage(){
- $limit = $this->getWhmcsConfigOption(ConfigurableOption::SNAPSHOTS, $this->configuration()->getSnapshotMaxFiles());
- if ($limit && $limit != "-1")
- {
- sl("lang")->addReplacementConstant("snapshotFilesLimit" , $limit);
- $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.'));
- $this->setInternalAlertMessageRaw(true);
- }
- }
- protected function initFields()
- {
- $formData = $this->getRequestValue("formData");
- //id
- $id = false;
- if(is_numeric($this->getRequestValue("actionElementId"))){
- $id = $this->getRequestValue("actionElementId");
- }
- if ($formData && $formData['id']){
- $id = $formData['id'];
- }
- //hourly
- $isHourly = true;
- if($formData && $formData['period'] ){
- $isHourly = $formData['period'] == JobPeriod::HOURLY;
- } elseif (!$formData && $id){
- $this->loadProvider();
- $this->dataProvider->read();
- $isHourly = $this->dataProvider->getValueById('period') == JobPeriod::HOURLY ;
- }elseif (!$formData && !$id){
- $period = $this->configuration()->getPermissionSnapshotJobPeriod();
- if($period && in_array(JobPeriod::HOURLY, $period)){
- $isHourly = true;
- }elseif ($period ){
- $isHourly = false;
- }
- }
- //id
- if(is_numeric($this->getRequestValue("actionElementId"))){
- $this->addField(new Hidden("id"));
- }
- //period
- $field = new Select('period');
- $field->addHtmlAttribute('bi-event-change', "reloadVueModal");
- $this->addField($field);
- //run_every
- if($isHourly){
- $field = new Number('run_every',1,48);
- $field->setPlaceholder("1");
- $this->addField($field);
- }
- //days
- if(!$isHourly){
- $field = new Select('days');
- $field->enableMultiple();
- $this->addField($field);
- }
- //start_time
- if(!$isHourly){
- $field = new Text('start_time');
- $field->setPlaceholder("00:00");
- $field->addValidator(new StartTimeValidator(false));
- $this->addField($field);
- }
- //name
- $field = new Text('name');
- $field->notEmpty();
- $field->addValidator(new SnapshotValidator(true));
- $this->addField($field);
- //vmstate
- if ($this->vm() instanceof Kvm)
- {
- $field = new Switcher("vmstate");
- $this->addField($field);
- }
- //description
- $field = new Textarea("description");
- $this->addField($field);
- }
- }
|