diff --git a/src/pretix/static/pretixbase/js/asynctask.js b/src/pretix/static/pretixbase/js/asynctask.js index dce4d61933..fdc9133d63 100644 --- a/src/pretix/static/pretixbase/js/asynctask.js +++ b/src/pretix/static/pretixbase/js/asynctask.js @@ -224,21 +224,22 @@ $(function () { async_task_is_long = $(this).is("[data-asynctask-long]"); async_task_old_url = location.href; $("body").data('ajaxing', true); - if ($(this).is("[data-asynctask-headline]")) { - waitingDialog.show($(this).attr("data-asynctask-headline")); - } else { - waitingDialog.show(gettext('We are processing your request …')); - } - if ($(this).is("[data-asynctask-text]")) { - $("#loadingmodal p.text").text($(this).attr("data-asynctask-text")).show(); - } else { - $("#loadingmodal p.text").hide(); - } - $("#loadingmodal p.status").text(gettext( - 'We are currently sending your request to the server. If this takes longer ' + - 'than one minute, please check your internet connection and then reload ' + - 'this page and try again.' - )); + + const ac = new AbortController(); + window.pretix.dialog({ + label: this.getAttribute("data-asynctask-headline") || gettext("We are processing your request …"), + message: (this.getAttribute("data-asynctask-text") || "") + gettext( + 'We are currently sending your request to the server. If this takes longer ' + + 'than one minute, please check your internet connection and then reload ' + + 'this page and try again.' + ), + icon: 'cog', + }, ac.signal); + + window.setTimeout(function() { + ac.abort(); + }, 2000); + return false; var action = this.action; var formData = new FormData(this); diff --git a/src/pretix/static/pretixpresale/js/ui/main.js b/src/pretix/static/pretixpresale/js/ui/main.js index 6a08c7f41b..465a26abc6 100644 --- a/src/pretix/static/pretixpresale/js/ui/main.js +++ b/src/pretix/static/pretixpresale/js/ui/main.js @@ -382,7 +382,14 @@ function get_label_text_for_id(id) { window.pretix = window.pretix || {}; -window.pretix.dialog = function(opt = {}) { +window.pretix.dialog = function(opt, signal) { + // always close any open dialogs + $("dialog[open]").each(function() { + this.close(); + }); + if (!opt) { + return; + } const id = "dialog-" + (opt.confirm ? "alert" : "info"); const dialog = document.getElementById(id); $("#" + id + "-label").text(opt.label); @@ -391,13 +398,22 @@ window.pretix.dialog = function(opt = {}) { if (opt.confirm) { $("button", dialog).attr("value", opt.confirm.toString()).text(opt.confirm === true ? gettext("OK") : opt.confirm); } - dialog.showModal(); return new Promise((resolve, reject) => { + if (signal) { + function onAbort() { + dialog.close(); + } + signal.addEventListener('abort', onAbort, { once: true }); + } dialog.addEventListener('close', function() { - // TODO: dialog.returnValue prüfen und entsprechend resolve/reject ausführen? + if (signal) { + signal.removeEventListener('abort', onAbort); + } resolve(dialog.returnValue); }, { once: true }); + + dialog.showModal(); }) };