Просмотр исходного кода

feat: update confirm modal to support dynamic content and streamline invocation

Manuel 8 месяцев назад
Родитель
Сommit
df22d2f2f2
2 измененных файлов с 13 добавлено и 10 удалено
  1. 8 9
      static/js/confirm_modal.js
  2. 5 1
      templates/admin/split_config.html

+ 8 - 9
static/js/confirm_modal.js

@@ -1,16 +1,9 @@
 // Confirm Modal Component Logic
 let confirmCallback = null;
 
-function showCustomConfirm(message, callback, options = {}) {
-    const msgEl = document.getElementById('confirmMessage');
-    msgEl.replaceChildren();
-    if (message instanceof Node) {
-        msgEl.appendChild(message);
-    } else {
-        msgEl.textContent = message;
-    }
+// Low-level: open the modal assuming confirmMessage is already populated.
+function openConfirmModal(callback, options = {}) {
     confirmCallback = callback;
-    // Polimorfismo visual: solo botón cerrar
     const cancelBtn = document.getElementById('confirmCancelBtn');
     const confirmBtn = document.getElementById('confirmConfirmBtn');
     if (options.onlyClose) {
@@ -27,6 +20,12 @@ function showCustomConfirm(message, callback, options = {}) {
     document.getElementById('confirmModal').classList.remove('hidden');
 }
 
+// High-level: set a plain-text message and open the modal.
+function showCustomConfirm(message, callback, options = {}) {
+    document.getElementById('confirmMessage').textContent = message;
+    openConfirmModal(callback, options);
+}
+
 function hideConfirmModal() {
     document.getElementById('confirmModal').classList.add('hidden');
 }

+ 5 - 1
templates/admin/split_config.html

@@ -231,6 +231,9 @@
     function confirmSplit() {
         const backupFilename = `squid.conf.bak${getCurrentDate()}`;
 
+        const msgEl = document.getElementById('confirmMessage');
+        msgEl.replaceChildren();
+
         const wrapper = document.createElement('div');
         wrapper.className = 'space-y-3';
 
@@ -268,8 +271,9 @@
         infoBox.appendChild(p2);
         infoBox.appendChild(p3);
         wrapper.appendChild(infoBox);
+        msgEl.appendChild(wrapper);
 
-        showCustomConfirm(wrapper, executeSplit);
+        openConfirmModal(executeSplit);
     }
 
     async function executeSplit() {