up
This commit is contained in:
+69
-1
@@ -471,10 +471,16 @@
|
||||
<i class="fas fa-user"></i>
|
||||
</div>
|
||||
<div class="chat-header-info">
|
||||
<h6 id="chat-name">Usuario <button class="btn btn-sm btn-link" id="edit-user-btn" title="Editar usuario"><i class="fas fa-user-edit"></i></button></h6>
|
||||
<h6 id="chat-name">Usuario <button class="btn btn-sm btn-link" id="edit-user-btn" title="Editar usuario"><i class="fas fa-user-edit"></i></button>
|
||||
<span id="hold-indicator" style="display:none; margin-left:8px; color:#b85; font-weight:600">EN ESPERA</span>
|
||||
</h6>
|
||||
<small id="chat-phone">+1234567890</small>
|
||||
<div style="font-size:12px; margin-top:4px;"><button id="release-hold-btn" class="btn btn-sm btn-outline-primary" style="display:none">Liberar espera</button></div>
|
||||
</div>
|
||||
<div style="margin-left: auto; display:flex; gap:8px; align-items:center;">
|
||||
<div id="bot-toggle-container" style="display:flex;align-items:center;gap:6px;margin-right:8px;">
|
||||
<button class="btn btn-sm btn-outline-secondary" id="bot-toggle">Bot: On</button>
|
||||
</div>
|
||||
<button class="btn btn-sm btn-outline-danger" id="delete-conversation-btn" title="Eliminar conversación"><i class="fas fa-trash"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -728,6 +734,68 @@
|
||||
});
|
||||
document.querySelector(`[data-user-id="${userId}"]`)?.classList.add('active');
|
||||
|
||||
// Actualizar estado del toggle del bot según datos de la conversación
|
||||
const conv = this.conversations.find(c => c.user_id === userId);
|
||||
if (conv) {
|
||||
const btn = document.getElementById('bot-toggle');
|
||||
const holdIndicator = document.getElementById('hold-indicator');
|
||||
const releaseBtn = document.getElementById('release-hold-btn');
|
||||
|
||||
if (holdIndicator) {
|
||||
holdIndicator.style.display = conv.on_hold ? 'inline' : 'none';
|
||||
}
|
||||
|
||||
if (releaseBtn) {
|
||||
releaseBtn.style.display = conv.on_hold ? 'inline-block' : 'none';
|
||||
releaseBtn.onclick = async () => {
|
||||
try {
|
||||
const resp = await fetch('api/release_hold.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ user_id: userId })
|
||||
});
|
||||
const json = await resp.json();
|
||||
if (json && json.success) {
|
||||
conv.on_hold = false;
|
||||
holdIndicator.style.display = 'none';
|
||||
releaseBtn.style.display = 'none';
|
||||
await this.loadConversations();
|
||||
} else {
|
||||
alert('Error al liberar la espera');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error releasing hold', e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (btn) {
|
||||
btn.textContent = conv.bot_enabled ? 'Bot: On' : 'Bot: Off';
|
||||
btn.classList.toggle('btn-outline-danger', !conv.bot_enabled);
|
||||
btn.classList.toggle('btn-outline-secondary', conv.bot_enabled);
|
||||
btn.onclick = async () => {
|
||||
try {
|
||||
const resp = await fetch('api/set_bot_enabled.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ user_id: userId, enabled: conv.bot_enabled ? 0 : 1 })
|
||||
});
|
||||
const json = await resp.json();
|
||||
if (json && json.success) {
|
||||
conv.bot_enabled = !conv.bot_enabled;
|
||||
btn.textContent = conv.bot_enabled ? 'Bot: On' : 'Bot: Off';
|
||||
btn.classList.toggle('btn-outline-danger', !conv.bot_enabled);
|
||||
btn.classList.toggle('btn-outline-secondary', conv.bot_enabled);
|
||||
} else {
|
||||
alert('Error al cambiar el estado del bot');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error toggling bot', e);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Cargar mensajes
|
||||
await this.loadMessages(userId);
|
||||
// Cargar respuestas rápidas
|
||||
|
||||
Reference in New Issue
Block a user