From 62ba861cd25579382a0dd120284ab7bd035bbb40 Mon Sep 17 00:00:00 2001 From: Mira Weller Date: Fri, 16 May 2025 20:53:52 +0200 Subject: [PATCH] use new dialog class for asynctask dialog --- src/pretix/static/pretixbase/js/asynctask.js | 118 +++++++++---------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/src/pretix/static/pretixbase/js/asynctask.js b/src/pretix/static/pretixbase/js/asynctask.js index 7bbd72fa68..e10ebbf3e3 100644 --- a/src/pretix/static/pretixbase/js/asynctask.js +++ b/src/pretix/static/pretixbase/js/asynctask.js @@ -251,73 +251,73 @@ $(function () { $("#ajaxerr").on("click", ".ajaxerr-close", ajaxErrDialog.hide); }); -var waitingDialog = { - show: function (title, text, status) { - "use strict"; - this.setTitle(title); - this.setText(text); - this.setStatus(status || gettext('If this takes longer than a few minutes, please contact us.')); - this.setProgress(null); - this.setSteps(null); - $("body").addClass("loading"); - $("#loadingmodal").removeAttr("hidden has-modal-dialog"); - }, - hide: function () { - "use strict"; - $("body").removeClass("loading has-modal-dialog"); - $("#loadingmodal").attr("hidden", true); - }, - setTitle: function(title) { - $("#loadingmodal h3").text(title); - }, - setStatus: function(statusText) { - $("#loadingmodal p.status").text(statusText); - }, - setText: function(text) { - if (text) - $("#loadingmodal p.text").text(text).show(); - else - $("#loadingmodal p.text").hide(); - }, - setProgress: function(percentage) { - if (typeof percentage === 'number') { - $("#loadingmodal .progress").show(); - $("#loadingmodal .progress .progress-bar").css("width", percentage + "%"); - } else { - $("#loadingmodal .progress").hide(); - } - }, - setSteps: function(steps) { - var $steps = $("#loadingmodal .steps"); - if (steps) { - $steps.html("").show() - for (var step of data.steps) { - $steps.append( - $("").addClass("fa fa-fw") - .toggleClass("fa-check text-success", step.done) - .toggleClass("fa-cog fa-spin text-muted", !step.done) - ).append( - $("").text(step.label) - ).append( - $("
") - ) - } - } else { - $steps.hide(); +function AsyncStatusDialog(options) { + ModalDialog.call(this, Object.assign({ + content: [ + this.textEl = EL('p', {}), + this.statusEl = EL('p', {}), + this.progressEl = EL('div', {class: 'progress'}, EL('div', {class:'progress-bar progress-bar-success', hidden: ''})), + this.stepsEl = EL('div', {class: 'steps', hidden: ''}, ''), + ] + }, options)); +} +AsyncStatusDialog.prototype = Object.create(ModalDialog.prototype); +AsyncStatusDialog.prototype.show = function (title, text, status) { + ModalDialog.prototype.show.call(this); + this.setTitle(title); + this.setText(text); + this.setStatus(status || gettext('If this takes longer than a few minutes, please contact us.')); + this.setProgress(null); + this.setSteps(null); +} +AsyncStatusDialog.prototype.setText = function (text) { + $(this.textEl).toggle(!!text); + this.textEl.innerText = text; +} +AsyncStatusDialog.prototype.setStatus = function (text) { + this.statusEl.innerText = text; +} +AsyncStatusDialog.prototype.setProgress = function (percent) { + $(this.progressEl).toggle(typeof percent === 'number').find('.progress-bar').css('width', percent + '%'); +} +AsyncStatusDialog.prototype.setSteps = function (steps) { + var $steps = $(this.stepsEl); + if (typeof steps === "object" && Array.isArray(steps)) { + $steps.html("").show(); + for (var step of steps) { + $steps.append( + $("").addClass("fa fa-fw") + .toggleClass("fa-check text-success", step.done) + .toggleClass("fa-cog fa-spin text-muted", !step.done) + ).append( + $("").text(step.label) + ).append( + $("
") + ) } + } else { + $steps.html("").hide(); } -}; +} + +var waitingDialog; +$(function() { + waitingDialog = new AsyncStatusDialog({ + icon: 'cog', rotatingIcon: true, + }); +}); var ajaxErrDialog = { show: function (c) { "use strict"; - $("#ajaxerr").html(c); + $("#ajaxerr").html(c).show(); $("#ajaxerr .links").html("" - + gettext("Close message") + ""); - $("body").addClass("ajaxerr has-modal-dialog"); + + gettext("Close message") + ""); + ModalDialog.updateBodyClass(); }, hide: function () { "use strict"; - $("body").removeClass("ajaxerr has-modal-dialog"); - }, + $("#ajaxerr").hide(); + ModalDialog.updateBodyClass(); + } };