mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
Introduce Form::setOnSuccess() in favor of overriding the constructor
Zend_Form uses setters for options if a respective setter method exists. It is not necessary to override the constructor for introducing new options. Conflicts: library/Icinga/Web/Form.php
This commit is contained in:
parent
10cfecf2ec
commit
f2717b6d26
@ -44,7 +44,7 @@ class DashboardController extends ActionController
|
|||||||
$params['url'] = rawurldecode($this->_request->getParam('url'));
|
$params['url'] = rawurldecode($this->_request->getParam('url'));
|
||||||
$form->populate($params);
|
$form->populate($params);
|
||||||
}
|
}
|
||||||
$form->setOnSuccess(function (Request $request, Form $form) use ($dashboard) {
|
$form->setOnSuccess(function (Form $form) use ($dashboard) {
|
||||||
try {
|
try {
|
||||||
$pane = $dashboard->getPane($form->getValue('pane'));
|
$pane = $dashboard->getPane($form->getValue('pane'));
|
||||||
} catch (ProgrammingError $e) {
|
} catch (ProgrammingError $e) {
|
||||||
@ -83,8 +83,14 @@ class DashboardController extends ActionController
|
|||||||
400
|
400
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$form->setOnSuccess(function (Request $request, Form $form) use ($dashboard) {
|
$form->setOnSuccess(function (Form $form) use ($dashboard) {
|
||||||
$pane = $dashboard->getPane($form->getValue('pane'));
|
try {
|
||||||
|
$pane = $dashboard->getPane($form->getValue('pane'));
|
||||||
|
} catch (ProgrammingError $e) {
|
||||||
|
$pane = new Dashboard\Pane($form->getValue('pane'));
|
||||||
|
$pane->setUserWidget();
|
||||||
|
$dashboard->addPane($pane);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$component = $pane->getComponent($form->getValue('component'));
|
$component = $pane->getComponent($form->getValue('component'));
|
||||||
$component->setUrl($form->getValue('url'));
|
$component->setUrl($form->getValue('url'));
|
||||||
@ -97,7 +103,11 @@ class DashboardController extends ActionController
|
|||||||
if ($form->getValue('org_component') && $form->getValue('org_component') !== $component->getTitle()) {
|
if ($form->getValue('org_component') && $form->getValue('org_component') !== $component->getTitle()) {
|
||||||
$pane->removeComponent($form->getValue('org_component'));
|
$pane->removeComponent($form->getValue('org_component'));
|
||||||
}
|
}
|
||||||
$dashboard->write();
|
// Move
|
||||||
|
if ($form->getValue('org_pane') && $form->getValue('org_pane') !== $pane->getTitle()) {
|
||||||
|
$oldPane = $dashboard->getPane($form->getValue('org_pane'));
|
||||||
|
$oldPane->removeComponent($component->getTitle());
|
||||||
|
}
|
||||||
$dashboard->write();
|
$dashboard->write();
|
||||||
Notification::success(t('Component updated'));
|
Notification::success(t('Component updated'));
|
||||||
return true;
|
return true;
|
||||||
@ -130,7 +140,7 @@ class DashboardController extends ActionController
|
|||||||
}
|
}
|
||||||
$pane = $this->_request->getParam('pane');
|
$pane = $this->_request->getParam('pane');
|
||||||
$component = $this->_request->getParam('component');
|
$component = $this->_request->getParam('component');
|
||||||
$form->setOnSuccess(function (Request $request, Form $form) use ($dashboard, $component, $pane) {
|
$form->setOnSuccess(function (Form $form) use ($dashboard, $component, $pane) {
|
||||||
try {
|
try {
|
||||||
$pane = $dashboard->getPane($pane);
|
$pane = $dashboard->getPane($pane);
|
||||||
$pane->removeComponent($component);
|
$pane->removeComponent($component);
|
||||||
@ -162,7 +172,7 @@ class DashboardController extends ActionController
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
$pane = $this->_request->getParam('pane');
|
$pane = $this->_request->getParam('pane');
|
||||||
$form->setOnSuccess(function (Request $request, Form $form) use ($dashboard, $pane) {
|
$form->setOnSuccess(function (Form $form) use ($dashboard, $pane) {
|
||||||
try {
|
try {
|
||||||
$pane = $dashboard->getPane($pane);
|
$pane = $dashboard->getPane($pane);
|
||||||
$dashboard->removePane($pane->getTitle());
|
$dashboard->removePane($pane->getTitle());
|
||||||
|
@ -161,26 +161,6 @@ class ComponentForm extends Form
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adjust preferences and persist them
|
|
||||||
*
|
|
||||||
* @see Form::onSuccess()
|
|
||||||
*/
|
|
||||||
public function onSuccess(Request $request)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Populate data if any
|
|
||||||
*
|
|
||||||
* @see Form::onRequest()
|
|
||||||
*/
|
|
||||||
public function onRequest(Request $request)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Icinga\Web\Widget\Dashboard $dashboard
|
* @param \Icinga\Web\Widget\Dashboard $dashboard
|
||||||
*/
|
*/
|
||||||
|
@ -163,6 +163,26 @@ class Form extends Zend_Form
|
|||||||
parent::__construct($options);
|
parent::__construct($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a callback that is called instead of this form's onSuccess method
|
||||||
|
*
|
||||||
|
* It is called using the following signature: (Request $request, Form $form).
|
||||||
|
*
|
||||||
|
* @param callable $onSuccess Callback
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*
|
||||||
|
* @throws LogicException If the callback is not callable
|
||||||
|
*/
|
||||||
|
public function setOnSuccess($onSuccess)
|
||||||
|
{
|
||||||
|
if (! is_callable($onSuccess)) {
|
||||||
|
throw new LogicException('The option `onSuccess\' is not callable');
|
||||||
|
}
|
||||||
|
$this->onSuccess = $onSuccess;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the label to use for the standard submit button
|
* Set the label to use for the standard submit button
|
||||||
*
|
*
|
||||||
|
@ -6,6 +6,7 @@ namespace Icinga\Web\Widget;
|
|||||||
|
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
|
use Icinga\Data\ConfigObject;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
use Icinga\Exception\NotReadableError;
|
use Icinga\Exception\NotReadableError;
|
||||||
use Icinga\Exception\ProgrammingError;
|
use Icinga\Exception\ProgrammingError;
|
||||||
@ -102,7 +103,8 @@ class Dashboard extends AbstractWidget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = new Config($output);
|
$co = new ConfigObject($output);
|
||||||
|
$config = new Config($co);
|
||||||
$writer = new IniWriter(array('config' => $config, 'filename' => $configFile));
|
$writer = new IniWriter(array('config' => $config, 'filename' => $configFile));
|
||||||
$writer->write();
|
$writer->write();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user