mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 16:54:04 +02:00
Enable dynamic form elements
Expire time of the AcknowledgeForm and hours as well as minutes of the ScheduleDowntimeForm are now dynamic. refs #4439
This commit is contained in:
parent
98e7ab02db
commit
fa7379adc7
@ -27,7 +27,6 @@ namespace Icinga\Web;
|
|||||||
|
|
||||||
use Icinga\Exception\ProgrammingError;
|
use Icinga\Exception\ProgrammingError;
|
||||||
use Icinga\Web\Form\InvalidCSRFTokenException;
|
use Icinga\Web\Form\InvalidCSRFTokenException;
|
||||||
use Zend_Form_Exception;
|
|
||||||
use Zend_View_Interface;
|
use Zend_View_Interface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,6 +39,14 @@ use Icinga\Protocol\Commandpipe\Comment;
|
|||||||
*/
|
*/
|
||||||
class AcknowledgeForm extends ConfirmationForm
|
class AcknowledgeForm extends ConfirmationForm
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Initialize form
|
||||||
|
*/
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->setName('AcknowledgeForm');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface method to build the form
|
* Interface method to build the form
|
||||||
* @see ConfirmationForm::create
|
* @see ConfirmationForm::create
|
||||||
@ -66,6 +74,13 @@ class AcknowledgeForm extends ConfirmationForm
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$expireNote = new Note(
|
||||||
|
array(
|
||||||
|
'name' => 'expirenote',
|
||||||
|
'value' => t('If the acknowledgement should expire, check the box and enter an expiration timestamp.')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$expireCheck = $this->createElement(
|
$expireCheck = $this->createElement(
|
||||||
'checkbox',
|
'checkbox',
|
||||||
'expire',
|
'expire',
|
||||||
@ -74,26 +89,25 @@ class AcknowledgeForm extends ConfirmationForm
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$now = new PhpDateTime();
|
if ($this->getRequest()->getPost('expire', '0') === '1') {
|
||||||
$interval = new DateInterval('PT1H'); // Add 3600 seconds
|
$now = new PhpDateTime();
|
||||||
$now->add($interval);
|
$interval = new DateInterval('PT1H'); // Add 3600 seconds
|
||||||
|
$now->add($interval);
|
||||||
|
|
||||||
$expireTime = new DateTime(
|
$expireTime = new DateTime(
|
||||||
array(
|
array(
|
||||||
'name' => 'expiretime',
|
'name' => 'expiretime',
|
||||||
'label' => t('Expire time'),
|
'label' => t('Expire time'),
|
||||||
'value' => $now->format($this->getDateFormat())
|
'value' => $now->format($this->getDateFormat())
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->addElements(array($expireNote, $expireCheck, $expireTime));
|
||||||
|
} else {
|
||||||
|
$this->addElements(array($expireNote, $expireCheck));
|
||||||
|
}
|
||||||
|
|
||||||
$expireNote = new Note(
|
$this->enableAutoSubmit(array('expire'));
|
||||||
array(
|
|
||||||
'name' => 'expirenote',
|
|
||||||
'value' => t('If the acknowledgement should expire, check the box and enter an expiration timestamp.')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->addElements(array($expireNote, $expireCheck, $expireTime));
|
|
||||||
|
|
||||||
$this->addDisplayGroup(
|
$this->addDisplayGroup(
|
||||||
array(
|
array(
|
||||||
|
@ -58,6 +58,14 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||||||
*/
|
*/
|
||||||
const TYPE_FLEXIBLE = 'flexible';
|
const TYPE_FLEXIBLE = 'flexible';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize form
|
||||||
|
*/
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->setName('ScheduleDowntimeForm');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build an array of timestamps
|
* Build an array of timestamps
|
||||||
*
|
*
|
||||||
@ -178,37 +186,41 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$this->enableAutoSubmit(array('type'));
|
||||||
|
|
||||||
$hoursText = new Zend_Form_Element_Text('hours');
|
|
||||||
$hoursText->setLabel(t('Flexible duration'));
|
if ($this->getRequest()->getPost('type') === self::TYPE_FLEXIBLE) {
|
||||||
$hoursText->setAttrib('style', 'width: 40px;');
|
$hoursText = new Zend_Form_Element_Text('hours');
|
||||||
$hoursText->setValue(1);
|
$hoursText->setLabel(t('Flexible duration'));
|
||||||
$hoursText->addDecorator('HtmlTag', array('tag' => 'dd', 'openOnly' => true));
|
$hoursText->setAttrib('style', 'width: 40px;');
|
||||||
$hoursText->addDecorator(
|
$hoursText->setValue(1);
|
||||||
'Callback',
|
$hoursText->addDecorator('HtmlTag', array('tag' => 'dd', 'openOnly' => true));
|
||||||
array(
|
$hoursText->addDecorator(
|
||||||
'callback' => function () {
|
'Callback',
|
||||||
return t('Hours');
|
array(
|
||||||
}
|
'callback' => function () {
|
||||||
)
|
return t('Hours');
|
||||||
);
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$minutesText = new Zend_Form_Element_Text('minutes');
|
$minutesText = new Zend_Form_Element_Text('minutes');
|
||||||
$minutesText->setLabel(t('Minutes'));
|
$minutesText->setLabel(t('Minutes'));
|
||||||
$minutesText->setAttrib('style', 'width: 40px;');
|
$minutesText->setAttrib('style', 'width: 40px;');
|
||||||
$minutesText->setValue(0);
|
$minutesText->setValue(0);
|
||||||
$minutesText->removeDecorator('HtmlTag');
|
$minutesText->removeDecorator('HtmlTag');
|
||||||
$minutesText->removeDecorator('Label');
|
$minutesText->removeDecorator('Label');
|
||||||
$minutesText->addDecorator(
|
$minutesText->addDecorator(
|
||||||
'Callback',
|
'Callback',
|
||||||
array(
|
array(
|
||||||
'callback' => function () {
|
'callback' => function () {
|
||||||
return t('Minutes');
|
return t('Minutes');
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addElements(array($hoursText, $minutesText));
|
$this->addElements(array($hoursText, $minutesText));
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->getWithChildren() === true) {
|
if ($this->getWithChildren() === true) {
|
||||||
$this->addNote(t('Schedule downtime for host and its services.'));
|
$this->addNote(t('Schedule downtime for host and its services.'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user