diff --git a/application/forms/IcingaObjectFieldForm.php b/application/forms/IcingaObjectFieldForm.php new file mode 100644 index 00000000..a4ce9733 --- /dev/null +++ b/application/forms/IcingaObjectFieldForm.php @@ -0,0 +1,67 @@ +icingaObject = $object; + $this->className = get_class($object) . 'Field'; + return $this; + } + + public function setup() + { + $type = $this->icingaObject->getShortTableName(); + $this->addHidden($type . '_id', $this->icingaObject->id); + + $this->addHtmlHint( + 'Custom data fields allow you to easily fill custom variables with' + . " meaningful data. It's perfectly legal to override inherited fields." + . ' You may for example want to allow "network devices" specifying any' + . ' string for vars.snmp_community, but restrict "customer routers" to' + . ' a specific set, shown as a dropdown.' + ); + + $fields = $this->db->enumDatafields(); + $this->addElement('select', 'datafield_id', array( + 'label' => 'Field', + 'required' => true, + 'description' => 'Field to assign', + 'multiOptions' => $this->optionalEnum($fields) + )); + + if (empty($fields)) { + $msg = $this->translate( + 'There are no data fields available.' + . ' Please ask an administrator to create such' + ); + + $this->getElement('datafield_id')->setError($msg); + } + + $this->addElement('select', 'is_required', array( + 'label' => $this->translate('Mandatory'), + 'description' => $this->translate('Whether this field should be mandatory'), + 'required' => true, + 'multiOptions' => array( + 'n' => $this->translate('Optional'), + 'y' => $this->translate('Mandatory'), + ) + )); + + $this->setSubmitLabel( + $this->translate('Add new field') + ); + } +} diff --git a/application/tables/IcingaObjectDatafieldTable.php b/application/tables/IcingaObjectDatafieldTable.php new file mode 100644 index 00000000..e38aa8e6 --- /dev/null +++ b/application/tables/IcingaObjectDatafieldTable.php @@ -0,0 +1,68 @@ +object = $object; + $this->setConnection($object->getConnection()); + return $this; + } + + protected $searchColumns = array( + 'varname', + ); + + public function getColumns() + { + return array( + 'id' => 'f.id', + 'varname' => 'f.varname', + 'caption' => 'f.caption', + 'description' => 'f.description', + 'datatype' => 'f.datatype', + 'required' => "CASE WHEN of.is_required = 'y' THEN 'mandatory' ELSE 'optional' END", + ); + } + + protected function getActionUrl($row) + { + return $this->url('director/objectdatafield', array('id' => $row->id)); + } + + public function getTitles() + { + $view = $this->view(); + return array( + 'caption' => $view->translate('Label'), + 'varname' => $view->translate('Field name'), + 'required' => $view->translate('Required'), + ); + } + + public function getBaseQuery() + { + $db = $this->connection()->getConnection(); + $otable = $this->object->getTableName() . '_field'; + $oname = $this->object->getShortTableName(); + + $query = $db->select()->from( + array('of' => $otable), + array() + )->join( + array('f' => 'director_datafield'), + 'f.id = of.datafield_id', + array() + )->where('of.' . $oname . '_id = ?', $this->object->id) + ->order('caption ASC'); + + return $query; + } +} diff --git a/application/views/scripts/object/fields.phtml b/application/views/scripts/object/fields.phtml new file mode 100644 index 00000000..13979fd1 --- /dev/null +++ b/application/views/scripts/object/fields.phtml @@ -0,0 +1,9 @@ +