mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Show the correct url in browser, when we got redirected by the controller.
This commit is contained in:
parent
3e7150735d
commit
f872f4a80c
1 changed files with 29 additions and 6 deletions
|
@ -56,6 +56,8 @@ class AjaxUI {
|
||||||
|
|
||||||
private statePopped : boolean = false;
|
private statePopped : boolean = false;
|
||||||
|
|
||||||
|
public xhr : XMLHttpRequest;
|
||||||
|
|
||||||
public constructor()
|
public constructor()
|
||||||
{
|
{
|
||||||
//Make back in the browser go back in history
|
//Make back in the browser go back in history
|
||||||
|
@ -82,6 +84,21 @@ class AjaxUI {
|
||||||
//Show flash messages
|
//Show flash messages
|
||||||
$(".toast").toast('show');
|
$(".toast").toast('show');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the XMLHttpRequest that jQuery used, to the class, so we can acess the responseURL property.
|
||||||
|
* This is a work-around as long jQuery does not implement this property in its jQXHR objects.
|
||||||
|
*/
|
||||||
|
//@ts-ignore
|
||||||
|
jQuery.ajaxSettings.xhr = function () {
|
||||||
|
//@ts-ignore
|
||||||
|
let xhr = new window.XMLHttpRequest();
|
||||||
|
//Save the XMLHttpRequest to the class.
|
||||||
|
ajaxUI.xhr = xhr;
|
||||||
|
return xhr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
this.registerLinks();
|
this.registerLinks();
|
||||||
this.registerForm();
|
this.registerForm();
|
||||||
this.fillTrees();
|
this.fillTrees();
|
||||||
|
@ -353,7 +370,18 @@ class AjaxUI {
|
||||||
|
|
||||||
ajaxUI.hideProgressBar();
|
ajaxUI.hideProgressBar();
|
||||||
|
|
||||||
|
/* We need to do the url checking before the parseHTML, so that we dont get wrong url name, caused by scripts
|
||||||
|
in the new content */
|
||||||
|
// @ts-ignore
|
||||||
|
let url = this.url;
|
||||||
|
//Check if we were redirect to a new url, then we should use that as new url.
|
||||||
|
if(ajaxUI.xhr.responseURL) {
|
||||||
|
url = ajaxUI.xhr.responseURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Parse response to DOM structure
|
//Parse response to DOM structure
|
||||||
|
//We need to preserve javascript, so the table ca
|
||||||
let dom = $.parseHTML(responseText, document, true);
|
let dom = $.parseHTML(responseText, document, true);
|
||||||
//And replace the content container
|
//And replace the content container
|
||||||
$("#content").replaceWith($("#content", dom));
|
$("#content").replaceWith($("#content", dom));
|
||||||
|
@ -364,18 +392,13 @@ class AjaxUI {
|
||||||
$("#message-container").replaceWith($('#message-container', dom));
|
$("#message-container").replaceWith($('#message-container', dom));
|
||||||
$(".toast").toast('show');
|
$(".toast").toast('show');
|
||||||
|
|
||||||
//Inject the local scripts
|
|
||||||
$("#script-reloading").replaceWith($('#script-reloading', dom));
|
|
||||||
|
|
||||||
|
|
||||||
//Set new title
|
//Set new title
|
||||||
let title = extractTitle(responseText);
|
let title = extractTitle(responseText);
|
||||||
document.title = title;
|
document.title = title;
|
||||||
|
|
||||||
//Push to history, if we currently arent poping an old value.
|
//Push to history, if we currently arent poping an old value.
|
||||||
if(!ajaxUI.statePopped) {
|
if(!ajaxUI.statePopped) {
|
||||||
// @ts-ignore
|
history.pushState(null, title, url);
|
||||||
history.pushState(null, title, this.url);
|
|
||||||
} else {
|
} else {
|
||||||
//Clear pop state
|
//Clear pop state
|
||||||
ajaxUI.statePopped = true;
|
ajaxUI.statePopped = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue