From 3d276dc4d6d827b1cf5b851839cf4cc485415a4a Mon Sep 17 00:00:00 2001 From: Giorgio Ravera Date: Tue, 26 May 2026 14:40:56 +0200 Subject: [PATCH] Created dedicate modals file --- backend/app.py | 5 + frontend/aliases.html | 66 +------------ frontend/devices.html | 76 +-------------- frontend/hosts.html | 76 +-------------- frontend/index.html | 76 +-------------- frontend/js/aliases.js | 10 +- frontend/js/common.js | 23 +++++ frontend/js/devices.js | 10 +- frontend/js/hosts.js | 10 +- frontend/js/index.js | 28 +++++- frontend/js/leases.js | 10 +- frontend/js/login.js | 5 +- frontend/js/session.js | 2 +- frontend/leases.html | 76 +-------------- frontend/modals.html | 214 +++++++++++++++++++++++++++++++++++++++++ 15 files changed, 318 insertions(+), 369 deletions(-) create mode 100644 frontend/modals.html diff --git a/backend/app.py b/backend/app.py index c169fce..46b0010 100644 --- a/backend/app.py +++ b/backend/app.py @@ -172,6 +172,10 @@ def home(request: Request): def js_home(request: Request): return FileResponse(os.path.join(settings.FRONTEND_DIR, "js/index.js")) +# Modals +def modals(request: Request): + return FileResponse(os.path.join(settings.FRONTEND_DIR, "modals.html")) + # CSS variables def css_variables(request: Request): return FileResponse(os.path.join(settings.FRONTEND_DIR, "css/variables.css")) @@ -240,6 +244,7 @@ def create_app() -> FastAPI: app.add_api_route("/", home, methods=["GET"]) app.add_api_route("/home", home, methods=["GET"]) app.add_api_route("/index.html", home, methods=["GET"]) + app.add_api_route("/modals.html", modals, methods=["GET"]) app.add_api_route("/js/index.js", js_home, methods=["GET"]) app.add_api_route("/css/variables.css", css_variables, methods=["GET"]) app.add_api_route("/css/layout.css", css_layout, methods=["GET"]) diff --git a/frontend/aliases.html b/frontend/aliases.html index 07924f6..4d587f1 100644 --- a/frontend/aliases.html +++ b/frontend/aliases.html @@ -130,70 +130,8 @@
- - + +
diff --git a/frontend/devices.html b/frontend/devices.html index 4a91842..f908c9d 100644 --- a/frontend/devices.html +++ b/frontend/devices.html @@ -132,80 +132,8 @@
- - + +
diff --git a/frontend/hosts.html b/frontend/hosts.html index 089a970..69dd032 100644 --- a/frontend/hosts.html +++ b/frontend/hosts.html @@ -131,80 +131,8 @@
- - + +
diff --git a/frontend/index.html b/frontend/index.html index c8a2485..f317eed 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -178,80 +178,8 @@ - - - - - + +
diff --git a/frontend/js/aliases.js b/frontend/js/aliases.js index 7f1f31e..f34e486 100644 --- a/frontend/js/aliases.js +++ b/frontend/js/aliases.js @@ -1,5 +1,5 @@ // Import common js -import { showToast, sortTable, initSortableTable, resetSorting } from './common.js'; +import { loadModals, showToast, sortTable, initSortableTable, resetSorting } from './common.js'; import { reloadDNS, reloadDHCP } from './services.js'; // ----------------------------- @@ -587,6 +587,14 @@ const actionHandlers = { // ----------------------------- document.addEventListener("DOMContentLoaded", async () => { + // Load modals (Bootstrap 5 requires JS initialization for dynamic content) + try { + await loadModals(); + } catch (err) { + console.error(err?.message || "Error loading modals"); + showToast(err?.message || "Error loading modals", false); + } + // Init UI sort (aria-sort, arrows) initSortableTable(); diff --git a/frontend/js/common.js b/frontend/js/common.js index 7c608f4..fad618b 100644 --- a/frontend/js/common.js +++ b/frontend/js/common.js @@ -4,6 +4,29 @@ let timeoutToast = 3000; // milliseconds const stringCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" }); +// ----------------------------- +// Load modals HTML and initialize them +// ----------------------------- +export async function loadModals() { + try { + const r = await fetch("/modals.html"); + if (!r.ok) throw new Error("Error loading modals"); + + const html = await r.text(); + + const container = document.getElementById("modals-container"); + if (!container) { + console.warn("modals-container not found"); + return; + } + + container.innerHTML = html; + + } catch (err) { + console.error("Modals load error:", err); + } +} + // ----------------------------- // Validate the IPv4 address format // ----------------------------- diff --git a/frontend/js/devices.js b/frontend/js/devices.js index 4b2966b..e2da545 100644 --- a/frontend/js/devices.js +++ b/frontend/js/devices.js @@ -1,5 +1,5 @@ // Import common js -import { isValidIPv4, isValidIPv6, isValidMAC, showToast, sortTable, initSortableTable, resetSorting } from './common.js'; +import { loadModals, isValidIPv4, isValidIPv6, isValidMAC, showToast, sortTable, initSortableTable, resetSorting } from './common.js'; import { reloadDNS, reloadDHCP } from './services.js'; // ----------------------------- @@ -704,6 +704,14 @@ const actionHandlers = { // ----------------------------- document.addEventListener("DOMContentLoaded", async () => { + // Load modals (Bootstrap 5 requires JS initialization for dynamic content) + try { + await loadModals(); + } catch (err) { + console.error(err?.message || "Error loading modals"); + showToast(err?.message || "Error loading modals", false); + } + // Init UI sort (aria-sort, arrows) initSortableTable(); diff --git a/frontend/js/hosts.js b/frontend/js/hosts.js index f142b43..c69c42b 100644 --- a/frontend/js/hosts.js +++ b/frontend/js/hosts.js @@ -1,5 +1,5 @@ // Import common js -import { isValidIPv4, isValidIPv6, isValidMAC, showToast, sortTable, initSortableTable, resetSorting } from './common.js'; +import { loadModals, isValidIPv4, isValidIPv6, isValidMAC, showToast, sortTable, initSortableTable, resetSorting } from './common.js'; import { reloadDNS, reloadDHCP } from './services.js'; // ----------------------------- @@ -611,6 +611,14 @@ const actionHandlers = { // ----------------------------- document.addEventListener("DOMContentLoaded", async () => { + // Load modals (Bootstrap 5 requires JS initialization for dynamic content) + try { + await loadModals(); + } catch (err) { + console.error(err?.message || "Error loading modals"); + showToast(err?.message || "Error loading modals", false); + } + // Init UI sort (aria-sort, arrows) initSortableTable(); diff --git a/frontend/js/index.js b/frontend/js/index.js index 2c5faf3..6704c02 100644 --- a/frontend/js/index.js +++ b/frontend/js/index.js @@ -1,7 +1,7 @@ // ------------------------------------------------------- // IMPORT // ------------------------------------------------------- -import { showToast } from './common.js'; +import { loadModals, showToast } from './common.js'; import { apiCheck, reloadDNS, reloadDHCP, doBackup, doRestore, checkHealth } from './services.js'; // ------------------------------------------------------- @@ -252,6 +252,23 @@ const actionHandlers = { } }; +// ----------------------------- +// DOMContentLoaded: initialize everything +// ----------------------------- +document.addEventListener("DOMContentLoaded", async () => { + + // Load modals (Bootstrap 5 requires JS initialization for dynamic content) + try { + await loadModals(); + } catch (err) { + console.error(err?.message || "Error loading modals"); + showToast(err?.message || "Error loading modals", false); + } + + // Init Restore Backup Modal (backdrop click to close) + initRestoreBackupModal(); +}); + // ------------------------------------------------------- // Global Click Delegation // ------------------------------------------------------- @@ -281,8 +298,13 @@ document.addEventListener('keydown', (e) => { } }); -const restoreModal = document.getElementById('restoreModal'); -if (restoreModal) { +// ------------------------------------------------------- +// Init Restore Backup Modal (backdrop click to close) +// ------------------------------------------------------- +function initRestoreBackupModal() { + const restoreModal = document.getElementById('restoreModal'); + if (!restoreModal) return; + restoreModal.addEventListener('click', (e) => { if (e.target === restoreModal) closeRestoreModal(); }); diff --git a/frontend/js/leases.js b/frontend/js/leases.js index 81ae6ad..f8e496b 100644 --- a/frontend/js/leases.js +++ b/frontend/js/leases.js @@ -1,5 +1,5 @@ // Import common js -import { isValidIPv4, isValidIPv6, isValidMAC, showToast, sortTable, initSortableTable, resetSorting } from './common.js'; +import { loadModals, isValidIPv4, isValidIPv6, isValidMAC, showToast, sortTable, initSortableTable, resetSorting } from './common.js'; import { reloadDNS, reloadDHCP } from './services.js'; // ----------------------------- @@ -575,6 +575,14 @@ const actionHandlers = { // ----------------------------- document.addEventListener("DOMContentLoaded", async () => { + // Load modals (Bootstrap 5 requires JS initialization for dynamic content) + try { + await loadModals(); + } catch (err) { + console.error(err?.message || "Error loading modals"); + showToast(err?.message || "Error loading modals", false); + } + // Init UI sort (aria-sort, arrows) initSortableTable(); diff --git a/frontend/js/login.js b/frontend/js/login.js index b29bc04..31d0422 100644 --- a/frontend/js/login.js +++ b/frontend/js/login.js @@ -1,4 +1,7 @@ -document.addEventListener('DOMContentLoaded', () => { +// ----------------------------- +// DOMContentLoaded: initialize everything +// ----------------------------- +document.addEventListener("DOMContentLoaded", () => { const form = document.getElementById('loginForm'); if (!form) return; diff --git a/frontend/js/session.js b/frontend/js/session.js index a140a4a..e85e776 100644 --- a/frontend/js/session.js +++ b/frontend/js/session.js @@ -11,7 +11,7 @@ async function handleLogout() { } // ----------------------------- -// DOM Ready +// DOMContentLoaded: initialize everything // ----------------------------- document.addEventListener("DOMContentLoaded", () => { const logoutBtn = document.getElementById("logoutBtn"); diff --git a/frontend/leases.html b/frontend/leases.html index 8b228b7..54e648d 100644 --- a/frontend/leases.html +++ b/frontend/leases.html @@ -128,80 +128,8 @@
- - + +
diff --git a/frontend/modals.html b/frontend/modals.html new file mode 100644 index 0000000..3d4cf70 --- /dev/null +++ b/frontend/modals.html @@ -0,0 +1,214 @@ + + + + + + + + + + + \ No newline at end of file -- 2.47.3