diff --git a/library/Director/Web/Controller/ObjectsController.php b/library/Director/Web/Controller/ObjectsController.php index d884521d..0eb8789d 100644 --- a/library/Director/Web/Controller/ObjectsController.php +++ b/library/Director/Web/Controller/ObjectsController.php @@ -19,6 +19,7 @@ use Icinga\Module\Director\Web\Table\TemplatesTable; use Icinga\Module\Director\Web\Tabs\ObjectsTabs; use Icinga\Module\Director\Web\Tree\TemplateTreeRenderer; use dipl\Html\Link; +use Icinga\Module\Director\Web\Widget\AdditionalTableActions; abstract class ObjectsController extends ActionController { @@ -91,6 +92,8 @@ abstract class ObjectsController extends ActionController // Hint: might be used in controllers extending this $this->table = $this->getTable(); $this->table->renderTo($this); + (new AdditionalTableActions($this->getAuth(), $this->url())) + ->appendTo($this->actions()); } protected function getTable() diff --git a/library/Director/Web/Widget/AdditionalTableActions.php b/library/Director/Web/Widget/AdditionalTableActions.php new file mode 100644 index 00000000..068c9c89 --- /dev/null +++ b/library/Director/Web/Widget/AdditionalTableActions.php @@ -0,0 +1,97 @@ +auth = $auth; + $this->url = $url; + } + + public function appendTo(Html $parent) + { + $links = []; + if ($this->hasPermission('director/showsql')) { + $links[] = $this->createShowSqlToggle(); + } + + if (! empty($links)) { + $parent->add($this->moreOptions($links)); + } + + return $this; + } + + protected function createShowSqlToggle() + { + if ($this->url->getParam('format') === 'sql') { + $link = Link::create( + $this->translate('Hide SQL'), + $this->url->without('format') + ); + } else { + $link = Link::create( + $this->translate('Show SQL'), + $this->url->with('format', 'sql') + ); + } + + return $link; + } + + protected function moreOptions($links) + { + $options = $this->ul( + $this->li([ + // TODO: extend link for dropdown-toggle from Web 2, doesn't + // seem to work: [..], null, ['class' => 'dropdown-toggle'] + Link::create(Icon::create('down-open'), '#'), + $subUl = Html::tag('ul') + ]), + ['class' => 'nav'] + ); + + foreach ($links as $link) { + $subUl->add($this->li($link)); + } + + return $options; + } + + protected function ulLi($content) + { + return $this->ul($this->li($content)); + } + + protected function ul($content, $attributes = null) + { + return Html::tag('ul', $attributes, $content); + } + + protected function li($content) + { + return Html::tag('li', null, $content); + } + + protected function hasPermission($permission) + { + return $this->auth->hasPermission($permission); + } +}