Latest changes
This commit is contained in:
@@ -59,36 +59,56 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Shared JS for compose (already in dashboard—keep if moved)
|
||||
document.getElementById('composeForm')?.addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
const status = document.getElementById('composeStatus');
|
||||
status.style.display = 'none';
|
||||
status.className = 'alert';
|
||||
|
||||
const to_call = document.getElementById('to_call').value.trim();
|
||||
const text = document.getElementById('message_text').value.trim();
|
||||
|
||||
if (!to_call || !text) {
|
||||
status.className = 'alert alert-danger';
|
||||
status.textContent = 'Both To and Message fields are required.';
|
||||
status.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
|
||||
const formData = new FormData(this);
|
||||
try {
|
||||
const response = await fetch('/api/v1/messages', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
credentials: 'include'
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
to_call: to_call,
|
||||
text: text
|
||||
}),
|
||||
credentials: 'include' // sends Basic Auth
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
const result = await response.json();
|
||||
status.className = 'alert alert-success';
|
||||
status.textContent = 'Message sent successfully!';
|
||||
status.style.display = 'block';
|
||||
this.reset();
|
||||
setTimeout(() => bootstrap.Modal.getInstance(document.getElementById('composeModal')).hide(), 1500);
|
||||
// Optional: refresh page after send
|
||||
setTimeout(() => location.reload(), 2000);
|
||||
// Auto-close modal and refresh page to show new message
|
||||
setTimeout(() => {
|
||||
const modal = bootstrap.Modal.getInstance(document.getElementById('composeModal'));
|
||||
if (modal) modal.hide();
|
||||
}, 1000);
|
||||
setTimeout(() => location.reload(), 1500);
|
||||
} else {
|
||||
const errorData = await response.json();
|
||||
status.className = 'alert alert-danger';
|
||||
status.textContent = result.detail || 'Failed to send message';
|
||||
status.textContent = errorData.detail || 'Failed to send message';
|
||||
status.style.display = 'block';
|
||||
}
|
||||
} catch (err) {
|
||||
status.className = 'alert alert-danger';
|
||||
status.textContent = 'Network error';
|
||||
status.textContent = 'Network error – check connection';
|
||||
status.style.display = 'block';
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user