DirectorDataList: Add controller, object etc.

This commit is contained in:
Alexander Fuhr 2015-07-03 14:00:40 +02:00
parent 644c6beeff
commit cfbe065b86
5 changed files with 74 additions and 1 deletions

View File

@ -0,0 +1,26 @@
<?php
use Icinga\Module\Director\Web\Controller\ActionController;
class Director_DatalistController extends ActionController
{
public function indexAction()
{
$this->view->title = $this->translate('Add list');
$this->getTabs()->add('addlist', array(
'url' => 'director/data/addlist',
'label' => $this->view->title,
))->activate('addlist');
$form = $this->view->form = $this->loadForm('directorDatalist')
->setSuccessUrl('director/list/datalist')
->setDb($this->db());
if ($id = $this->params->get('id')) {
$form->loadObject($id);
}
$form->handleRequest();
$this->render('object/form', null, true);
}
}

View File

@ -14,6 +14,11 @@ class Director_ListController extends ActionController
public function datalistAction()
{
$this->view->addLink = $this->view->qlink(
$this->translate('Add list'),
'director/datalist'
);
$this->setConfigTabs()->activate('datalist');
$this->view->title = $this->translate('Data lists');
$this->view->table = $this->loadTable('datalist')->setConnection($this->db());

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
use Icinga\Authentication\Manager as Auth;
class DirectorDatalistForm extends DirectorObjectForm
{
@ -11,5 +12,26 @@ class DirectorDatalistForm extends DirectorObjectForm
$this->addElement('text', 'list_name', array(
'label' => $this->translate('List name')
));
$this->addElement('hidden', 'owner');
}
public function onSuccess()
{
$this->getElement('owner')->setValue(
self::username()
);
parent::onSuccess();
}
protected static function username()
{
$auth = Auth::getInstance();
if ($auth->isAuthenticated()) {
return $auth->getUser()->getUsername();
} else {
return '<unknown>';
}
}
}

View File

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

View File

@ -0,0 +1,20 @@
<?php
namespace Icinga\Module\Director\Objects;
use Icinga\Module\Director\Data\Db\DbObject;
class DirectorDatalist extends DbObject
{
protected $table = 'director_datalist';
protected $keyName = 'id';
protected $autoincKeyName = 'id';
protected $defaultProperties = array(
'id' => null,
'list_name' => null,
'owner' => null
);
}