CloudInitSection.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Sections\Qemu;
  3. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\AdminArea;
  4. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\BaseField;
  5. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Select;
  6. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Switcher;
  7. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Text;
  8. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Textarea;
  9. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Sections\BoxSection;
  10. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Sections\HalfPageSection;
  11. class CloudInitSection extends BoxSection implements AdminArea
  12. {
  13. protected $id = 'cloudInitSection';
  14. protected $name = 'cloudInitSection';
  15. protected $title = 'cloudInitSection';
  16. private $sectionFields=[];
  17. /**
  18. * @var HalfPageSection
  19. */
  20. private $leftSection;
  21. /**
  22. * @var HalfPageSection
  23. */
  24. private $rightSection;
  25. public function initContent()
  26. {
  27. $this->leftSection = new HalfPageSection('leftSection');
  28. $this->rightSection = new HalfPageSection('rightSection');
  29. $this->addSection($this->leftSection)
  30. ->addSection($this->rightSection);
  31. $this->initFields();
  32. }
  33. private function initFields()
  34. {
  35. //Enable Cloud-Init
  36. $field = new Switcher('customconfigoption[cloudInit]');
  37. $field->setDescription('tip');
  38. $field->setDefaultValue("on");
  39. $this->addSectionField($field);
  40. //Service Username
  41. $field = new Switcher('customconfigoption[cloudInitServiceUsername]');
  42. $field->setDescription('tip');
  43. $field->setDefaultValue("on");
  44. $this->addSectionField($field);
  45. //Service Password
  46. $field = new Switcher('customconfigoption[cloudInitServicePassword]');
  47. $field->setDescription('tip');
  48. $field->setDefaultValue("on");
  49. $this->addSectionField($field);
  50. //Service Nameservers
  51. $field = new Switcher('customconfigoption[cloudInitServiceNameservers]');
  52. $field->setDescription('tip');
  53. $this->addSectionField($field);
  54. //DNS Domain
  55. $field = new Text('customconfigoption[searchdomain]');
  56. $field->setDescription('tip');
  57. $this->addSectionField($field);
  58. //Default User
  59. $field = new Text('customconfigoption[ciuser]');
  60. $field->setDescription('tip');
  61. $this->addSectionField($field);
  62. //cicustom
  63. $field = new Textarea('customconfigoption[cicustom]');
  64. $field->setDescription('tip');
  65. $this->addSectionField($field);
  66. //cloudInitScript
  67. $field = new Select('customconfigoption[cloudInitScript]');
  68. $field->setDescription('tip');
  69. $this->addSectionField($field);
  70. $this->addFieldsToSections();
  71. }
  72. public function addSectionField(BaseField $field)
  73. {
  74. $this->sectionFields[] = $field;
  75. return $this;
  76. }
  77. private function addFieldsToSections(){
  78. foreach($this->sectionFields as $k => $field){
  79. if($k % 2 == 0 ){
  80. $this->leftSection->addField($field);
  81. }else{
  82. $this->rightSection->addField($field);
  83. }
  84. }
  85. unset($this->sectionFields);
  86. }
  87. }