mirror of
https://github.com/pretix/pretix.git
synced 2026-05-17 17:14:04 +00:00
experimental support for AbortController
This commit is contained in:
@@ -224,21 +224,22 @@ $(function () {
|
|||||||
async_task_is_long = $(this).is("[data-asynctask-long]");
|
async_task_is_long = $(this).is("[data-asynctask-long]");
|
||||||
async_task_old_url = location.href;
|
async_task_old_url = location.href;
|
||||||
$("body").data('ajaxing', true);
|
$("body").data('ajaxing', true);
|
||||||
if ($(this).is("[data-asynctask-headline]")) {
|
|
||||||
waitingDialog.show($(this).attr("data-asynctask-headline"));
|
const ac = new AbortController();
|
||||||
} else {
|
window.pretix.dialog({
|
||||||
waitingDialog.show(gettext('We are processing your request …'));
|
label: this.getAttribute("data-asynctask-headline") || gettext("We are processing your request …"),
|
||||||
}
|
message: (this.getAttribute("data-asynctask-text") || "") + gettext(
|
||||||
if ($(this).is("[data-asynctask-text]")) {
|
'We are currently sending your request to the server. If this takes longer ' +
|
||||||
$("#loadingmodal p.text").text($(this).attr("data-asynctask-text")).show();
|
'than one minute, please check your internet connection and then reload ' +
|
||||||
} else {
|
'this page and try again.'
|
||||||
$("#loadingmodal p.text").hide();
|
),
|
||||||
}
|
icon: 'cog',
|
||||||
$("#loadingmodal p.status").text(gettext(
|
}, ac.signal);
|
||||||
'We are currently sending your request to the server. If this takes longer ' +
|
|
||||||
'than one minute, please check your internet connection and then reload ' +
|
window.setTimeout(function() {
|
||||||
'this page and try again.'
|
ac.abort();
|
||||||
));
|
}, 2000);
|
||||||
|
return false;
|
||||||
|
|
||||||
var action = this.action;
|
var action = this.action;
|
||||||
var formData = new FormData(this);
|
var formData = new FormData(this);
|
||||||
|
|||||||
@@ -382,7 +382,14 @@ function get_label_text_for_id(id) {
|
|||||||
|
|
||||||
|
|
||||||
window.pretix = window.pretix || {};
|
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 id = "dialog-" + (opt.confirm ? "alert" : "info");
|
||||||
const dialog = document.getElementById(id);
|
const dialog = document.getElementById(id);
|
||||||
$("#" + id + "-label").text(opt.label);
|
$("#" + id + "-label").text(opt.label);
|
||||||
@@ -391,13 +398,22 @@ window.pretix.dialog = function(opt = {}) {
|
|||||||
if (opt.confirm) {
|
if (opt.confirm) {
|
||||||
$("button", dialog).attr("value", opt.confirm.toString()).text(opt.confirm === true ? gettext("OK") : opt.confirm);
|
$("button", dialog).attr("value", opt.confirm.toString()).text(opt.confirm === true ? gettext("OK") : opt.confirm);
|
||||||
}
|
}
|
||||||
dialog.showModal();
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
if (signal) {
|
||||||
|
function onAbort() {
|
||||||
|
dialog.close();
|
||||||
|
}
|
||||||
|
signal.addEventListener('abort', onAbort, { once: true });
|
||||||
|
}
|
||||||
dialog.addEventListener('close', function() {
|
dialog.addEventListener('close', function() {
|
||||||
// TODO: dialog.returnValue prüfen und entsprechend resolve/reject ausführen?
|
if (signal) {
|
||||||
|
signal.removeEventListener('abort', onAbort);
|
||||||
|
}
|
||||||
resolve(dialog.returnValue);
|
resolve(dialog.returnValue);
|
||||||
}, { once: true });
|
}, { once: true });
|
||||||
|
|
||||||
|
dialog.showModal();
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user