ObjectForm: do not allow to choose type...

...when one is already given
This commit is contained in:
Thomas Gelf 2016-10-13 11:53:01 +00:00
parent c1afda4392
commit 0e45429196
3 changed files with 33 additions and 7 deletions

View File

@ -184,10 +184,21 @@ abstract class ObjectController extends ActionController
->setApi($this->getApiIfAvailable())
->setSuccessUrl($url);
if ($type = $this->params->shift('type')) {
$form->setPreferredObjectType($type);
}
if ($type === 'template') {
$this->view->title = sprintf(
$this->translate('Add new Icinga %s template'),
ucfirst($ltype)
);
} else {
$this->view->title = sprintf(
$this->translate('Add new Icinga %s'),
ucfirst($ltype)
);
}
$this->beforeHandlingAddRequest($form);

View File

@ -104,12 +104,10 @@ abstract class ObjectsController extends ActionController
$addParams = array('type' => 'template');
$this->getTabs()->activate('templates');
$title = $this->translate('Icinga ' . ucfirst($ltype) . ' Templates');
$addTitle = $this->translate('Add %s template');
$table->enforceFilter(Filter::expression('object_type', '=', 'template'));
} else {
$addParams = array('type' => 'object');
$title = $this->translate('Icinga ' . ucfirst($ltype) . 's');
$addTitle = $this->translate('Add %s');
if ($dummy->supportsImports()
&& array_key_exists('object_type', $table->getColumns())
&& ! in_array(ucfirst($type), $this->globalTypes)
@ -121,7 +119,7 @@ abstract class ObjectsController extends ActionController
$this->view->title = $title;
$this->view->addLink = $this->view->qlink(
sprintf($addTitle, $this->translate(ucfirst($ltype))),
$this->translate('Add'),
'director/' . $ltype .'/add',
$addParams,
array('class' => 'icon-plus')

View File

@ -30,14 +30,26 @@ abstract class DirectorObjectForm extends QuickForm
protected $listUrl;
protected $preferredObjectType;
private $allowsExperimental;
private $api;
public function setPreferredObjectType($type)
{
$this->preferredObjectType = $type;
return $this;
}
protected function object($values = array())
{
if ($this->object === null) {
$class = $this->getObjectClassname();
if ($this->preferredObjectType && ! array_key_exists('object_type', $values)) {
$values['object_type'] = $this->preferredObjectType;
}
$this->object = $class::create($values, $this->db);
foreach ($this->getValues() as $key => $value) {
if ($this->object->hasProperty($key)) {
@ -1056,6 +1068,11 @@ abstract class DirectorObjectForm extends QuickForm
return;
}
if ($this->preferredObjectType) {
$this->addHidden('object_type', $this->preferredObjectType);
return $this;
}
$object = $this->object();
if ($object->supportsImports()) {