From: Alexander Moisseev Date: Fri, 14 Mar 2025 10:21:21 +0000 (+0300) Subject: [WebUI] Fix map editor modal handling X-Git-Tag: 3.12.0~58^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F5388%2Fhead;p=thirdparty%2Frspamd.git [WebUI] Fix map editor modal handling - Prevent WebUI crash on `jar.destroy` when map query fails - Do not open the map editor when map query fails - Ensure proper cleanup of the editor modal --- diff --git a/interface/js/app/config.js b/interface/js/app/config.js index 037dabfdd4..0f35e31073 100644 --- a/interface/js/app/config.js +++ b/interface/js/app/config.js @@ -116,7 +116,6 @@ define(["jquery", "app/common"], success: function (json) { const [{data}] = json; $listmaps.empty(); - $("#modalBody").empty(); const $tbody = $(""); $.each(data, (i, item) => { @@ -126,8 +125,7 @@ define(["jquery", "app/common"], } const $tr = $("").append($td); - const $span = $('' + - item.uri + "").data("item", item); + const $span = $('' + item.uri + "").data("item", item); $span.wrap("").parent().appendTo($tr); $("" + item.description + "").appendTo($tr); $tr.appendTo($tbody); @@ -157,7 +155,7 @@ define(["jquery", "app/common"], let mode = "advanced"; // Modal form for maps - $(document).on("click", "[data-bs-toggle=\"modal\"]", function () { + $(document).on("click", ".map-link", function () { const item = $(this).data("item"); common.query("getmap", { headers: { @@ -167,6 +165,7 @@ define(["jquery", "app/common"], // Highlighting a large amount of text is unresponsive mode = (new Blob([data[0].data]).size > 5120) ? "basic" : $("input[name=editorMode]:checked").val(); + $("#modalBody").empty(); $("<" + editor[mode].elt + ' id="editor" class="' + editor[mode].class + '" data-id="' + item.map + '">").appendTo("#modalBody"); @@ -198,10 +197,9 @@ define(["jquery", "app/common"], errorMessage: "Cannot receive maps data", server: common.getServer() }); - return false; }); $("#modalDialog").on("hidden.bs.modal", () => { - if (editor[mode].codejar) { + if (editor[mode].codejar && jar && typeof jar.destroy === "function") { jar.destroy(); $(".codejar-wrap").remove(); } else {