mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2025-12-20 23:00:16 -05:00
QuickForm: a couple of small changes
This commit is contained in:
parent
7fcef19c6e
commit
98241dd9cd
1 changed files with 47 additions and 25 deletions
|
|
@ -8,6 +8,7 @@ use Icinga\Exception\ProgrammingError;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
use Icinga\Web\Request;
|
use Icinga\Web\Request;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
|
use Exception;
|
||||||
use Zend_Form;
|
use Zend_Form;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,8 +47,6 @@ abstract class QuickForm extends Zend_Form
|
||||||
|
|
||||||
protected $successUrl;
|
protected $successUrl;
|
||||||
|
|
||||||
protected $succeeded;
|
|
||||||
|
|
||||||
protected $successMessage;
|
protected $successMessage;
|
||||||
|
|
||||||
protected $submitLabel;
|
protected $submitLabel;
|
||||||
|
|
@ -76,6 +75,14 @@ abstract class QuickForm extends Zend_Form
|
||||||
$this->setAction(Url::fromRequest());
|
$this->setAction(Url::fromRequest());
|
||||||
$this->createIdElement();
|
$this->createIdElement();
|
||||||
$this->regenerateCsrfToken();
|
$this->regenerateCsrfToken();
|
||||||
|
$this->setDecorators(
|
||||||
|
array(
|
||||||
|
'Description',
|
||||||
|
array('FormErrors', array('onlyCustomFormErrors' => true)),
|
||||||
|
'FormElements',
|
||||||
|
'Form'
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function handleOptions($options = null)
|
protected function handleOptions($options = null)
|
||||||
|
|
@ -96,20 +103,22 @@ abstract class QuickForm extends Zend_Form
|
||||||
protected function addSubmitButtonIfSet()
|
protected function addSubmitButtonIfSet()
|
||||||
{
|
{
|
||||||
if (false !== ($label = $this->getSubmitLabel())) {
|
if (false !== ($label = $this->getSubmitLabel())) {
|
||||||
$el = $this->createElement('submit', $label)->setLabel($label)->removeDecorator('Label');
|
$el = $this->createElement('submit', $label)->setLabel($label)->setDecorators(array('ViewHelper'));
|
||||||
$this->submitButtonName = $el->getName();
|
$this->submitButtonName = $el->getName();
|
||||||
$this->addElement($el);
|
$this->addElement($el);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: This is ugly, we need to defer button creation
|
$grp = array(
|
||||||
protected function moveSubmitToBottom()
|
$this->submitButtonName,
|
||||||
{
|
$this->deleteButtonName
|
||||||
$name = $this->submitButtonName;
|
);
|
||||||
if ($name && ($submit = $this->getElement($name))) {
|
$this->addDisplayGroup($grp, 'buttons', array(
|
||||||
$this->removeElement($name);
|
'decorators' => array(
|
||||||
$this->addElement($submit);
|
'FormElements',
|
||||||
}
|
'DtDdWrapper',
|
||||||
|
),
|
||||||
|
'order' => 1000,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createIdElement()
|
protected function createIdElement()
|
||||||
|
|
@ -119,11 +128,10 @@ abstract class QuickForm extends Zend_Form
|
||||||
$this->getElement(self::ID)->setIgnore(true);
|
$this->getElement(self::ID)->setIgnore(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getSentValue($name, $default = null)
|
public function getSentValue($name, $default = null)
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
if ($request->isPost() && $this->hasBeenSent()) {
|
||||||
if ($request->isPost()) {
|
|
||||||
return $request->getPost($name);
|
return $request->getPost($name);
|
||||||
} else {
|
} else {
|
||||||
return $default;
|
return $default;
|
||||||
|
|
@ -208,17 +216,28 @@ abstract class QuickForm extends Zend_Form
|
||||||
) + $enum;
|
) + $enum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function succeeded()
|
public function setSuccessUrl($url, $params = null)
|
||||||
{
|
|
||||||
return $this->succeeded;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setSuccessUrl($url)
|
|
||||||
{
|
{
|
||||||
|
if (! $url instanceof Url) {
|
||||||
|
$url = Url::fromPath($url);
|
||||||
|
}
|
||||||
|
if ($params !== null) {
|
||||||
|
$url->setParams($params);
|
||||||
|
}
|
||||||
$this->successUrl = $url;
|
$this->successUrl = $url;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSuccessUrl()
|
||||||
|
{
|
||||||
|
$url = $this->successUrl ?: $this->getAction();
|
||||||
|
if (! $url instanceof Url) {
|
||||||
|
$url = Url::fromPath($url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
public function setup()
|
public function setup()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -292,11 +311,14 @@ abstract class QuickForm extends Zend_Form
|
||||||
if ($this->hasBeenSubmitted()) {
|
if ($this->hasBeenSubmitted()) {
|
||||||
$this->beforeValidation($post);
|
$this->beforeValidation($post);
|
||||||
if ($this->isValid($post)) {
|
if ($this->isValid($post)) {
|
||||||
$this->onSuccess();
|
try {
|
||||||
$this->succeeded = true;
|
$this->onSuccess();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->addError($e->getMessage());
|
||||||
|
$this->onFailure();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->onFailure();
|
$this->onFailure();
|
||||||
$this->succeeded = false;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->setDefaults($post);
|
$this->setDefaults($post);
|
||||||
|
|
@ -341,7 +363,7 @@ abstract class QuickForm extends Zend_Form
|
||||||
|
|
||||||
public function redirectOnSuccess($message = null)
|
public function redirectOnSuccess($message = null)
|
||||||
{
|
{
|
||||||
$url = $this->successUrl ?: $this->getAction();
|
$url = $this->getSuccessUrl();
|
||||||
$this->notifySuccess($this->getSuccessMessage($message));
|
$this->notifySuccess($this->getSuccessMessage($message));
|
||||||
$this->redirectAndExit($url);
|
$this->redirectAndExit($url);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue