mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
DirectorDatafield: introduce new object class...
...and adjust table, form and controller
This commit is contained in:
parent
5f3c85d202
commit
644c6beeff
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||
use Icinga\Module\Director\Forms\DirectorDatafieldForm;
|
||||
|
||||
class Director_DataController extends ActionController
|
||||
{
|
||||
public function addfieldAction()
|
||||
{
|
||||
$title = $this->translate('Add field');
|
||||
$this->getTabs()->add('addfield', array(
|
||||
'url' => 'director/data/addfield',
|
||||
'label' => $title,
|
||||
))->activate('addfield');
|
||||
|
||||
$form = new DirectorDatafieldForm();
|
||||
$form->setDb($this->db());
|
||||
|
||||
$form->handleRequest();
|
||||
|
||||
$this->view->title = $title;
|
||||
$this->view->form = $form;
|
||||
}
|
||||
}
|
26
application/controllers/DatafieldController.php
Normal file
26
application/controllers/DatafieldController.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||
|
||||
class Director_DatafieldController extends ActionController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$this->view->title = $this->translate('Add field');
|
||||
$this->getTabs()->add('addfield', array(
|
||||
'url' => 'director/data/addfield',
|
||||
'label' => $this->view->title,
|
||||
))->activate('addfield');
|
||||
|
||||
$form = $this->view->form = $this->loadForm('directorDatafield')
|
||||
->setSuccessUrl('director/list/datafield')
|
||||
->setDb($this->db());
|
||||
|
||||
if ($id = $this->params->get('id')) {
|
||||
$form->loadObject($id);
|
||||
}
|
||||
$form->handleRequest();
|
||||
|
||||
$this->render('object/form', null, true);
|
||||
}
|
||||
}
|
@ -24,10 +24,9 @@ class Director_ListController extends ActionController
|
||||
{
|
||||
$this->view->addLink = $this->view->qlink(
|
||||
$this->translate('Add field'),
|
||||
'director/data/addfield'
|
||||
'director/datafield'
|
||||
);
|
||||
|
||||
$this->setConfigTabs()->activate('generatedconfig');
|
||||
$this->setConfigTabs()->activate('datafield');
|
||||
$this->view->title = $this->translate('Data fields');
|
||||
$this->view->table = $this->loadTable('datafield')->setConnection($this->db());
|
||||
|
@ -2,13 +2,10 @@
|
||||
|
||||
namespace Icinga\Module\Director\Forms;
|
||||
|
||||
use Icinga\Module\Director\Web\Form\QuickForm;
|
||||
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
||||
|
||||
class DirectorDatafieldForm extends QuickForm
|
||||
class DirectorDatafieldForm extends DirectorObjectForm
|
||||
{
|
||||
protected $db;
|
||||
protected $successUrl = 'director/list/datafield';
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->addElement('text', 'varname', array(
|
||||
@ -37,27 +34,4 @@ class DirectorDatafieldForm extends QuickForm
|
||||
'description' => $this->translate('Field format (string, json, expression)')
|
||||
));
|
||||
}
|
||||
|
||||
public function onSuccess()
|
||||
{
|
||||
$values = $this->getValues();
|
||||
|
||||
$this->db->insert(
|
||||
'director_datafield',
|
||||
array(
|
||||
'varname' => $values['varname'],
|
||||
'caption' => $values['caption'],
|
||||
'description' => $values['description'],
|
||||
'datatype' => $values['datatype'],
|
||||
'format' => $values['format'],
|
||||
)
|
||||
);
|
||||
|
||||
parent::onSuccess('Ding dong');
|
||||
}
|
||||
|
||||
public function setDb($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class DatafieldTable extends QuickTable
|
||||
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return $this->url('director/show/datafield', array('id' => $row->id));
|
||||
return $this->url('director/datafield', array('id' => $row->id));
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
|
@ -1,8 +0,0 @@
|
||||
<div class="controls">
|
||||
<?= $this->tabs ?>
|
||||
<h1><?= $this->escape($this->title) ?></h1>
|
||||
</div>
|
||||
|
||||
<div class="content" data-base-target="_next">
|
||||
<?= $form; ?>
|
||||
</div>
|
23
library/Director/Objects/DirectorDatafield.php
Normal file
23
library/Director/Objects/DirectorDatafield.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Objects;
|
||||
|
||||
use Icinga\Module\Director\Data\Db\DbObject;
|
||||
|
||||
class DirectorDatafield extends DbObject
|
||||
{
|
||||
protected $table = 'director_datafield';
|
||||
|
||||
protected $keyName = 'id';
|
||||
|
||||
protected $autoincKeyName = 'id';
|
||||
|
||||
protected $defaultProperties = array(
|
||||
'id' => null,
|
||||
'varname' => null,
|
||||
'caption' => null,
|
||||
'description' => null,
|
||||
'datatype' => null,
|
||||
'format' => null,
|
||||
);
|
||||
}
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace Icinga\Module\Director\Web\Form;
|
||||
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
|
||||
abstract class DirectorObjectForm extends QuickForm
|
||||
{
|
||||
protected $db;
|
||||
@ -26,7 +28,13 @@ abstract class DirectorObjectForm extends QuickForm
|
||||
|
||||
protected function onSetup()
|
||||
{
|
||||
if ($this->object()->supportsCustomVars()) {
|
||||
$object = $this->object();
|
||||
|
||||
if (! $object instanceof IcingaObject) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($object->supportsCustomVars()) {
|
||||
$this->addElement('note', '_newvar_hint', array('label' => 'New custom variable'));
|
||||
$this->addElement('text', '_newvar_name', array(
|
||||
'label' => 'Name'
|
||||
@ -40,7 +48,7 @@ abstract class DirectorObjectForm extends QuickForm
|
||||
));
|
||||
}
|
||||
|
||||
if (false && $this->object()->supportsRanges()) {
|
||||
if (false && $object->supportsRanges()) {
|
||||
/* TODO implement when new logic is there
|
||||
$this->addElement('note', '_newrange_hint', array('label' => 'New range'));
|
||||
$this->addElement('text', '_newrange_name', array(
|
||||
@ -53,9 +61,8 @@ abstract class DirectorObjectForm extends QuickForm
|
||||
}
|
||||
}
|
||||
|
||||
public function onSuccess()
|
||||
protected function handleIcingaObject(& $values)
|
||||
{
|
||||
$values = $this->getValues();
|
||||
$object = $this->object();
|
||||
$handled = array();
|
||||
|
||||
@ -117,7 +124,15 @@ abstract class DirectorObjectForm extends QuickForm
|
||||
foreach ($handled as $key => $value) {
|
||||
unset($values[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
public function onSuccess()
|
||||
{
|
||||
$object = $this->object;
|
||||
$values = $this->getValues();
|
||||
if ($object instanceof IcingaObject) {
|
||||
$this->handleIcingaObject($values);
|
||||
}
|
||||
$object->setProperties($values);
|
||||
$msg = sprintf(
|
||||
$object->hasBeenLoadedFromDb()
|
||||
@ -192,6 +207,9 @@ abstract class DirectorObjectForm extends QuickForm
|
||||
$this->addHidden('id');
|
||||
}
|
||||
$this->setDefaults($this->object->getProperties());
|
||||
if (! $this->object instanceof IcingaObject) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($submit = $this->getElement('submit')) {
|
||||
$this->removeElement('submit');
|
||||
|
Loading…
x
Reference in New Issue
Block a user