mirror of
https://github.com/pretix/pretix.git
synced 2026-05-17 17:14:04 +00:00
change to window.pretix.dialog Promise-based approach
This commit is contained in:
@@ -380,20 +380,34 @@ function get_label_text_for_id(id) {
|
|||||||
}).text().trim();
|
}).text().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
window.pretix = window.pretix || {};
|
||||||
|
window.pretix.dialog = function(opt = {}) {
|
||||||
|
const id = "dialog-" + (opt.confirm ? "alert" : "info");
|
||||||
|
const dialog = document.getElementById(id);
|
||||||
|
$("#" + id + "-label").text(opt.label);
|
||||||
|
$("#" + id + "-description").text(opt.message);
|
||||||
|
$(".modal-card-icon .fa", dialog).attr('class', 'fa fa-' + (opt.icon || "exclamation-triangle"));
|
||||||
|
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) => {
|
||||||
|
dialog.addEventListener('close', function() {
|
||||||
|
// TODO: dialog.returnValue prüfen und entsprechend resolve/reject ausführen?
|
||||||
|
resolve(dialog.returnValue);
|
||||||
|
}, { once: true });
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
$("body").removeClass("nojs");
|
$("body").removeClass("nojs");
|
||||||
moment.locale($("body").attr("data-datetimelocale"));
|
moment.locale($("body").attr("data-datetimelocale"));
|
||||||
|
|
||||||
$(document).on("pretix:alert pretix:info", function (e, detail) {
|
|
||||||
var dialog = document.getElementById("dialog-" + e.type.substring(7));
|
|
||||||
$("#" + dialog.getAttribute("aria-labelledby")).text(detail.label);
|
|
||||||
$("#" + dialog.getAttribute("aria-describedby")).text(detail.description);
|
|
||||||
$(".modal-card-icon .fa", dialog).attr('class', 'fa fa-' + (detail.icon || "exclamation-triangle"));
|
|
||||||
dialog.showModal();
|
|
||||||
});
|
|
||||||
|
|
||||||
$("form:has(#btn-add-to-cart)").on("submit", function(e) {
|
$("form:has(#btn-add-to-cart)").on("submit", function(e) {
|
||||||
if (
|
if (
|
||||||
(this.classList.contains("has-seating") && this.querySelector("pretix-seating-checkout-button button")) ||
|
(this.classList.contains("has-seating") && this.querySelector("pretix-seating-checkout-button button")) ||
|
||||||
@@ -406,10 +420,15 @@ $(function () {
|
|||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
$(document).trigger("pretix:alert", {
|
window.pretix.dialog({
|
||||||
label: gettext("You have not selected any ticket"),
|
type: "alert",
|
||||||
description: gettext("Please tick a checkbox or enter a quantity for one of the ticket types to add to the cart."),
|
label: gettext("You have not selected any ticket."),
|
||||||
|
message: gettext("Please tick a checkbox or enter a quantity for one of the ticket types to add to the cart."),
|
||||||
icon: 'exclamation',
|
icon: 'exclamation',
|
||||||
|
confirm: true,
|
||||||
|
}).then((result) => {
|
||||||
|
//console.log("returnValue is", result);
|
||||||
|
// TODO: should we focus the first input/checkbox/variants-button?
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user