ScheduledDowntimes: controllers, first form

This commit is contained in:
Thomas Gelf 2018-06-14 17:51:48 +02:00
parent 3cb4a0cbe9
commit 0c2cb9e484
4 changed files with 96 additions and 1 deletions

View File

@ -0,0 +1,38 @@
<?php
namespace Icinga\Module\Director\Controllers;
use Icinga\Module\Director\Forms\IcingaScheduledDowntimeRangeForm;
use Icinga\Module\Director\Objects\IcingaScheduledDowntime;
use Icinga\Module\Director\Web\Controller\ObjectController;
use Icinga\Module\Director\Web\Table\IcingaScheduledDowntimeTable;
class ScheduledDowntimeController extends ObjectController
{
public function rangesAction()
{
/** @var IcingaScheduledDowntime $object */
$object = $this->object;
$this->tabs()->activate('ranges');
$this->addTitle($this->translate('Time period ranges'));
$form = IcingaScheduledDowntimeRangeForm::load()
->setTimePeriod($object);
if (null !== ($name = $this->params->get('range'))) {
$this->addBackLink($this->url()->without('range'));
$form->loadObject([
'scheduled_downtime_id' => $object->get('id'),
'range_key' => $name,
'range_type' => $this->params->get('range_type')
]);
}
$this->content()->add($form->handleRequest());
IcingaScheduledDowntimeTable::load($object)->renderTo($this);
}
public function getType()
{
return 'scheduledDowntime';
}
}

View File

@ -6,4 +6,13 @@ use Icinga\Module\Director\Web\Controller\ObjectsController;
class ScheduledDowntimesController extends ObjectsController
{
public function getType()
{
return 'scheduledDowntime';
}
public function getBaseObjectUrl()
{
return 'scheduled-downtime';
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaScheduledDowntimeForm extends DirectorObjectForm
{
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('Object'),
'template' => $this->translate('Template'),
))
));
if ($isTemplate) {
$this->addElement('text', 'object_name', array(
'label' => $this->translate('Template name'),
'required' => true,
));
} else {
$this->addElement('text', 'object_name', array(
'label' => $this->translate('Downtime name'),
'required' => true,
));
}
$this->addElement('text', 'display_name', array(
'label' => $this->translate('Display Name'),
'description' => $this->translate('the display name')
));
$this->addImportsElement();
$this->setButtons();
}
}

View File

@ -106,7 +106,7 @@ abstract class ObjectsController extends ActionController
->addObjectsTabs()
->setAutorefreshInterval(10)
->addTitle($this->translate(ucfirst($this->getPluralType())))
->actions(new ObjectsActionBar($type, $this->url()));
->actions(new ObjectsActionBar($this->getBaseObjectUrl(), $this->url()));
if ($type === 'command' && $this->params->get('type') === 'external_object') {
$this->tabs()->activate('external');
@ -429,6 +429,11 @@ abstract class ObjectsController extends ActionController
}
}
protected function getBaseObjectUrl()
{
return $this->getType();
}
/**
* @return string
*/