Asynctask JS: On errors, only replace inner part of page

This commit is contained in:
Raphael Michel
2021-02-15 18:26:05 +01:00
parent d109dde1e1
commit 9fdaf040dc
2 changed files with 23 additions and 10 deletions

View File

@@ -71,6 +71,7 @@ function async_task_check_error(jqXHR, textStatus, errorThrown) {
jqXHR.responseText.indexOf("</body") jqXHR.responseText.indexOf("</body")
)); ));
form_handlers($("body")); form_handlers($("body"));
setup_collapsible_details($("body"));
} else if (c.length > 0) { } else if (c.length > 0) {
// This is some kind of 500/404/403 page, show it in an overlay // This is some kind of 500/404/403 page, show it in an overlay
$("body").data('ajaxing', false); $("body").data('ajaxing', false);
@@ -146,11 +147,20 @@ function async_task_error(jqXHR, textStatus, errorThrown) {
if (respdom.filter('form') && (respdom.filter('.has-error') || respdom.filter('.alert-danger'))) { if (respdom.filter('form') && (respdom.filter('.has-error') || respdom.filter('.alert-danger'))) {
// This is a failed form validation, let's just use it // This is a failed form validation, let's just use it
waitingDialog.hide(); waitingDialog.hide();
$("body").html(jqXHR.responseText.substring(
jqXHR.responseText.indexOf("<body"), if (respdom.filter('#page-wrapper') && $('#page-wrapper').length) {
jqXHR.responseText.indexOf("</body") $("#page-wrapper").html(respdom.find("#page-wrapper").html());
)); form_handlers($("#page-wrapper"));
form_handlers($("body")); setup_collapsible_details($("#page-wrapper"));
} else {
$("body").html(jqXHR.responseText.substring(
jqXHR.responseText.indexOf("<body"),
jqXHR.responseText.indexOf("</body")
));
form_handlers($("body"));
setup_collapsible_details($("body"));
}
} else if (c.length > 0) { } else if (c.length > 0) {
waitingDialog.hide(); waitingDialog.hide();
ajaxErrDialog.show(c.first().html()); ajaxErrDialog.show(c.first().html());

View File

@@ -1,11 +1,8 @@
/*global $ */ /*global $ */
$(function () { setup_collapsible_details = function (el) {
"use strict";
var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]'; var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
el.find("details summary, details summary a[data-toggle=variations]").click(function (e) {
$("details summary, details summary a[data-toggle=variations]").click(function (e) {
if (this.tagName !== "A" && $(e.target).closest("a").length > 0) { if (this.tagName !== "A" && $(e.target).closest("a").length > 0) {
return true; return true;
} }
@@ -55,4 +52,10 @@ $(function () {
return false; return false;
}); });
}); });
};
$(function () {
"use strict";
setup_collapsible_details($("body"));
}); });