302 lines
16 KiB
HTML
302 lines
16 KiB
HTML
{% extends "base.html" %}
|
|
{% load static %}
|
|
|
|
{% block title %}Delete Message - Communications{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="container-fluid">
|
|
<!-- Breadcrumb -->
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="page-title-box d-sm-flex align-items-center justify-content-between">
|
|
<h4 class="mb-sm-0">Delete Message</h4>
|
|
<div class="page-title-right">
|
|
<ol class="breadcrumb m-0">
|
|
<li class="breadcrumb-item"><a href="{% url 'core:dashboard' %}">Dashboard</a></li>
|
|
<li class="breadcrumb-item"><a href="{% url 'communications:dashboard' %}">Communications</a></li>
|
|
<li class="breadcrumb-item"><a href="{% url 'communications:message_list' %}">Messages</a></li>
|
|
<li class="breadcrumb-item active">Delete</li>
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-8">
|
|
<div class="card">
|
|
<div class="card-header bg-danger text-white">
|
|
<h5 class="card-title mb-0">
|
|
<i class="fas fa-exclamation-triangle me-2"></i>
|
|
Confirm Message Deletion
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<!-- Warning Message -->
|
|
<div class="alert alert-warning" role="alert">
|
|
<div class="d-flex">
|
|
<div class="flex-shrink-0">
|
|
<i class="fas fa-exclamation-triangle fa-2x"></i>
|
|
</div>
|
|
<div class="flex-grow-1 ms-3">
|
|
<h5 class="alert-heading">Warning: Permanent Action</h5>
|
|
<p class="mb-0">
|
|
You are about to permanently delete this message. This action cannot be undone.
|
|
All delivery logs and recipient information will also be removed.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Message Details -->
|
|
<div class="card bg-light">
|
|
<div class="card-body">
|
|
<h6 class="card-title">Message to be deleted:</h6>
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="table-responsive">
|
|
<table class="table table-borderless table-sm">
|
|
<tr>
|
|
<td class="fw-bold text-muted">Subject:</td>
|
|
<td>{{ object.subject }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-bold text-muted">Type:</td>
|
|
<td>
|
|
<span class="badge bg-{% if object.message_type == 'EMAIL' %}info{% elif object.message_type == 'SMS' %}success{% elif object.message_type == 'PUSH' %}warning{% else %}secondary{% endif %}">
|
|
{{ object.get_message_type_display }}
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-bold text-muted">Priority:</td>
|
|
<td>
|
|
<span class="badge bg-{% if object.priority == 'CRITICAL' %}danger{% elif object.priority == 'URGENT' %}warning{% elif object.priority == 'HIGH' %}info{% else %}secondary{% endif %}">
|
|
{{ object.get_priority_display }}
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="table-responsive">
|
|
<table class="table table-borderless table-sm">
|
|
<tr>
|
|
<td class="fw-bold text-muted">Status:</td>
|
|
<td>
|
|
<span class="badge bg-{% if object.status == 'SENT' %}success{% elif object.status == 'DELIVERED' %}primary{% elif object.status == 'FAILED' %}danger{% elif object.status == 'PENDING' %}warning{% else %}secondary{% endif %}">
|
|
{{ object.get_status_display }}
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-bold text-muted">Recipients:</td>
|
|
<td>{{ object.messagerecipient_set.count }} recipient{{ object.messagerecipient_set.count|pluralize }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-bold text-muted">Created:</td>
|
|
<td>{{ object.created_at|date:"M d, Y g:i A" }}</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Message Content Preview -->
|
|
<div class="mt-3">
|
|
<h6 class="text-muted">Content Preview:</h6>
|
|
<div class="bg-white p-3 rounded border">
|
|
{{ object.body|truncatewords:50|linebreaks }}
|
|
{% if object.body|wordcount > 50 %}
|
|
<small class="text-muted">[Content truncated...]</small>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Impact Assessment -->
|
|
<div class="mt-4">
|
|
<h6 class="text-muted mb-3">Deletion Impact:</h6>
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<div class="text-center p-3 bg-light rounded">
|
|
<i class="fas fa-users fa-2x text-primary mb-2"></i>
|
|
<h6>{{ object.messagerecipient_set.count }}</h6>
|
|
<small class="text-muted">Recipients affected</small>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="text-center p-3 bg-light rounded">
|
|
<i class="fas fa-history fa-2x text-info mb-2"></i>
|
|
<h6>{{ delivery_logs_count|default:0 }}</h6>
|
|
<small class="text-muted">Delivery logs</small>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="text-center p-3 bg-light rounded">
|
|
<i class="fas fa-chart-line fa-2x text-success mb-2"></i>
|
|
<h6>All</h6>
|
|
<small class="text-muted">Analytics data</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Alternative Actions -->
|
|
<div class="mt-4">
|
|
<h6 class="text-muted mb-3">Consider these alternatives:</h6>
|
|
<div class="list-group">
|
|
{% if object.status == 'DRAFT' %}
|
|
<div class="list-group-item">
|
|
<div class="d-flex w-100 justify-content-between">
|
|
<h6 class="mb-1">Edit Message</h6>
|
|
<small>Recommended</small>
|
|
</div>
|
|
<p class="mb-1">Modify the message content instead of deleting it.</p>
|
|
<a href="{% url 'communications:message_update' object.pk %}" class="btn btn-sm btn-outline-primary">
|
|
<i class="fas fa-edit me-1"></i>Edit Message
|
|
</a>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<div class="list-group-item">
|
|
<div class="d-flex w-100 justify-content-between">
|
|
<h6 class="mb-1">Archive Message</h6>
|
|
<small>Alternative</small>
|
|
</div>
|
|
<p class="mb-1">Keep the message but mark it as archived for future reference.</p>
|
|
<button class="btn btn-sm btn-outline-secondary" onclick="archiveMessage()">
|
|
<i class="fas fa-archive me-1"></i>Archive Instead
|
|
</button>
|
|
</div>
|
|
|
|
<div class="list-group-item">
|
|
<div class="d-flex w-100 justify-content-between">
|
|
<h6 class="mb-1">Export Data</h6>
|
|
<small>Backup</small>
|
|
</div>
|
|
<p class="mb-1">Download message data before deletion for your records.</p>
|
|
<button class="btn btn-sm btn-outline-info" onclick="exportMessage()">
|
|
<i class="fas fa-download me-1"></i>Export First
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Confirmation Form -->
|
|
<form method="post" class="mt-4">
|
|
{% csrf_token %}
|
|
|
|
<!-- Confirmation Checkbox -->
|
|
<div class="form-check mb-3">
|
|
<input class="form-check-input" type="checkbox" id="confirmDelete" required>
|
|
<label class="form-check-label fw-bold text-danger" for="confirmDelete">
|
|
I understand that this action is permanent and cannot be undone
|
|
</label>
|
|
</div>
|
|
|
|
<!-- Reason for Deletion -->
|
|
<div class="mb-3">
|
|
<label for="deletionReason" class="form-label">Reason for deletion (optional):</label>
|
|
<select class="form-select" id="deletionReason" name="deletion_reason">
|
|
<option value="">Select a reason...</option>
|
|
<option value="duplicate">Duplicate message</option>
|
|
<option value="incorrect_content">Incorrect content</option>
|
|
<option value="wrong_recipients">Wrong recipients</option>
|
|
<option value="no_longer_needed">No longer needed</option>
|
|
<option value="compliance">Compliance requirement</option>
|
|
<option value="other">Other</option>
|
|
</select>
|
|
</div>
|
|
|
|
<!-- Additional Comments -->
|
|
<div class="mb-4">
|
|
<label for="deletionComments" class="form-label">Additional comments (optional):</label>
|
|
<textarea class="form-control" id="deletionComments" name="deletion_comments" rows="3"
|
|
placeholder="Provide additional context for this deletion..."></textarea>
|
|
</div>
|
|
|
|
<!-- Action Buttons -->
|
|
<div class="d-flex gap-2 justify-content-end">
|
|
<a href="{% url 'communications:message_detail' object.pk %}" class="btn btn-secondary">
|
|
<i class="fas fa-arrow-left me-1"></i>
|
|
Cancel
|
|
</a>
|
|
<a href="{% url 'communications:message_list' %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-list me-1"></i>
|
|
Back to List
|
|
</a>
|
|
<button type="submit" class="btn btn-danger" id="deleteButton" disabled>
|
|
<i class="fas fa-trash me-1"></i>
|
|
Delete Message Permanently
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block js %}
|
|
<script>
|
|
// Enable delete button only when confirmation is checked
|
|
document.getElementById('confirmDelete').addEventListener('change', function() {
|
|
document.getElementById('deleteButton').disabled = !this.checked;
|
|
});
|
|
|
|
// Archive message function
|
|
function archiveMessage() {
|
|
if (confirm('Archive this message instead of deleting it?')) {
|
|
fetch(`{% url 'communications:message_detail' object.pk %}archive/`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value,
|
|
'Content-Type': 'application/json',
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
window.location.href = '{% url "communications:message_list" %}';
|
|
} else {
|
|
alert('Error archiving message: ' + data.error);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
// Export message function
|
|
function exportMessage() {
|
|
window.open(`{% url 'communications:message_detail' object.pk %}export/`, '_blank');
|
|
}
|
|
|
|
// Form submission with additional validation
|
|
document.querySelector('form').addEventListener('submit', function(e) {
|
|
const confirmed = document.getElementById('confirmDelete').checked;
|
|
|
|
if (!confirmed) {
|
|
e.preventDefault();
|
|
alert('Please confirm that you understand this action is permanent.');
|
|
return;
|
|
}
|
|
|
|
const finalConfirm = confirm(
|
|
'FINAL CONFIRMATION:\n\n' +
|
|
'Are you absolutely sure you want to delete this message?\n\n' +
|
|
'Subject: {{ object.subject|escapejs }}\n' +
|
|
'Recipients: {{ object.messagerecipient_set.count }} people\n\n' +
|
|
'This action CANNOT be undone!'
|
|
);
|
|
|
|
if (!finalConfirm) {
|
|
e.preventDefault();
|
|
}
|
|
});
|
|
</script>
|
|
{% endblock %}
|
|
|