redirect fixes

This commit is contained in:
Dennis Eichhorn 2024-04-26 22:02:22 +00:00
parent 31419927be
commit d3337d327d
2 changed files with 42 additions and 27 deletions

View File

@ -1194,14 +1194,15 @@ export class Form
}
let statusCode = null;
let responseData = null;
if (xhr.getResponseHeader('content-type').includes('application/octet-stream')) {
const blob = new Blob([xhr.response], { type: 'application/octet-stream' });
responseData = new Blob([xhr.response], { type: 'application/octet-stream' });
const doc = document.createElement('a');
doc.style = 'display: none';
document.body.appendChild(doc);
const url = window.URL.createObjectURL(blob);
const url = window.URL.createObjectURL(responseData);
doc.href = url;
const disposition = xhr.getResponseHeader('content-disposition');
@ -1222,6 +1223,7 @@ export class Form
} else if (xhr.getResponseHeader('content-type').includes('text/html')) {
// window.location = UriFactory.build(uri);
responseData = xhr.response;
document.documentElement.innerHTML = xhr.response;
/* This is not working as it reloads the page ?!
document.open();
@ -1232,8 +1234,8 @@ export class Form
window.omsApp.reInit(); // @todo fix memory leak which most likely exists because of continuous binding without removing binds
} else {
try {
const o = JSON.parse(xhr.response)[0];
const response = new Response(o);
responseData = JSON.parse(xhr.response);
const response = new Response(responseData[0]);
let successInject = null;
statusCode = parseInt(xhr.getResponseHeader('status'));
@ -1247,9 +1249,16 @@ export class Form
if (response.get('type') !== null) {
self.app.responseManager.run(response.get('type'), response.get(), null);
} else if (typeof o.status !== 'undefined' && o.status !== NotificationLevel.HIDDEN) {
} else if (typeof responseData[0].status !== 'undefined'
&& responseData[0].status !== NotificationLevel.HIDDEN
) {
self.app.notifyManager.send(
new NotificationMessage(o.status, o.title, o.message), NotificationType.APP_NOTIFICATION
new NotificationMessage(
responseData[0].status,
responseData[0].title,
responseData[0].message
),
NotificationType.APP_NOTIFICATION
);
}
} catch (e) {
@ -1267,13 +1276,16 @@ export class Form
'Some failure happened'
), NotificationType.APP_NOTIFICATION
);
statusCode = 400;
}
}
if (redirect !== null
&& (statusCode === 200 || statusCode === null)
) {
fetch(UriFactory.build(redirect))
const redirectUrl = UriFactory.build(redirect, responseData)
fetch(redirectUrl)
.then((response) => response.text())
.then((html) => {
document.documentElement.innerHTML = html;
@ -1282,7 +1294,7 @@ export class Form
window.omsApp.state.hasChanges = false;
}
history.pushState({}, null, UriFactory.build(redirect));
history.pushState({}, null, redirectUrl);
/* This is not working as it reloads the page ?!
document.open();
document.write(html);

View File

@ -215,8 +215,11 @@ export class UriFactory
let parsed = uri.replace(new RegExp('\{[\/#\?%@\.\$\!].*?\}', 'g'), function (match) {
match = match.substring(1, match.length - 1);
if (toMatch !== null && Object.prototype.hasOwnProperty.call(toMatch, match)) {
return toMatch[match];
if (toMatch !== null
&& (Object.prototype.hasOwnProperty.call(toMatch, match)
|| match.includes('/'))
) {
return match.includes('/') ? jsOMS.getArray(match, toMatch) : toMatch[match];
} else if (typeof UriFactory.uri[match] !== 'undefined') {
return UriFactory.uri[match];
} else if (match.indexOf('!') === 0) {