feat(extensions): add Redémarrer action with call detection and confirmation modal

This commit is contained in:
sorcier committed 2026-11-06 02:01:37 +01:00
1 parent 1908af5d13
commit 7fd75fbff4
4 files changed
+257 -3

No files matched your search

+88 -3
View File
@@ -951,9 +951,10 @@ function renderExtensionsTable() {
<td class="py-3.5 px-4">
<code class="px-2 py-0.5 rounded bg-anthracite-950 border border-anthracite-700 text-xs font-mono text-slate-300">${escapeHtml(ext.secret)}</code>
</td>
<td class="py-3.5 px-4 text-right space-x-2">
<button type="button" onclick="editExtension(${Number(ext.id)})" class="text-xs font-semibold text-indigo-300 hover:text-indigo-200">Modifier</button>
<button type="button" onclick="deleteExtension(${Number(ext.id)})" class="text-xs font-semibold text-red-400 hover:text-red-300">Supprimer</button>
<td class="py-3.5 px-4 text-right space-x-2 whitespace-nowrap">
<button type="button" onclick="promptRebootExtension(${Number(ext.id)})" class="text-xs font-semibold text-amber-400 hover:text-amber-300 transition">Redémarrer</button>
<button type="button" onclick="editExtension(${Number(ext.id)})" class="text-xs font-semibold text-indigo-300 hover:text-indigo-200 transition">Modifier</button>
<button type="button" onclick="deleteExtension(${Number(ext.id)})" class="text-xs font-semibold text-red-400 hover:text-red-300 transition">Supprimer</button>
</td>
</tr>
`;
@@ -1109,6 +1110,90 @@ async function deleteExtension(id, optNum = null) {
}
}
let pendingRebootExtension = null;
async function promptRebootExtension(id) {
const ext = (appState.extensions || []).find(e => Number(e.id) === Number(id));
if (!ext) return;
pendingRebootExtension = ext;
document.getElementById('reboot-modal-ext-num').textContent = ext.extension;
document.getElementById('reboot-modal-ext-name').textContent = ext.name || '';
const checkingEl = document.getElementById('reboot-modal-checking');
const warningEl = document.getElementById('reboot-modal-call-warning');
const normalEl = document.getElementById('reboot-modal-normal-info');
const btnAction = document.getElementById('btn-confirm-reboot-action');
const btnLabel = document.getElementById('reboot-confirm-btn-label');
checkingEl.classList.remove('hidden');
warningEl.classList.add('hidden');
normalEl.classList.add('hidden');
btnAction.disabled = true;
btnAction.className = 'px-5 py-2.5 rounded-xl text-xs font-bold bg-anthracite-700 text-slate-400 transition cursor-not-allowed flex items-center gap-2';
btnLabel.textContent = 'Vérification en cours...';
openModal('modal-confirm-reboot-extension');
try {
const res = await apiCall('check_extension_call_status', { extension: ext.extension });
checkingEl.classList.add('hidden');
btnAction.disabled = false;
if (res.in_call) {
warningEl.classList.remove('hidden');
normalEl.classList.add('hidden');
const detailsEl = document.getElementById('reboot-modal-call-details');
if (detailsEl) {
detailsEl.textContent = res.call_details || 'Communication active détectée sur ce combiné.';
}
btnAction.className = 'px-5 py-2.5 rounded-xl text-xs font-bold bg-rose-600 hover:bg-rose-500 text-white shadow-lg shadow-rose-600/30 transition flex items-center gap-2';
btnLabel.textContent = "Forcer le redémarrage (Couper l'appel)";
} else {
warningEl.classList.add('hidden');
normalEl.classList.remove('hidden');
btnAction.className = 'px-5 py-2.5 rounded-xl text-xs font-bold bg-amber-600 hover:bg-amber-500 text-white shadow-lg shadow-amber-600/30 transition flex items-center gap-2';
btnLabel.textContent = 'Confirmer le redémarrage';
}
} catch (err) {
checkingEl.classList.add('hidden');
normalEl.classList.remove('hidden');
btnAction.disabled = false;
btnAction.className = 'px-5 py-2.5 rounded-xl text-xs font-bold bg-amber-600 hover:bg-amber-500 text-white shadow-lg shadow-amber-600/30 transition flex items-center gap-2';
btnLabel.textContent = 'Confirmer le redémarrage';
}
}
function closeRebootModal() {
pendingRebootExtension = null;
closeModal('modal-confirm-reboot-extension');
}
async function confirmRebootExtension() {
if (!pendingRebootExtension) return;
const ext = pendingRebootExtension;
const btnAction = document.getElementById('btn-confirm-reboot-action');
const btnLabel = document.getElementById('reboot-confirm-btn-label');
if (btnAction) btnAction.disabled = true;
if (btnLabel) btnLabel.textContent = 'Envoi de l\'ordre...';
try {
const res = await apiCall('reboot_extension', { extension: ext.extension });
closeRebootModal();
showToast(res.message, 'success');
} catch (err) {
showToast(err.message, 'error');
} finally {
if (btnAction) btnAction.disabled = false;
}
}
function syncEncryptionToggle(transport, currentVal = null) {
const sel = document.getElementById('ext-encryption');
if (!sel) return;