Sign in
EN
games/xencenter-xenadmin-xcp-jumphp / src / Form / NameForm.php · commit fb1b7c9
<?phpnamespace App\Form;use JumPHP\Gui\Button;use JumPHP\Gui\Form;use JumPHP\Gui\Label;use JumPHP\Gui\TextBox;/** * Asks a name and a description (Take Snapshot, Copy VM). Closes with ['name', 'description', 'command', 'target']. * * @property Label $heading * @property Label $label * @property TextBox $name * @property TextBox $description * @property Label $error * @property Button $ok * @property Button $cancel */final class NameForm extends Form{    public function __construct(private \App\Model\Session $session)    {        parent::__construct();    }    /** XAPI's answers, events and the console go on while this dialog is open. */    protected function tick(float $dt): void    {        $this->session->tick($dt);    }    private array $params = [];    protected function loaded(array $params = []): void    {        $this->params = $params;        $this->heading->text = (string)($params['title'] ?? 'Name');        $this->label->text = (string)($params['label'] ?? 'Name:');        $this->name->text = (string)($params['name'] ?? '');        $this->description->text = (string)($params['description'] ?? '');        $this->ok->text = (string)($params['ok'] ?? 'OK');        $this->error->text = '';        $this->setFocus($this->name);    }    public function onOkClick(mixed $sender = null): void    {        if (trim($this->name->text) === '') {            $this->error->text = 'Enter a name.';            return;        }        $this->close(['name' => trim($this->name->text), 'description' => $this->description->text,            'command' => $this->params['command'] ?? '', 'target' => $this->params['target'] ?? '']);    }    public function onCancelClick(Button $sender): void    {        $this->close();    }}