CloudInitSection.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. //cloudInitStorage
  72. $field = new Select('customconfigoption[cloudInitStorage]');
  73. $field->setDescription('tip');
  74. $this->rightSection->addField($field);
  75. }
  76. public function addSectionField(BaseField $field)
  77. {
  78. $this->sectionFields[] = $field;
  79. return $this;
  80. }
  81. private function addFieldsToSections(){
  82. foreach($this->sectionFields as $k => $field){
  83. if($k % 2 == 0 ){
  84. $this->leftSection->addField($field);
  85. }else{
  86. $this->rightSection->addField($field);
  87. }
  88. }
  89. unset($this->sectionFields);
  90. }
  91. }