Fix navigation reload

Activate the correct menu item with JavaScript after relaod and don't
 render it on server-side on XHR requests.
This commit is contained in:
Matthias Jentsch 2014-09-09 13:57:48 +02:00
parent 56b779af4d
commit 157818c8e7
3 changed files with 16 additions and 10 deletions

View File

@ -21,8 +21,9 @@ class LayoutController extends ActionController
$this->setAutorefreshInterval(15);
$this->_helper->layout()->disableLayout();
$url = Url::fromPath($this->getParam('url'));
$this->view->menuRenderer = new MenuRenderer(Menu::load(), $url->getRelativeUrl());
$url = Url::fromRequest();
$menu = new MenuRenderer(Menu::load(), $url->getRelativeUrl());
$this->view->menuRenderer = $menu->useCustomRenderers();
}
/**

View File

@ -9,14 +9,11 @@ use Icinga\Web\Widget\SearchDashboard;
if (! $this->auth()->isAuthenticated()) {
return;
}
$dataIcingaUrl = $this->href(
'layout/menu',
array('url' => Url::fromRequest()->without('renderLayout')->getAbsoluteUrl())
);
?>
<div
id="menu" data-base-target="_main" class="container" data-icinga-url="<?= $dataIcingaUrl?>" data-icinga-refresh="15"
id="menu" data-base-target="_main" class="container" data-icinga-url="<?=$this->href('layout/menu');?>"
data-icinga-refresh="15"
>
<? if (SearchDashboard::search('dummy')->getPane('search')->hasComponents()): ?>
<form action="<?= $this->href('search') ?>" method="get" role="search">

View File

@ -151,8 +151,14 @@
// restore menu state
if (activeMenuId) {
$('#menu .active').removeClass('active');
$('#' + activeMenuId).addClass('active');
$('li.active', el).removeClass('active');
var $selectedMenu = $('#' + activeMenuId, el);
var $outerMenu = $selectedMenu.parent().closest('li');
if ($outerMenu.size()) {
$selectedMenu = $outerMenu;
}
$selectedMenu.addClass('active');
}
},
@ -576,7 +582,6 @@
$li.addClass('active');
activeMenuId = $($li).attr('id');
if ($li.hasClass('hover')) {
$('#menu .active').removeClass('active');
$li.removeClass('hover');
}
}
@ -601,6 +606,9 @@
return false;
}
} else {
if (isMenuLink) {
activeMenuId = $(event.target).closest('li').attr('id');
}
$target = self.getLinkTargetFor($a);
}