parent
76ac1e104e
commit
bab0ebc6c1
|
@ -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()
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Widget;
|
||||
|
||||
use dipl\Html\Html;
|
||||
use dipl\Html\Icon;
|
||||
use dipl\Html\Link;
|
||||
use dipl\Translation\TranslationHelper;
|
||||
use dipl\Web\Url;
|
||||
use Icinga\Authentication\Auth;
|
||||
|
||||
class AdditionalTableActions
|
||||
{
|
||||
use TranslationHelper;
|
||||
|
||||
/** @var Auth */
|
||||
protected $auth;
|
||||
|
||||
/** @var Url */
|
||||
protected $url;
|
||||
|
||||
public function __construct(Auth $auth, Url $url)
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue