| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- // Confirm Modal Component Logic
- let confirmCallback = null;
- // Low-level: open the modal assuming confirmMessage is already populated.
- function openConfirmModal(callback, options = {}) {
- confirmCallback = callback;
- const cancelBtn = document.getElementById('confirmCancelBtn');
- const confirmBtn = document.getElementById('confirmConfirmBtn');
- if (options.onlyClose) {
- cancelBtn.classList.add('hidden');
- confirmBtn.textContent = 'Cerrar';
- confirmBtn.classList.remove('bg-red-500', 'hover:bg-red-600');
- confirmBtn.classList.add('bg-blue-500', 'hover:bg-blue-600');
- } else {
- cancelBtn.classList.remove('hidden');
- confirmBtn.textContent = 'Confirmar';
- confirmBtn.classList.remove('bg-blue-500', 'hover:bg-blue-600');
- confirmBtn.classList.add('bg-red-500', 'hover:bg-red-600');
- }
- 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');
- }
- function executeConfirmCallback() {
- if (confirmCallback) {
- confirmCallback();
- confirmCallback = null;
- }
- hideConfirmModal();
- }
- // Close modal on Escape key
- document.addEventListener('keydown', (event) => {
- if (event.key === 'Escape' && !document.getElementById('confirmModal').classList.contains('hidden')) {
- hideConfirmModal();
- }
- });
|