Messages wrapped up.
This commit is contained in:
@@ -40,7 +40,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="mb-3">
|
<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>
|
<input type="text" class="form-control" id="to_call" name="to_call" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
@@ -59,18 +59,32 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.getElementById('composeForm')?.addEventListener('submit', async function(e) {
|
const composeForm = document.getElementById('composeForm');
|
||||||
|
if (composeForm) {
|
||||||
|
composeForm.addEventListener('submit', async function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const status = document.getElementById('composeStatus');
|
const status = document.getElementById('composeStatus');
|
||||||
status.style.display = 'none';
|
status.style.display = 'none';
|
||||||
status.className = 'alert';
|
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();
|
const text = document.getElementById('message_text').value.trim();
|
||||||
|
|
||||||
if (!to_call || !text) {
|
if (!toInput || !text) {
|
||||||
status.className = 'alert alert-danger';
|
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';
|
status.style.display = 'block';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -82,36 +96,44 @@
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
to_call: to_call,
|
to: toList, // <-- array of callsigns
|
||||||
text: text
|
text: text // <-- body
|
||||||
}),
|
}),
|
||||||
credentials: 'include' // sends Basic Auth
|
credentials: 'include'
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const result = await response.json();
|
|
||||||
status.className = 'alert alert-success';
|
status.className = 'alert alert-success';
|
||||||
status.textContent = 'Message sent successfully!';
|
status.textContent = 'Message sent successfully!';
|
||||||
status.style.display = 'block';
|
status.style.display = 'block';
|
||||||
this.reset();
|
composeForm.reset();
|
||||||
// Auto-close modal and refresh page to show new message
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const modal = bootstrap.Modal.getInstance(document.getElementById('composeModal'));
|
const modal = bootstrap.Modal.getInstance(document.getElementById('composeModal'));
|
||||||
if (modal) modal.hide();
|
if (modal) modal.hide();
|
||||||
}, 1000);
|
}, 1200);
|
||||||
setTimeout(() => location.reload(), 1500);
|
setTimeout(() => location.reload(), 1700);
|
||||||
} else {
|
} else {
|
||||||
const errorData = await response.json();
|
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.className = 'alert alert-danger';
|
||||||
status.textContent = errorData.detail || 'Failed to send message';
|
status.textContent = errorMsg;
|
||||||
status.style.display = 'block';
|
status.style.display = 'block';
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
status.className = 'alert alert-danger';
|
status.className = 'alert alert-danger';
|
||||||
status.textContent = 'Network error – check connection';
|
status.textContent = 'Network error';
|
||||||
status.style.display = 'block';
|
status.style.display = 'block';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -35,6 +35,6 @@
|
|||||||
<pre class="bg-light p-3 border">{{ message.text }}</pre>
|
<pre class="bg-light p-3 border">{{ message.text }}</pre>
|
||||||
|
|
||||||
<p class="nav-links">
|
<p class="nav-links">
|
||||||
<a href="/dashboard">← Back to Dashboard</a>
|
<a href="/messages">← Back to Messages</a>
|
||||||
</p>
|
</p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user