From 96e3845f464c8cedc4486e559b157b807db237ed Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 25 Aug 2015 16:55:10 +0200 Subject: [PATCH] Improve handling of navigation on link closes Do not drop active menu when closing the left column, unless there is a different active menu that matches the current state. fixes #9761 --- public/js/icinga/behavior/navigation.js | 13 +++++++++++++ public/js/icinga/loader.js | 19 ++++++------------- public/js/icinga/ui.js | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/public/js/icinga/behavior/navigation.js b/public/js/icinga/behavior/navigation.js index d2caef82f..4abcee473 100644 --- a/public/js/icinga/behavior/navigation.js +++ b/public/js/icinga/behavior/navigation.js @@ -157,6 +157,19 @@ } }; + /** + * Try to select a new URL by + * + * @param url + */ + Navigation.prototype.trySetActiveByUrl = function(url) { + var active = this.active; + this.setActiveByUrl(url); + if (! this.active && active) { + this.setActive($(this.icinga.utils.getElementByDomPath(active))); + } + }; + /** * Remove all active elements */ diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index 6a296d03c..92bd4810a 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -570,27 +570,20 @@ if (! req.autorefresh) { // TODO: Hook for response/url? var url = req.url; + + if (req.$target[0].id === 'col1') { + self.icinga.behaviors.navigation.trySetActiveByUrl(url); + } + var $forms = $('[action="' + this.icinga.utils.parseUrl(url).path + '"]'); var $matches = $.merge($('[href="' + url + '"]'), $forms); - $matches.each(function (idx, el) { - if ($(el).closest('#menu').length) { - if (req.$target[0].id === 'col1') { - self.icinga.behaviors.navigation.resetActive(); - } - } - }); - $matches.each(function (idx, el) { var $el = $(el); if ($el.closest('#menu').length) { if ($el.is('form')) { $('input', $el).addClass('active'); - } else { - if (req.$target[0].id === 'col1') { - self.icinga.behaviors.navigation.setActive($el); - } } - // Interrupt .each, only on menu item shall be active + // Interrupt .each, only one menu item shall be active return false; } }); diff --git a/public/js/icinga/ui.js b/public/js/icinga/ui.js index 5d65e1277..16fc4ae2b 100644 --- a/public/js/icinga/ui.js +++ b/public/js/icinga/ui.js @@ -154,7 +154,7 @@ var kill = this.cutContainer($('#col1')); this.pasteContainer($('#col1'), col2); this.fixControls(); - this.icinga.behaviors.navigation.setActiveByUrl($('#col1').data('icingaUrl')); + this.icinga.behaviors.navigation.trySetActiveByUrl($('#col1').data('icingaUrl')); }, cutContainer: function ($col) {