From 57dac6a925c55f79687fe82c8b5ac7a6e244b8f5 Mon Sep 17 00:00:00 2001 From: moisseev Date: Thu, 16 Nov 2023 17:07:27 +0300 Subject: [WebUI] Load modules dynamically --- interface/js/app/config.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'interface/js/app/config.js') diff --git a/interface/js/app/config.js b/interface/js/app/config.js index 71a59a34b..df912eeea 100644 --- a/interface/js/app/config.js +++ b/interface/js/app/config.js @@ -22,12 +22,14 @@ THE SOFTWARE. */ -define(["jquery", "codejar", "linenumbers", "prism"], - function ($, CodeJar, withLineNumbers, Prism) { +/* global require */ + +define(["jquery", "app/rspamd"], + function ($, rspamd) { "use strict"; var ui = {}; - ui.getActions = function getActions(rspamd, checked_server) { + ui.getActions = function getActions(checked_server) { rspamd.query("actions", { success: function (data) { $("#actionsFormField").empty(); @@ -63,7 +65,7 @@ define(["jquery", "codejar", "linenumbers", "prism"], }); }; - ui.saveActions = function (rspamd, server) { + ui.saveActions = function (server) { function descending(arr) { var desc = true; var filtered = arr.filter(function (el) { @@ -113,7 +115,7 @@ define(["jquery", "codejar", "linenumbers", "prism"], } }; - ui.getMaps = function (rspamd, checked_server) { + ui.getMaps = function (checked_server) { var $listmaps = $("#listMaps"); $listmaps.closest(".card").hide(); rspamd.query("maps", { @@ -142,7 +144,7 @@ define(["jquery", "codejar", "linenumbers", "prism"], }); }; - ui.setup = function (rspamd) { + (() => { var jar = {}; const editor = { advanced: { @@ -175,11 +177,13 @@ define(["jquery", "codejar", "linenumbers", "prism"], "").appendTo("#modalBody"); if (editor[mode].codejar) { - jar = new CodeJar( - document.querySelector("#editor"), - withLineNumbers((el) => Prism.highlightElement(el)) - ); - jar.updateCode(data[0].data); + require(["codejar", "linenumbers", "prism"], function (CodeJar, withLineNumbers, Prism) { + jar = new CodeJar( + document.querySelector("#editor"), + withLineNumbers((el) => Prism.highlightElement(el)) + ); + jar.updateCode(data[0].data); + }); } else { document.querySelector("#editor").innerHTML = rspamd.escapeHTML(data[0].data); } @@ -212,10 +216,10 @@ define(["jquery", "codejar", "linenumbers", "prism"], }); $("#saveActionsBtn").on("click", function () { - ui.saveActions(rspamd); + ui.saveActions(); }); $("#saveActionsClusterBtn").on("click", function () { - ui.saveActions(rspamd, "All SERVERS"); + ui.saveActions("All SERVERS"); }); function saveMap(server) { @@ -242,7 +246,7 @@ define(["jquery", "codejar", "linenumbers", "prism"], $("#modalSaveAll").on("click", function () { saveMap("All SERVERS"); }); - }; + })(); return ui; }); -- cgit v1.2.3