AutoFiller_QR_Campamento/assets/js/admin.js

74 lines
2.3 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function () {
var toggle = document.getElementById('sidebarToggle');
var sidebar = document.getElementById('adminSidebar');
if (toggle && sidebar) {
toggle.addEventListener('click', function () {
sidebar.classList.toggle('show');
});
}
var modalEl = document.getElementById('confirmActionModal');
var msgEl = document.getElementById('confirmActionMessage');
var okBtn = document.getElementById('confirmActionOk');
var pendingForm = null;
var modal = modalEl && window.bootstrap ? bootstrap.Modal.getOrCreateInstance(modalEl) : null;
function submitConfirmed(form) {
form.dataset.confirmed = '1';
if (typeof form.requestSubmit === 'function') {
form.requestSubmit();
} else {
form.submit();
}
}
document.querySelectorAll('form[data-confirm]').forEach(function (form) {
form.addEventListener('submit', function (e) {
if (form.dataset.confirmed === '1') {
delete form.dataset.confirmed;
return;
}
e.preventDefault();
var message = form.getAttribute('data-confirm') || '¿Confirma esta acción? / Confirm this action?';
if (!modal) {
if (window.confirm(message)) {
submitConfirmed(form);
}
return;
}
pendingForm = form;
if (msgEl) {
msgEl.textContent = message;
}
var btnLabel = form.getAttribute('data-confirm-btn') || 'Eliminar / Delete';
var btnClass = form.getAttribute('data-confirm-class') || 'btn-danger';
if (okBtn) {
okBtn.textContent = btnLabel;
okBtn.className = 'btn ' + btnClass;
}
modal.show();
});
});
if (okBtn) {
okBtn.addEventListener('click', function () {
if (pendingForm) {
var form = pendingForm;
pendingForm = null;
modal.hide();
submitConfirmed(form);
}
});
}
if (modalEl) {
modalEl.addEventListener('hidden.bs.modal', function () {
pendingForm = null;
});
}
});