Allow container-based url in history api

When a url is now loaded for an non-main container, the url for the
container is appended to the GET part of the URL

refs #4303
This commit is contained in:
Jannis Moßhammer 2013-06-19 13:17:43 +02:00
parent e8d7971531
commit fa5c499733
5 changed files with 41 additions and 12 deletions

View File

@ -71,7 +71,6 @@ define([
loadUrl: function(url, target, params) {
target = target || "icinga-main";
async.loadToTarget(target, url, params);
History.pushState(params, document.title, url);
},
getFailedModules: function() {

View File

@ -10,6 +10,32 @@
};
var getCurrentGETParameters = function() {
var currentGET = window.location.search.substring(1).split("&");
var params = {};
if(currentGET.length > 0) {
$.each(currentGET, function(idx, elem) {
var keyVal = elem.split("=");
params[encodeURIComponent(keyVal[0])] = encodeURIComponent(keyVal[1]);
});
}
return params;
}
;
var pushGet = function(param, value, url) {
url = url || (window.location.origin+window.location.pathname);
var params = getCurrentGETParameters();
params[encodeURIComponent(param)] = encodeURIComponent(value);
var search = "?";
for (var name in params) {
if(search != "?")
search += "&";
search += name+"="+params[name];
}
return url+search+"#"+window.location.hash;
};
var getDOMForDestination = function(destination) {
var target = destination;
if(typeof destination === "string") {
@ -96,12 +122,11 @@
if (destination == "icinga-main") {
History.pushState(data, document.title, url);
} else {
data = data || {};
data[destination] = url;
History.pushState(data, document.title, document.location.href);
url = pushGet("c["+destination+"]", url);
History.pushState(data, document.title, url);
}
console.log("New url: ", url);
return req;
};
this.loadCSS = function(name) {

View File

@ -44,12 +44,16 @@ var onSecondLink = function() {
casper.page.evaluate(function() {
requirejs(["icinga/icinga"], function(icinga) {
icinga.loadUrl("/fragments/testFragment3.html?this=is_a_param", "icinga-detail");
console.log(document.location.href);
});
});
this.wait(400, function() {
console.log(casper.page.evaluate(function() {
return document.location.href;
return window.location.href;
}));
this.test.assertUrlMatch(/testFragment2.html.*testFragment3.html/);
});
};
casper.run(function() {

View File

@ -1,6 +1,6 @@
<div>
<h1>Test fragment</h1>
<a href="/fragments/testFragment2.html">Fragment 2</a>
<a href="/fragments/testFragment2.html?this=istesting">Fragment 2</a>
<a href="/fragments/testFragment3.html">Fragment 3</a>
</div>

1
test/frontend/static/public Symbolic link
View File

@ -0,0 +1 @@
/Users/moja/git/icinga2-web/test/frontend/../../public