Notification: form and rendering improvements

This commit is contained in:
Thomas Gelf 2016-03-12 01:35:24 +01:00
parent 8b903486d3
commit f971839f82
3 changed files with 123 additions and 0 deletions

View File

@ -22,9 +22,91 @@ class IcingaNotificationForm extends DirectorObjectForm
$this->addDisabledElement()
->addImportsElement()
->addIntervalElement()
->addPeriodElement()
->addTimesElements()
->addDisabledElement()
->addCommandElements()
->addEventFilterElements()
->groupMainProperties()
->setButtons();
}
protected function addIntervalElement()
{
$this->addElement(
'text',
'notification_interval',
array(
'label' => $this->translate('Notification interval'),
'description' => $this->translate(
'The notification interval (in seconds). This interval is'
. ' used for active notifications. Defaults to 30 minutes.'
. ' If set to 0, re-notifications are disabled.'
)
)
);
return $this;
}
protected function addTimesElements()
{
$this->addElement(
'text',
'times_begin',
array(
'label' => $this->translate('First notification delay'),
'description' => $this->translate(
'Delay unless the first notification should be sent'
)
)
);
$this->addElement(
'text',
'times_end',
array(
'label' => $this->translate('Times end'),
'description' => $this->translate(
'When the last notification should be sent'
)
)
);
return $this;
}
protected function addPeriodElement()
{
$this->addElement(
'select',
'period',
array(
'label' => $this->translate('Time period'),
'description' => $this->translate(
'The name of a time period which determines when this'
. ' notification should be triggered. Not set by default.'
)
)
);
return $this;
}
protected function addCommandElements()
{
if (! $this->isTemplate()) {
return $this;
}
$this->addElement('select', 'command_id', array(
'label' => $this->translate('Notification command'),
'description' => $this->translate('Check command definition'),
'multiOptions' => $this->optionalEnum($this->db->enumNotificationCommands()),
'class' => 'autosubmit',
));
return $this;
}
}

View File

@ -2,6 +2,8 @@
namespace Icinga\Module\Director\Objects;
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
class IcingaNotification extends IcingaObject
{
protected $table = 'icinga_notification';
@ -42,7 +44,44 @@ class IcingaNotification extends IcingaObject
'period' => 'IcingaTimePeriod',
);
protected $intervalProperties = array(
'notification_interval' => 'notification_interval',
'times_begin' => 'times_begin',
'times_end' => 'times_end',
);
// listOfRelations -> users, user_groups
protected function renderTimes_begin()
{
$times = (object) array(
'begin' => c::renderInterval($this->times_begin)
);
if ($this->times_end !== null) {
$times->end = c::renderInterval($this->times_end);
}
return c::renderKeyValue(
'times',
c::renderDictionary($times)
);
}
protected function renderTimes_end()
{
if ($this->times_begin !== null) {
return '';
}
$times = (object) array(
'end' => c::renderInterval($this->times_end)
);
return c::renderKeyValue(
'times',
c::renderDictionary($times)
);
}
protected function setKey($key)
{

View File

@ -416,6 +416,8 @@ abstract class DirectorObjectForm extends QuickForm
'address6',
'groups',
'command_id', // Notification
'notification_interval',
'period',
'email',
'pager',
'enable_notifications',