DataListEntry: Implement the datalistentry management

This commit is contained in:
Alexander Fuhr 2015-07-22 13:41:13 +02:00
parent 9bc8d3882e
commit 9af1b60dc9
7 changed files with 201 additions and 1 deletions

View File

@ -27,6 +27,9 @@ class Director_DatalistController extends ActionController
$this->getTabs()->add('editlist', array(
'url' => 'director/datalist/edit' . '?id=' . $id,
'label' => $this->view->title,
))->add('entries', array(
'url' => 'director/list/datalistentry' . '?list_id=' . $id,
'label' => $this->translate('List entries'),
))->activate('editlist');
} else {
$this->view->title = $this->translate('Add list');

View File

@ -0,0 +1,66 @@
<?php
use Icinga\Module\Director\Web\Controller\ActionController;
class Director_DatalistentryController extends ActionController
{
public function addAction()
{
$this->forward('index', 'datalistentry', 'director');
}
public function editAction()
{
$this->forward('index', 'datalistentry', 'director', array('edit' => true));
}
public function indexAction()
{
$request = $this->getRequest();
if ($request->getParam('edit')) {
$edit = true;
} else {
$edit = false;
}
$listId = $this->params->get('list_id');
$this->view->lastId = $listId;
if($this->params->get('list_id') && $entryName = $this->params->get('entry_name')) {
$edit = true;
}
if ($edit) {
$this->view->title = $this->translate('Edit entry');
$this->getTabs()->add('editentry', array(
'url' => 'director/datalistentry/edit' . '?list_id=' . $listId . '&entry_name=' . $entryName,
'label' => $this->view->title,
))->activate('editentry');
} else {
$this->view->title = $this->translate('Add entry');
$this->getTabs()->add('addlistentry', array(
'url' => 'director/datalistentry/add' . '?list_id=' . $listId,
'label' => $this->view->title,
))->activate('addlistentry');
}
$form = $this->view->form = $this->loadForm('directorDatalistentry')
->setSuccessUrl('director/datalistentry' . '?list_id=' . $listId)
->setDb($this->db());
if ($request->isPost()) {
$listId = $request->getParam('list_id');
$entryName = $request->getParam('entry_name');
}
if ($edit) {
$form->loadObject(array('list_id' => $listId, 'entry_name' => $entryName));
$form->getElement('entry_name')->setAttribs(array('readonly' => true));
}
$form->handleRequest();
$this->render('object/form', null, true);
}
}

View File

@ -46,6 +46,29 @@ class Director_ListController extends ActionController
$this->render('table');
}
public function datalistentryAction()
{
$listId = $this->params->get('list_id');
$this->view->lastId = $listId;
$this->view->addLink = $this->view->qlink(
$this->translate('Add entry'),
'director/datalistentry/add' . '?list_id=' . $listId
);
$this->view->title = $this->translate('List entries');
$this->getTabs()->add('editlist', array(
'url' => 'director/datalist/edit' . '?id=' . $listId,
'label' => $this->translate('Edit list'),
))->add('datalistentry', array(
'url' => 'director/datalistentry' . '?list_id=' . $listId,
'label' => $this->view->title,
))->activate('datalistentry');
$this->view->table = $this->loadTable('datalistEntry')->setConnection($this->db());
$this->render('table');
}
public function datafieldAction()
{
$this->view->addLink = $this->view->qlink(

View File

@ -0,0 +1,26 @@
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class DirectorDatalistEntryForm extends DirectorObjectForm
{
public function setup()
{
$this->addElement('text', 'entry_name', array(
'label' => 'Name'
));
$this->addElement('text', 'entry_value', array(
'label' => 'Value'
));
$this->addElement('select', 'format', array(
'label' => 'Type',
'multiOptions' => array('string' => $this->translate('String'))
));
$this->addElement('hidden', 'list_id', array(
'value' => $this->getRequest()->getParam('list_id'),
));
}
}

View File

@ -0,0 +1,51 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Web\Table\QuickTable;
class DatalistEntryTable extends QuickTable
{
public function getColumns()
{
return array(
'list_id' => 'l.list_id',
'entry_name' => 'l.entry_name',
'entry_value' => 'l.entry_value',
);
}
protected function getActionUrl($row)
{
return $this->url('director/datalistentry/edit', array(
'list_id' => $row->list_id,
'entry_name' => $row->entry_name,
));
}
public function getListId()
{
return $this->view()->lastId;
}
public function getTitles()
{
$view = $this->view();
return array(
'entry_name' => $view->translate('Name'),
'entry_value' => $view->translate('Value'),
);
}
public function fetchData()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('l' => 'director_datalist_entry'),
$this->getColumns()
)->where('l.list_id = ?', $this->getListId())->order('l.entry_name ASC');
return $db->fetchAll($query);
}
}

View File

@ -17,7 +17,7 @@ class DatalistTable extends QuickTable
protected function getActionUrl($row)
{
return $this->url('director/datalist/edit', array('id' => $row->id));
return $this->url('director/list/datalistentry', array('list_id' => $row->id));
}
public function getTitles()

View File

@ -0,0 +1,31 @@
<?php
namespace Icinga\Module\Director\Objects;
use Icinga\Module\Director\Data\Db\DbObject;
class DirectorDatalistEntry extends DbObject
{
protected $keyName = array('list_id', 'entry_name');
protected $table = 'director_datalist_entry';
protected $defaultProperties = array(
'list_id' => null,
'entry_name' => null,
'entry_value' => null,
'format' => null,
);
public function onInsert()
{
}
public function onUpdate()
{
}
public function onDelete()
{
}
}