File manager - Edit - /var/www/html/portal/public/pmar/js/classes/BoletimFunctions.js
Back
class BoletimFunctions { constructor() { this.init(); } init() { this.setupStatusToggle(); } setupStatusToggle() { const toggles = document.querySelectorAll('.status-toggle'); toggles.forEach(toggle => { toggle.addEventListener('change', function () { const boletimId = this.getAttribute('data-boletim-id'); const newStatus = this.checked ? 'ATIVO' : 'INATIVO'; BoletimFunctions.toggleStatus(boletimId, newStatus, this); }); }); } static async toggleStatus(boletimId, newStatus, toggleElement) { const originalState = toggleElement.checked; toggleElement.disabled = true; try { const response = await fetch('/admin/boletim/meteorologico/toggle-status', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content') }, body: JSON.stringify({ boletim_id: boletimId, status: newStatus }) }); const data = await response.json(); if (data.success) { const label = toggleElement.parentElement.querySelector('.form-check-label'); if (label) { label.textContent = newStatus == 'ATIVO' ? 'Ativo' : 'Inativo'; } // Usar a nova função de alerta showBootstrapAlert('Status atualizado com sucesso!', 'success'); } else { toggleElement.checked = !originalState; showBootstrapAlert('Erro ao atualizar status!', 'danger'); } } catch (error) { toggleElement.checked = !originalState; showBootstrapAlert('Erro ao atualizar status!', 'danger'); } finally { toggleElement.disabled = false; } } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings