DataField: Impelement - Add Field
This commit is contained in:
parent
899f8bc984
commit
5f3c85d202
|
@ -14,6 +14,9 @@ class Director_DataController extends ActionController
|
|||
))->activate('addfield');
|
||||
|
||||
$form = new DirectorDatafieldForm();
|
||||
$form->setDb($this->db());
|
||||
|
||||
$form->handleRequest();
|
||||
|
||||
$this->view->title = $title;
|
||||
$this->view->form = $form;
|
||||
|
|
|
@ -6,9 +6,13 @@ use Icinga\Module\Director\Web\Form\QuickForm;
|
|||
|
||||
class DirectorDatafieldForm extends QuickForm
|
||||
{
|
||||
protected $db;
|
||||
protected $successUrl = 'director/list/datafield';
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->addElement('text', 'varname', array(
|
||||
'required' => true,
|
||||
'label' => $this->translate('Field name'),
|
||||
'description' => $this->translate('The unique name of the field')
|
||||
));
|
||||
|
@ -25,12 +29,35 @@ class DirectorDatafieldForm extends QuickForm
|
|||
|
||||
$this->addElement('text', 'datatype', array(
|
||||
'label' => $this->translate('Data type'),
|
||||
'description' => $this->translate('Field format')
|
||||
'description' => $this->translate('Field type')
|
||||
));
|
||||
|
||||
$this->addElement('text', 'format', array(
|
||||
'label' => $this->translate('Format'),
|
||||
'description' => $this->translate('Field format')
|
||||
'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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue