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\Web\Form\InvalidCSRFTokenException;
|
||||
use Zend_Form_Exception;
|
||||
use Zend_View_Interface;
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,6 +39,14 @@ use Icinga\Protocol\Commandpipe\Comment;
|
|||
*/
|
||||
class AcknowledgeForm extends ConfirmationForm
|
||||
{
|
||||
/**
|
||||
* Initialize form
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->setName('AcknowledgeForm');
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface method to build the form
|
||||
* @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(
|
||||
'checkbox',
|
||||
'expire',
|
||||
|
@ -74,26 +89,25 @@ class AcknowledgeForm extends ConfirmationForm
|
|||
)
|
||||
);
|
||||
|
||||
$now = new PhpDateTime();
|
||||
$interval = new DateInterval('PT1H'); // Add 3600 seconds
|
||||
$now->add($interval);
|
||||
if ($this->getRequest()->getPost('expire', '0') === '1') {
|
||||
$now = new PhpDateTime();
|
||||
$interval = new DateInterval('PT1H'); // Add 3600 seconds
|
||||
$now->add($interval);
|
||||
|
||||
$expireTime = new DateTime(
|
||||
array(
|
||||
'name' => 'expiretime',
|
||||
'label' => t('Expire time'),
|
||||
'value' => $now->format($this->getDateFormat())
|
||||
)
|
||||
);
|
||||
$expireTime = new DateTime(
|
||||
array(
|
||||
'name' => 'expiretime',
|
||||
'label' => t('Expire time'),
|
||||
'value' => $now->format($this->getDateFormat())
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElements(array($expireNote, $expireCheck, $expireTime));
|
||||
} else {
|
||||
$this->addElements(array($expireNote, $expireCheck));
|
||||
}
|
||||
|
||||
$expireNote = new Note(
|
||||
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->enableAutoSubmit(array('expire'));
|
||||
|
||||
$this->addDisplayGroup(
|
||||
array(
|
||||
|
|
|
@ -58,6 +58,14 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
*/
|
||||
const TYPE_FLEXIBLE = 'flexible';
|
||||
|
||||
/**
|
||||
* Initialize form
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->setName('ScheduleDowntimeForm');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'));
|
||||
$hoursText->setAttrib('style', 'width: 40px;');
|
||||
$hoursText->setValue(1);
|
||||
$hoursText->addDecorator('HtmlTag', array('tag' => 'dd', 'openOnly' => true));
|
||||
$hoursText->addDecorator(
|
||||
'Callback',
|
||||
array(
|
||||
'callback' => function () {
|
||||
return t('Hours');
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
if ($this->getRequest()->getPost('type') === self::TYPE_FLEXIBLE) {
|
||||
$hoursText = new Zend_Form_Element_Text('hours');
|
||||
$hoursText->setLabel(t('Flexible duration'));
|
||||
$hoursText->setAttrib('style', 'width: 40px;');
|
||||
$hoursText->setValue(1);
|
||||
$hoursText->addDecorator('HtmlTag', array('tag' => 'dd', 'openOnly' => true));
|
||||
$hoursText->addDecorator(
|
||||
'Callback',
|
||||
array(
|
||||
'callback' => function () {
|
||||
return t('Hours');
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$minutesText = new Zend_Form_Element_Text('minutes');
|
||||
$minutesText->setLabel(t('Minutes'));
|
||||
$minutesText->setAttrib('style', 'width: 40px;');
|
||||
$minutesText->setValue(0);
|
||||
$minutesText->removeDecorator('HtmlTag');
|
||||
$minutesText->removeDecorator('Label');
|
||||
$minutesText->addDecorator(
|
||||
'Callback',
|
||||
array(
|
||||
'callback' => function () {
|
||||
return t('Minutes');
|
||||
}
|
||||
)
|
||||
);
|
||||
$minutesText = new Zend_Form_Element_Text('minutes');
|
||||
$minutesText->setLabel(t('Minutes'));
|
||||
$minutesText->setAttrib('style', 'width: 40px;');
|
||||
$minutesText->setValue(0);
|
||||
$minutesText->removeDecorator('HtmlTag');
|
||||
$minutesText->removeDecorator('Label');
|
||||
$minutesText->addDecorator(
|
||||
'Callback',
|
||||
array(
|
||||
'callback' => function () {
|
||||
return t('Minutes');
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
$this->addElements(array($hoursText, $minutesText));
|
||||
$this->addElements(array($hoursText, $minutesText));
|
||||
}
|
||||
|
||||
if ($this->getWithChildren() === true) {
|
||||
$this->addNote(t('Schedule downtime for host and its services.'));
|
||||
|
|
Loading…
Reference in New Issue