Use the MenuItemRenderer render() implemnetations

refs #7658
This commit is contained in:
Alexander Fuhr 2015-04-20 17:07:34 +02:00
parent 4eb5f75c62
commit 9ebf4742de
2 changed files with 15 additions and 35 deletions

View File

@ -9,15 +9,9 @@ use Icinga\Web\Url;
/** /**
* A menu item with a link that surpasses the regular navigation link behavior * A menu item with a link that surpasses the regular navigation link behavior
*/ */
class ForeignMenuItemRenderer implements MenuItemRenderer { class ForeignMenuItemRenderer extends MenuItemRenderer
{
public function render(Menu $menu) protected $attributes = array(
{ 'target' => '_self'
return sprintf( );
'<a href="%s" target="_self">%s%s<span></span></a>',
$menu->getUrl() ?: '#',
$menu->getIcon() ? '<img aria-hidden="true" src="' . Url::fromPath($menu->getIcon()) . '" class="icon" /> ' : '',
htmlspecialchars($menu->getTitle())
);
}
} }

View File

@ -6,10 +6,9 @@ namespace Icinga\Module\Monitoring\Web\Menu;
use Icinga\Web\Menu as Menu; use Icinga\Web\Menu as Menu;
use Icinga\Module\Monitoring\Backend\MonitoringBackend; use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\Menu\MenuItemRenderer; use Icinga\Web\Menu\MenuItemRenderer;
use Icinga\Web\Url;
class MonitoringMenuItemRenderer implements MenuItemRenderer {
class MonitoringMenuItemRenderer extends MenuItemRenderer
{
protected static $summary; protected static $summary;
protected $columns = array(); protected $columns = array();
@ -70,31 +69,18 @@ class MonitoringMenuItemRenderer implements MenuItemRenderer {
public function render(Menu $menu) public function render(Menu $menu)
{ {
$count = $this->countItems(); return $this->getBadge() . $this->createLink($menu);
$badge = ''; }
if ($count) {
$badge = sprintf( protected function getBadge()
{
if ($count = $this->countItems()) {
return sprintf(
'<div title="%s" class="badge-container"><span class="badge badge-critical">%s</span></div>', '<div title="%s" class="badge-container"><span class="badge badge-critical">%s</span></div>',
$this->getBadgeTitle(), $this->getBadgeTitle(),
$count $count
); );
} }
if ($menu->getIcon() && strpos($menu->getIcon(), '.') === false) { return '';
return sprintf(
'%s <a href="%s"><i aria-hidden="true" class="icon-%s"></i>%s</a>',
$badge,
$menu->getUrl() ?: '#',
$menu->getIcon(),
htmlspecialchars($menu->getTitle())
);
}
return sprintf(
'%s<a href="%s">%s%s<span></span></a>',
$badge,
$menu->getUrl() ?: '#',
$menu->getIcon() ? '<img aria-hidden="true" src="' . Url::fromPath($menu->getIcon()) . '" class="icon" /> ' : '',
htmlspecialchars($menu->getTitle())
);
} }
} }