Merge pull request #4053 from Icinga/feature/js-addUrlFlag

JS: Introduce Icinga.Utils.addUrlFlag()
This commit is contained in:
Johannes Meyer 2020-01-16 08:14:20 +01:00 committed by GitHub
commit 4c39772667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 6 deletions

View File

@ -415,13 +415,19 @@
return true;
},
/**
* Add the specified flag to the given URL
*
* @param {string} url
* @param {string} flag
*
* @returns {string}
*
* @deprecated since version 2.8.0. Use {@link Icinga.Utils.addUrlFlag()} instead
*/
addUrlFlag: function(url, flag)
{
if (url.match(/\?/)) {
return url + '&' + flag;
} else {
return url + '?' + flag;
}
return this.icinga.utils.addUrlFlag(url, flag);
},
/**
@ -543,7 +549,7 @@
if (rerenderLayout) {
var parts = url.split(/#!/);
url = parts.shift();
var redirectionUrl = this.addUrlFlag(url, 'renderLayout');
var redirectionUrl = icinga.utils.addUrlFlag(url, 'renderLayout');
var r = this.loadUrl(redirectionUrl, $('#layout'));
r.historyUrl = url;
if (parts.length) {

View File

@ -225,6 +225,30 @@
return params;
},
/**
* Add the specified flag to the given URL
*
* @param {string} url
* @param {string} flag
*
* @returns {string}
*/
addUrlFlag: function (url, flag) {
var pos = url.search(/#(?!!)/);
if (url.indexOf('?') !== -1) {
flag = '&' + flag;
} else {
flag = '?' + flag;
}
if (pos === -1) {
return url + flag;
}
return url.slice(0, pos) + flag + url.slice(pos);
},
/**
* Check whether two HTMLElements overlap
*