IcingaTimePeriodForm: cleanup.

fixes #788
This commit is contained in:
Thomas Gelf 2018-10-30 18:54:28 +01:00
parent 46d3800014
commit 77f8f7d4ca
1 changed files with 37 additions and 60 deletions

View File

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