diff --git a/application/forms/Pending/PackagesForm.php b/application/forms/Pending/PackagesForm.php index 30d5273..8c70fb9 100644 --- a/application/forms/Pending/PackagesForm.php +++ b/application/forms/Pending/PackagesForm.php @@ -3,14 +3,14 @@ namespace Icinga\Module\Masifupgrader\Forms\Pending; use Icinga\Module\Masifupgrader\Web\DbAwareFormTrait; -use Icinga\Module\Masifupgrader\Web\HeadlessFormTrait; use Icinga\Web\Form; +use Zend_Form_Element_Checkbox; +use Zend_Form_Element_Submit; use Zend_View_Interface; class PackagesForm extends Form { use DbAwareFormTrait; - use HeadlessFormTrait; /** * @var array @@ -157,7 +157,7 @@ public function createElements(array $formData) foreach ($actions as $action => $toVersions) { foreach ($toVersions as $toVersion => $_) { $checkboxName = implode('_', [bin2hex($package), $action, bin2hex($toVersion)]); - $this->addHeadlessElement('checkbox', $checkboxName, []); + $this->addElement('checkbox', $checkboxName, []); if (isset($formData[$checkboxName]) && $formData[$checkboxName]) { $agentFilter[$package][$action][$toVersion] = null; @@ -171,15 +171,25 @@ public function createElements(array $formData) $this->addElement('hidden', 'filter_agents', ['value' => '1']); foreach ($this->getAgents($agentFilter) as $agent => $packages) { - $this->addHeadlessElement('checkbox', 'agent_' . bin2hex($agent), []); + $this->addElement('checkbox', 'agent_' . bin2hex($agent), []); } } else { - $this->addHeadlessElement('checkbox', 'filter_agents_first', []); + $this->addElement('checkbox', 'filter_agents_first', []); } } public function render(Zend_View_Interface $view = null) { + $this->create(); + + foreach ($this->getElements() as $element) { + if ($element instanceof Zend_Form_Element_Checkbox || $element instanceof Zend_Form_Element_Submit) { + $element->setDecorators([ + 'Zend_Form_Decorator_ViewHelper' => $element->getDecorators()['Zend_Form_Decorator_ViewHelper'] + ]); + } + } + if ($view === null) { $view = $this->getView(); } @@ -190,7 +200,16 @@ public function render(Zend_View_Interface $view = null) $invertTrigger = $this->translate('(invert selection)'); $t1checkbox1 = $this->translate('Select specific agents first'); - $result = $this->renderHeadless($view) + $filterAgents = $this->getElement('filter_agents'); + if ($filterAgents !== null) { + $filterAgents = $filterAgents->render($view); + } + + $result = "
" + . $this->getElement($this->getUidElementName())->render($view) + . $this->getElement($this->getTokenElementName())->render($view) + . $filterAgents . "" . "" . ""; @@ -251,7 +270,7 @@ public function render(Zend_View_Interface $view = null) $result .= '' . implode('', $row) . ''; } - if ($this->getElement('filter_agents') === null) { + if ($filterAgents === null) { $filterAgents = $this->getElement('filter_agents_first'); $result .= "
{$view->escape($t1header1)}{$view->escape($t1header2)}{$view->escape($t1header3)} {$view->escape($invertTrigger)}
{$filterAgents->render($view)}" @@ -269,7 +288,7 @@ public function render(Zend_View_Interface $view = null) $result .= "
{$this->getElement('btn_submit')->render($view)}
"; } - return $result; + return "$result
"; } public function onSuccess() @@ -297,7 +316,7 @@ public function onSuccess() foreach ($this->getTasks() as $package => list($agents, $actions)) { foreach ($actions as $action => $toVersions) { foreach ($toVersions as $toVersion => $_) { - /** @var \Zend_Form_Element_Checkbox $checkbox */ + /** @var Zend_Form_Element_Checkbox $checkbox */ $checkbox = $this->getElement(implode('_', [bin2hex($package), $action, bin2hex($toVersion)])); if ($checkbox->isChecked()) { diff --git a/library/Masifupgrader/Web/HeadlessFormTrait.php b/library/Masifupgrader/Web/HeadlessFormTrait.php deleted file mode 100644 index 8dfdcfd..0000000 --- a/library/Masifupgrader/Web/HeadlessFormTrait.php +++ /dev/null @@ -1,63 +0,0 @@ -createElement($element, ...$args); - } - - $element->form = $this->getId(); - $element->setDecorators([$element->getDecorators()['Zend_Form_Decorator_ViewHelper']]); - - $this->headlessElements[$element->getName()] = $element; - - return $this->addElement($element); - } - - protected function renderHeadless(Zend_View_Interface $view = null) - { - /** @var Form $that */ - $that = $this; - - $that->setAttrib('style', 'display: none;'); - - $that->create(); - - $element = $that->getElement('btn_submit'); - if ($element !== null) { - $element->form = $this->getId(); - $element->setDecorators([$element->getDecorators()['Zend_Form_Decorator_ViewHelper']]); - - $this->headlessElements[$element->getName()] = $element; - } - - foreach ($this->headlessElements as $headlessElement => $_) { - $that->removeElement($headlessElement); - } - - $result = Zend_Form::render($view); - - foreach ($this->headlessElements as $headlessElement) { - $that->addElement($headlessElement); - } - - return $result; - } -}