experimental support for AbortController

This commit is contained in:
Richard Schreiber
2025-05-14 12:13:22 +02:00
parent d2ebbcc4d9
commit 0bc09a3583
2 changed files with 35 additions and 18 deletions

View File

@@ -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);

View File

@@ -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();
})
};