Messages wrapped up.

This commit is contained in:
Michael Woods
2025-12-24 21:22:35 -05:00
parent d6ca7703a1
commit c8a1614c79
2 changed files with 72 additions and 50 deletions

View File

@@ -40,7 +40,7 @@
</div>
<div class="modal-body">
<div class="mb-3">
<label for="to_call" class="form-label">To (callsign)</label>
<label for="to_call" class="form-label">To (comma-separated callsigns, or ALL for bulletin)</label>
<input type="text" class="form-control" id="to_call" name="to_call" required>
</div>
<div class="mb-3">
@@ -59,18 +59,32 @@
</div>
<script>
document.getElementById('composeForm')?.addEventListener('submit', async function(e) {
const composeForm = document.getElementById('composeForm');
if (composeForm) {
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 toInput = document.getElementById('to_call').value.trim(); // keep ID for compatibility
const text = document.getElementById('message_text').value.trim();
if (!to_call || !text) {
if (!toInput || !text) {
status.className = 'alert alert-danger';
status.textContent = 'Both To and Message fields are required.';
status.textContent = 'To and Message fields are required.';
status.style.display = 'block';
return;
}
// Split comma-separated, strip, uppercase, filter empty
const toList = toInput.split(',')
.map(c => c.trim().toUpperCase())
.filter(c => c.length > 0);
if (toList.length === 0) {
status.className = 'alert alert-danger';
status.textContent = 'At least one valid callsign required.';
status.style.display = 'block';
return;
}
@@ -82,36 +96,44 @@
'Content-Type': 'application/json',
},
body: JSON.stringify({
to_call: to_call,
text: text
to: toList, // <-- array of callsigns
text: text // <-- body
}),
credentials: 'include' // sends Basic Auth
credentials: 'include'
});
if (response.ok) {
const result = await response.json();
status.className = 'alert alert-success';
status.textContent = 'Message sent successfully!';
status.style.display = 'block';
this.reset();
// Auto-close modal and refresh page to show new message
composeForm.reset();
setTimeout(() => {
const modal = bootstrap.Modal.getInstance(document.getElementById('composeModal'));
if (modal) modal.hide();
}, 1000);
setTimeout(() => location.reload(), 1500);
}, 1200);
setTimeout(() => location.reload(), 1700);
} else {
const errorData = await response.json();
let errorMsg = 'Failed to send message';
if (errorData.detail) {
if (Array.isArray(errorData.detail)) {
errorMsg = errorData.detail.map(d => d.msg || d).join('; ');
} else {
errorMsg = errorData.detail;
}
}
status.className = 'alert alert-danger';
status.textContent = errorData.detail || 'Failed to send message';
status.textContent = errorMsg;
status.style.display = 'block';
}
} catch (err) {
console.error(err);
status.className = 'alert alert-danger';
status.textContent = 'Network error check connection';
status.textContent = 'Network error';
status.style.display = 'block';
}
});
}
</script>
</body>
</html>

View File

@@ -35,6 +35,6 @@
<pre class="bg-light p-3 border">{{ message.text }}</pre>
<p class="nav-links">
<a href="/dashboard">← Back to Dashboard</a>
<a href="/messages">← Back to Messages</a>
</p>
{% endblock %}