From 77046136f28451373eb07ea7693cbc24df042736 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Fri, 12 Jul 2019 12:23:34 +0200 Subject: [PATCH] asynctask.js: Hack to allow form validation --- src/pretix/static/pretixbase/js/asynctask.js | 35 ++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/pretix/static/pretixbase/js/asynctask.js b/src/pretix/static/pretixbase/js/asynctask.js index 121a79d639..305c6c0f9f 100644 --- a/src/pretix/static/pretixbase/js/asynctask.js +++ b/src/pretix/static/pretixbase/js/asynctask.js @@ -51,8 +51,18 @@ function async_task_check_callback(data, jqXHR, status) { function async_task_check_error(jqXHR, textStatus, errorThrown) { "use strict"; - var c = $(jqXHR.responseText).filter('.container'); - if (c.length > 0) { + var respdom = $(jqXHR.responseText); + var c = respdom.filter('.container'); + if (respdom.filter('form') && (respdom.filter('.has-error') || respdom.filter('.alert-danger'))) { + // This is a failed form validation, let's just use it + $("body").data('ajaxing', false); + waitingDialog.hide(); + $("body").html(jqXHR.responseText.substring( + jqXHR.responseText.indexOf(" 0) { + // This is some kind of 500/404/403 page, show it in an overlay $("body").data('ajaxing', false); waitingDialog.hide(); if (location.href.indexOf("async_id") !== -1) { @@ -114,10 +124,23 @@ function async_task_error(jqXHR, textStatus, errorThrown) { if (textStatus === "timeout") { alert(gettext("The request took to long. Please try again.")); waitingDialog.hide(); - } else if (jqXHR.responseText.indexOf('container') > 0) { - var c = $(jqXHR.responseText).filter('.container'); - waitingDialog.hide(); - ajaxErrDialog.show(c.first().html()); + } else if (jqXHR.responseText.indexOf(' 0) { + var respdom = $(jqXHR.responseText); + var c = respdom.filter('.container'); + if (respdom.filter('form') && (respdom.filter('.has-error') || respdom.filter('.alert-danger'))) { + // This is a failed form validation, let's just use it + waitingDialog.hide(); + $("body").html(jqXHR.responseText.substring( + jqXHR.responseText.indexOf(" 0) { + waitingDialog.hide(); + ajaxErrDialog.show(c.first().html()); + } else { + waitingDialog.hide(); + alert(gettext('An error of type {code} occurred.').replace(/\{code\}/, jqXHR.status)); + } } else { if (jqXHR.status >= 400 && jqXHR.status < 500) { waitingDialog.hide();