diff --git a/public/js/icinga/behavior/actiontable.js b/public/js/icinga/behavior/actiontable.js index 48d214836..3fde04732 100644 --- a/public/js/icinga/behavior/actiontable.js +++ b/public/js/icinga/behavior/actiontable.js @@ -261,10 +261,10 @@ */ refresh: function() { this.clear(); - var hash = this.icinga.utils.parseUrl(window.location.href).hash; + var hash = icinga.history.getCol2State().replace(/^#!/, ''); if (this.hasMultiselection()) { var query = parseSelectionQuery(hash); - if (query.length > 1 && this.getMultiselectionUrl() === this.icinga.utils.parseUrl(hash.substr(1)).path) { + if (query.length > 1 && this.getMultiselectionUrl() === this.icinga.utils.parseUrl(hash).path) { // select all rows with matching filters var self = this; $.each(query, function(i, selection) { @@ -275,7 +275,7 @@ return; } } - this.selectUrl(hash.substr(1)); + this.selectUrl(hash); } }; @@ -348,13 +348,12 @@ } // update history - var url = self.icinga.utils.parseUrl(window.location.href.split('#')[0]); + var state = icinga.history.getCol1State(); var count = table.selections().length; - var state = url.path + url.query; if (count > 0) { var query = table.toQuery(); self.icinga.loader.loadUrl(query, self.icinga.events.getLinkTargetFor($tr)); - state += '#!' + query; + state += '#!' + query; } else { if (self.icinga.events.getLinkTargetFor($tr).attr('id') === 'col2') { self.icinga.ui.layout1col(); diff --git a/public/js/icinga/history.js b/public/js/icinga/history.js index 9af58980f..47f11566d 100644 --- a/public/js/icinga/history.js +++ b/public/js/icinga/history.js @@ -94,6 +94,11 @@ } }, + /** + * Push the given url as the new history state, unless the history is disabled + * + * @param {string} url The full url path, including anchor + */ pushUrl: function (url) { // No history API, no action if (!this.enabled) { @@ -102,6 +107,13 @@ this.push(url); }, + /** + * Execute the history state, preserving the current state of behaviors + * + * Used internally by the history and should not be called externally, instead use {@link pushUrl}. + * + * @param {string} url + */ push: function (url) { url = url.replace(/[\?&]?_(render|reload)=[a-z0-9]+/g, ''); if (this.lastPushUrl === url) { @@ -169,6 +181,14 @@ }); }, + /** + * Update the application containers to match the current url + * + * Read the pane url from the current URL and load the corresponding panes into containers to + * match the current history state. + * + * @param {Boolean|Null} onload Set to true when the main pane should not be updated, defaults to false + */ applyLocationBar: function (onload) { var icinga = this.icinga, main, @@ -187,9 +207,13 @@ ).addToHistory = false; } - if (document.location.hash && document.location.hash.match(/^#!/)) { + if (this.getPaneAnchor(0)) { + $('#col1').data('icingaUrl', $('#col1').data('icingaUrl') + '#' + this.getPaneAnchor(0)); + } - parts = document.location.hash.split(/#!/); + var hash = this.getCol2State(); + if (hash && hash.match(/^#!/)) { + parts = hash.split(/#!/); if ($('#layout > #login').length) { // We are on the login page @@ -215,6 +239,51 @@ } }, + /** + * Get the state of the selected pane + * + * @param col {int} The column index 0 or 1 + * + * @returns {String} The string representing the state + */ + getPaneAnchor: function (col) { + if (col !== 1 && col !== 0) { + throw 'Trying to get anchor for non-existing column: ' + col; + } + var panes = document.location.toString().split('#!')[col]; + return panes && panes.split('#')[1] || ''; + }, + + /** + * Get the side pane state after (and including) the #! + * + * @returns {string} The pane url + */ + getCol2State: function () { + var hash = document.location.hash; + if (hash) { + if (hash.match(/^#[^!]/)) { + var hashs = hash.split('#'); + hashs.shift(); + hashs.shift(); + hash = '#' + hashs.join('#'); + } + } + return hash || ''; + }, + + /** + * Return the main pane state fragment + * + * @returns {string} The main url including anchors, without #! + */ + getCol1State: function () { + var anchor = this.getPaneAnchor(0); + var hash = window.location.pathname + window.location.search + + (anchor.length ? ('#' + anchor) : ''); + return hash || ''; + }, + /** * Cleanup */ diff --git a/public/js/icinga/logger.js b/public/js/icinga/logger.js index 1898bf2a4..8583b9f7f 100644 --- a/public/js/icinga/logger.js +++ b/public/js/icinga/logger.js @@ -100,7 +100,7 @@ }, /** - * Return the numeric identifier fot a given log level + * Return the numeric identifier for a given log level */ numericLevel: function (level) { var ret = this.logLevels[level];