parent
46d3800014
commit
77f8f7d4ca
|
@ -6,44 +6,25 @@ use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
|||
|
||||
class IcingaTimePeriodForm extends DirectorObjectForm
|
||||
{
|
||||
/**
|
||||
* @throws \Zend_Form_Exception
|
||||
*/
|
||||
public function setup()
|
||||
{
|
||||
$isTemplate = isset($_POST['object_type']) && $_POST['object_type'] === 'template';
|
||||
$this->addElement('select', 'object_type', array(
|
||||
'label' => $this->translate('Object type'),
|
||||
'description' => $this->translate('Whether this should be a template'),
|
||||
'class' => 'autosubmit',
|
||||
'multiOptions' => $this->optionalEnum(array(
|
||||
'object' => $this->translate('Timeperiod object'),
|
||||
'template' => $this->translate('Timeperiod template'),
|
||||
))
|
||||
));
|
||||
$this->addElement('text', 'object_name', [
|
||||
'label' => $this->translate('Name'),
|
||||
'required' => true,
|
||||
]);
|
||||
|
||||
if ($isTemplate) {
|
||||
$this->addElement('text', 'object_name', array(
|
||||
'label' => $this->translate('Timeperiod template name'),
|
||||
'required' => true,
|
||||
'description' => $this->translate('Name for the Icinga timperiod template you are going to create')
|
||||
));
|
||||
} else {
|
||||
$this->addElement('text', 'object_name', array(
|
||||
'label' => $this->translate('Timeperiod'),
|
||||
'required' => true,
|
||||
'description' => $this->translate('Name for the Icinga timeperiod you are going to create')
|
||||
));
|
||||
}
|
||||
|
||||
$this->addElement('text', 'display_name', array(
|
||||
$this->addElement('text', 'display_name', [
|
||||
'label' => $this->translate('Display Name'),
|
||||
'description' => $this->translate('the display name')
|
||||
));
|
||||
]);
|
||||
|
||||
if ($this->isTemplate()) {
|
||||
$this->addElement('text', 'update_method', array(
|
||||
'label' => $this->translate('Update Method'),
|
||||
'description' => $this->translate('the update method'),
|
||||
'value' => 'LegacyTimePeriod',
|
||||
));
|
||||
$this->addElement('text', 'update_method', [
|
||||
'label' => $this->translate('Update Method'),
|
||||
'value' => 'LegacyTimePeriod',
|
||||
]);
|
||||
} else {
|
||||
// TODO: I'd like to skip this for objects inheriting from a template
|
||||
// with a defined update_method. However, unfortunately it's too
|
||||
|
@ -52,13 +33,15 @@ class IcingaTimePeriodForm extends DirectorObjectForm
|
|||
$this->addHidden('update_method', 'LegacyTimePeriod');
|
||||
}
|
||||
|
||||
$this->addIncludeExclude();
|
||||
|
||||
$this->addImportsElement();
|
||||
|
||||
$this->setButtons();
|
||||
$this->addIncludeExclude()
|
||||
->addImportsElement()
|
||||
->setButtons();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @throws \Zend_Form_Exception
|
||||
*/
|
||||
protected function addIncludeExclude()
|
||||
{
|
||||
$periods = [];
|
||||
|
@ -69,37 +52,31 @@ class IcingaTimePeriodForm extends DirectorObjectForm
|
|||
}
|
||||
|
||||
if (empty($periods)) {
|
||||
return;
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->addElement(
|
||||
'extensibleSet',
|
||||
'includes',
|
||||
array(
|
||||
'label' => $this->translate('Include period'),
|
||||
'description' => $this->translate(
|
||||
'Include other time periods into this.'
|
||||
),
|
||||
'multiOptions' => $this->optionalEnum($periods),
|
||||
)
|
||||
);
|
||||
$this->addElement('extensibleSet', 'includes', [
|
||||
'label' => $this->translate('Include period'),
|
||||
'multiOptions' => $this->optionalEnum($periods),
|
||||
'description' => $this->translate(
|
||||
'Include other time periods into this.'
|
||||
),
|
||||
]);
|
||||
|
||||
$this->addElement(
|
||||
'extensibleSet',
|
||||
'excludes',
|
||||
array(
|
||||
'label' => $this->translate('Exclude period'),
|
||||
'description' => $this->translate(
|
||||
'Exclude other time periods from this.'
|
||||
),
|
||||
'multiOptions' => $this->optionalEnum($periods),
|
||||
)
|
||||
);
|
||||
$this->addElement('extensibleSet', 'excludes', [
|
||||
'label' => $this->translate('Exclude period'),
|
||||
'multiOptions' => $this->optionalEnum($periods),
|
||||
'description' => $this->translate(
|
||||
'Exclude other time periods from this.'
|
||||
),
|
||||
]);
|
||||
|
||||
$this->optionalBoolean(
|
||||
'prefer_includes',
|
||||
$this->translate('Prefer includes'),
|
||||
$this->translate('Whether to prefer timeperiods includes or excludes. Default to true.')
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue