Fix creating large numbers of subevents (introduces async task) (#2091)

This commit is contained in:
Raphael Michel
2021-05-25 19:24:43 +02:00
committed by GitHub
parent 72f4b77603
commit e510a2c121
7 changed files with 131 additions and 55 deletions

View File

@@ -72,6 +72,8 @@ function async_task_check_error(jqXHR, textStatus, errorThrown) {
));
form_handlers($("body"));
setup_collapsible_details($("body"));
window.setTimeout(function () { $(window).scrollTop(0) }, 200)
$(document).trigger("pretix:bind-forms");
} else if (c.length > 0) {
// This is some kind of 500/404/403 page, show it in an overlay
$("body").data('ajaxing', false);
@@ -152,6 +154,8 @@ function async_task_error(jqXHR, textStatus, errorThrown) {
$("#page-wrapper").html(respdom.find("#page-wrapper").html());
form_handlers($("#page-wrapper"));
setup_collapsible_details($("#page-wrapper"));
$(document).trigger("pretix:bind-forms");
window.setTimeout(function () { $(window).scrollTop(0) }, 200)
} else {
$("body").html(jqXHR.responseText.substring(
jqXHR.responseText.indexOf("<body"),
@@ -159,6 +163,8 @@ function async_task_error(jqXHR, textStatus, errorThrown) {
));
form_handlers($("body"));
setup_collapsible_details($("body"));
$(document).trigger("pretix:bind-forms");
window.setTimeout(function () { $(window).scrollTop(0) }, 200)
}
} else if (c.length > 0) {

View File

@@ -1,6 +1,6 @@
/*globals $*/
$(function () {
$(document).on("pretix:bind-forms", function () {
function cleanup(l) {
return $.trim(l.replace(/\n/g, ", "));
}

View File

@@ -72,6 +72,36 @@ $(document).ajaxError(function (event, jqXHR, settings, thrownError) {
});
var form_handlers = function (el) {
el.find("[data-formset]").formset(
{
animateForms: true,
reorderMode: 'animate'
}
);
el.find("[data-formset]").on("formAdded", "div", function (event) {
form_handlers($(event.target));
});
// Vouchers
el.find("#voucher-bulk-codes-generate").click(function () {
var num = $("#voucher-bulk-codes-num").val();
var prefix = $('#voucher-bulk-codes-prefix').val();
if (num != "") {
var url = $(this).attr("data-rng-url");
$("#id_codes").html("Generating...");
$(".form-group:has(#voucher-bulk-codes-num)").removeClass("has-error");
$.getJSON(url + '?num=' + num + '&prefix=' + escape(prefix), function (data) {
$("#id_codes").val(data.codes.join("\n"));
});
} else {
$(".form-group:has(#voucher-bulk-codes-num)").addClass("has-error");
$("#voucher-bulk-codes-num").focus();
setTimeout(function () {
$(".form-group:has(#voucher-bulk-codes-num)").removeClass("has-error");
}, 3000);
}
});
el.find(".datetimepicker").each(function () {
$(this).datetimepicker({
format: $("body").attr("data-datetimeformat"),
@@ -602,15 +632,6 @@ $(function () {
$("body").removeClass("nojs");
lightbox.init();
$("[data-formset]").formset(
{
animateForms: true,
reorderMode: 'animate'
}
);
$("[data-formset]").on("formAdded", "div", function (event) {
form_handlers($(event.target));
});
$(document).on("click", ".variations .variations-select-all", function (e) {
$(this).parent().parent().find("input[type=checkbox]").prop("checked", true).change();
e.stopPropagation();
@@ -675,27 +696,8 @@ $(function () {
});
});
// Vouchers
$("#voucher-bulk-codes-generate").click(function () {
var num = $("#voucher-bulk-codes-num").val();
var prefix = $('#voucher-bulk-codes-prefix').val();
if (num != "") {
var url = $(this).attr("data-rng-url");
$("#id_codes").html("Generating...");
$(".form-group:has(#voucher-bulk-codes-num)").removeClass("has-error");
$.getJSON(url + '?num=' + num + '&prefix=' + escape(prefix), function (data) {
$("#id_codes").val(data.codes.join("\n"));
});
} else {
$(".form-group:has(#voucher-bulk-codes-num)").addClass("has-error");
$("#voucher-bulk-codes-num").focus();
setTimeout(function () {
$(".form-group:has(#voucher-bulk-codes-num)").removeClass("has-error");
}, 3000);
}
});
form_handlers($("body"));
$(document).trigger("pretix:bind-forms");
$(".qrcode-canvas").each(function () {
$(this).qrcode(

View File

@@ -1,6 +1,6 @@
/*globals $, Morris, gettext, RRule, RRuleSet*/
$(function () {
$(document).on("pretix:bind-forms", function () {
if (!$("div[data-formset-prefix=checkinlist_set]").length) {
return;
}