Fix error handling on add-ons selection step (#2659)

Co-authored-by: Richard Schreiber <wiffbi@gmail.com>
This commit is contained in:
Raphael Michel
2022-05-19 13:27:28 +02:00
committed by GitHub
parent 15407732ea
commit 591f5a75ef
2 changed files with 61 additions and 55 deletions

View File

@@ -70,6 +70,7 @@ function async_task_check_error(jqXHR, textStatus, errorThrown) {
jqXHR.responseText.indexOf("<body"), jqXHR.responseText.indexOf("<body"),
jqXHR.responseText.indexOf("</body") jqXHR.responseText.indexOf("</body")
)); ));
setup_basics($("body"));
form_handlers($("body")); form_handlers($("body"));
setup_collapsible_details($("body")); setup_collapsible_details($("body"));
window.setTimeout(function () { $(window).scrollTop(0) }, 200) window.setTimeout(function () { $(window).scrollTop(0) }, 200)
@@ -152,6 +153,7 @@ function async_task_error(jqXHR, textStatus, errorThrown) {
if (respdom.filter('#page-wrapper') && $('#page-wrapper').length) { if (respdom.filter('#page-wrapper') && $('#page-wrapper').length) {
$("#page-wrapper").html(respdom.find("#page-wrapper").html()); $("#page-wrapper").html(respdom.find("#page-wrapper").html());
setup_basics($("#page-wrapper"));
form_handlers($("#page-wrapper")); form_handlers($("#page-wrapper"));
setup_collapsible_details($("#page-wrapper")); setup_collapsible_details($("#page-wrapper"));
$(document).trigger("pretix:bind-forms"); $(document).trigger("pretix:bind-forms");
@@ -161,6 +163,7 @@ function async_task_error(jqXHR, textStatus, errorThrown) {
jqXHR.responseText.indexOf("<body"), jqXHR.responseText.indexOf("<body"),
jqXHR.responseText.indexOf("</body") jqXHR.responseText.indexOf("</body")
)); ));
setup_basics($("body"));
form_handlers($("body")); form_handlers($("body"));
setup_collapsible_details($("body")); setup_collapsible_details($("body"));
$(document).trigger("pretix:bind-forms"); $(document).trigger("pretix:bind-forms");

View File

@@ -174,39 +174,23 @@ var form_handlers = function (el) {
} }
}; };
function setup_basics(el) {
$(function () { el.find("input[data-toggle=radiocollapse]").change(function () {
"use strict";
$("body").removeClass("nojs");
var scrollpos = sessionStorage ? sessionStorage.getItem('scrollpos') : 0;
if (scrollpos) {
window.scrollTo(0, scrollpos);
sessionStorage.removeItem('scrollpos');
}
$(".accordion-radio").click(function() {
var $input = $("input", this);
if (!$input.prop("checked")) $input.prop('checked', true).trigger("change");
});
$("input[data-toggle=radiocollapse]").change(function () {
$($(this).attr("data-parent")).find(".collapse.in").collapse('hide'); $($(this).attr("data-parent")).find(".collapse.in").collapse('hide');
$($(this).attr("data-target")).collapse('show'); $($(this).attr("data-target")).collapse('show');
}); });
$(".js-only").removeClass("js-only"); el.find(".js-only").removeClass("js-only");
$(".js-hidden").hide(); el.find(".js-hidden").hide();
$("div.collapsed").removeClass("collapsed").addClass("collapse"); el.find("div.collapsed").removeClass("collapsed").addClass("collapse");
$(".has-error, .alert-danger").each(function () { el.find(".has-error, .alert-danger").each(function () {
$(this).closest("div.panel-collapse").collapse("show"); $(this).closest("div.panel-collapse").collapse("show");
}); });
$(".has-error").first().each(function(){ el.find(".has-error").first().each(function(){
if ($(this).is(':input')) this.focus(); if ($(this).is(':input')) this.focus();
else $(":input", this).get(0).focus(); else $(":input", this).get(0).focus();
}); });
$(".alert-danger").first().each(function() { el.find(".alert-danger").first().each(function() {
var content = $("<ul></ul>").click(function(e) { var content = $("<ul></ul>").click(function(e) {
var input = $(e.target.hash).get(0); var input = $(e.target.hash).get(0);
if (input) input.focus(); if (input) input.focus();
@@ -227,12 +211,44 @@ $(function () {
$(this).append(content); $(this).append(content);
}); });
$("[data-click-to-load]").on("click", function(e) { el.find("[data-click-to-load]").on("click", function(e) {
var target = document.getElementById(this.getAttribute("data-click-to-load")); var target = document.getElementById(this.getAttribute("data-click-to-load"));
target.src = this.href; target.src = this.href;
target.focus(); target.focus();
e.preventDefault(); e.preventDefault();
}); });
el.find('[data-toggle="tooltip"]').tooltip();
// AddOns
el.find('.addon-variation-description').hide();
el.find('.toggle-variation-description').click(function () {
$(this).parent().find('.addon-variation-description').slideToggle();
});
el.find('input[type=radio][description]').change(function () {
if ($(this).prop("checked")) {
$(this).parent().parent().find('.addon-variation-description').stop().slideDown();
}
});
}
$(function () {
"use strict";
$("body").removeClass("nojs");
var scrollpos = sessionStorage ? sessionStorage.getItem('scrollpos') : 0;
if (scrollpos) {
window.scrollTo(0, scrollpos);
sessionStorage.removeItem('scrollpos');
}
$(".accordion-radio").click(function() {
var $input = $("input", this);
if (!$input.prop("checked")) $input.prop('checked', true).trigger("change");
});
setup_basics($("body"));
$(".overlay-remove").on("click", function() { $(".overlay-remove").on("click", function() {
$(this).closest(".contains-overlay").find(".overlay").fadeOut(); $(this).closest(".contains-overlay").find(".overlay").fadeOut();
}); });
@@ -244,21 +260,8 @@ $(function () {
$("#voucher-toggle").slideUp(); $("#voucher-toggle").slideUp();
}); });
$('[data-toggle="tooltip"]').tooltip();
$("#ajaxerr").on("click", ".ajaxerr-close", ajaxErrDialog.hide); $("#ajaxerr").on("click", ".ajaxerr-close", ajaxErrDialog.hide);
// AddOns
$('.addon-variation-description').hide();
$('.toggle-variation-description').click(function () {
$(this).parent().find('.addon-variation-description').slideToggle();
});
$('input[type=radio][description]').change(function () {
if ($(this).prop("checked")) {
$(this).parent().parent().find('.addon-variation-description').stop().slideDown();
}
});
// Copy answers // Copy answers
$(".js-copy-answers").click(function (e) { $(".js-copy-answers").click(function (e) {
e.preventDefault(); e.preventDefault();