ObjectController: allow for graceful tabs
This commit is contained in:
parent
d01194a7b4
commit
d1af897114
|
@ -21,7 +21,7 @@ class CommandController extends ObjectController
|
|||
|
||||
public function argumentsAction()
|
||||
{
|
||||
$this->getTabs()->activate('arguments');
|
||||
$this->gracefullyActivateTab('arguments');
|
||||
$this->view->title = sprintf(
|
||||
$this->translate('Command arguments: %s'),
|
||||
$this->object->object_name
|
||||
|
|
|
@ -75,7 +75,7 @@ class HostController extends ObjectController
|
|||
|
||||
public function agentAction()
|
||||
{
|
||||
$this->getTabs()->activate('agent');
|
||||
$this->gracefullyActivateTab('agent');
|
||||
$this->view->title = 'Agent deployment instructions';
|
||||
// TODO: Fail when no ticket
|
||||
$this->view->certname = $this->object->object_name;
|
||||
|
|
|
@ -53,16 +53,14 @@ abstract class ObjectController extends ActionController
|
|||
'label' => $this->translate('History')
|
||||
));
|
||||
|
||||
if ($object->hasBeenLoadedFromDb()
|
||||
&& $object->supportsFields()
|
||||
&& ($object->isTemplate() || $type === 'command')
|
||||
) {
|
||||
if ($this->hasFields()) {
|
||||
$tabs->add('fields', array(
|
||||
'url' => sprintf('director/%s/fields', $type),
|
||||
'urlParams' => $params,
|
||||
'label' => $this->translate('Fields')
|
||||
));
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->beforeTabs();
|
||||
$this->getTabs()->add('add', array(
|
||||
|
@ -337,6 +335,17 @@ abstract class ObjectController extends ActionController
|
|||
return $this->object;
|
||||
}
|
||||
|
||||
protected function hasFields()
|
||||
{
|
||||
if (! ($object = $this->object)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $object->hasBeenLoadedFromDb()
|
||||
&& $object->supportsFields()
|
||||
&& ($object->isTemplate() || $this->getType() === 'command');
|
||||
}
|
||||
|
||||
protected function handleApiRequest()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
@ -434,6 +443,20 @@ abstract class ObjectController extends ActionController
|
|||
}
|
||||
}
|
||||
|
||||
protected function gracefullyActivateTab($name)
|
||||
{
|
||||
$tabs = $this->getTabs();
|
||||
|
||||
if ($tabs->has($name)) {
|
||||
return $tabs->activate($name);
|
||||
}
|
||||
|
||||
$req = $this->getRequest();
|
||||
$this->redirectNow(
|
||||
$req->getUrl()->setPath('director/' . $req->getControllerName())
|
||||
);
|
||||
}
|
||||
|
||||
protected function beforeTabs()
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue