CreateForm.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /* * ********************************************************************
  3. * Wordpress_Manager Product developed. (Dec 11, 2017)
  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\ProxmoxAddon\App\UI\ServerGroup\Forms;
  20. use MGProvision\Proxmox\v2\ProxmoxApiException;
  21. use ModulesGarden\ProxmoxAddon\App\UI\ServerGroup\Providers\ServerGroupProvider;
  22. use ModulesGarden\ProxmoxAddon\Core\UI\Helpers\AlertTypesConstants;
  23. use ModulesGarden\ProxmoxAddon\Core\UI\Interfaces\AdminArea;
  24. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\BaseForm;
  25. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\Fields;
  26. /**
  27. * Description of CreateForm
  28. *
  29. * @author Pawel Kopec <pawelk@modulesgarden.com>
  30. */
  31. class CreateForm extends BaseForm implements AdminArea
  32. {
  33. public function initContent()
  34. {
  35. $this->initIds('createForm');
  36. $this->setFormType('create');
  37. $this->setProvider(new ServerGroupProvider);
  38. $this->initFields();
  39. }
  40. protected function initFields()
  41. {
  42. try{
  43. //Server Id
  44. $this->addField(new Fields\Hidden('server_id'));
  45. //id
  46. $this->addField(new Fields\Hidden('id'));
  47. //name
  48. $field = new Fields\Text('name');
  49. $field->notEmpty();
  50. $this->addField($field);
  51. //node
  52. $field = new Fields\Select('node');
  53. $field->enableMultiple()
  54. ->notEmpty();
  55. $this->addField($field);
  56. $this->loadDataToForm();
  57. }catch (ProxmoxApiException $ex){
  58. $this->setInternalAlertMessage($ex->getMessage())->setInternalAlertMessageType(AlertTypesConstants::DANGER);
  59. }
  60. }
  61. protected function getDefaultActions()
  62. {
  63. return ['create'];
  64. }
  65. }