hospital-management/templates/communications/notification_template_confirm_delete.html
2025-08-12 13:33:25 +03:00

399 lines
21 KiB
HTML

{% extends "base.html" %}
{% load static %}
{% block title %}Delete Template - 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 Template</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:notification_template_list' %}">Templates</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 Template 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 notification template. This action cannot be undone.
Any messages currently using this template may be affected.
</p>
</div>
</div>
</div>
<!-- Template Details -->
<div class="card bg-light">
<div class="card-body">
<h6 class="card-title">Template 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">Template Name:</td>
<td>{{ object.template_name }}</td>
</tr>
<tr>
<td class="fw-bold text-muted">Category:</td>
<td>
<span class="badge bg-{% if object.category == 'APPOINTMENT' %}primary{% elif object.category == 'REMINDER' %}warning{% elif object.category == 'ALERT' %}danger{% else %}info{% endif %}">
{{ object.get_category_display }}
</span>
</td>
</tr>
<tr>
<td class="fw-bold text-muted">Message 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>
</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.is_active %}success{% else %}secondary{% endif %}">
{% if object.is_active %}Active{% else %}Inactive{% endif %}
</span>
</td>
</tr>
<tr>
<td class="fw-bold text-muted">Usage Count:</td>
<td>{{ object.usage_count|default:0 }} times</td>
</tr>
<tr>
<td class="fw-bold text-muted">Created:</td>
<td>{{ object.created_at|date:"M d, Y" }}</td>
</tr>
</table>
</div>
</div>
</div>
<!-- Template Content Preview -->
<div class="mt-3">
<h6 class="text-muted">Subject Template:</h6>
<div class="bg-white p-2 rounded border">
<code>{{ object.subject_template }}</code>
</div>
</div>
<div class="mt-3">
<h6 class="text-muted">Body Preview:</h6>
<div class="bg-white p-3 rounded border">
{{ object.body_template|truncatewords:30|linebreaks }}
{% if object.body_template|wordcount > 30 %}
<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-3">
<div class="text-center p-3 bg-light rounded">
<i class="fas fa-envelope fa-2x text-primary mb-2"></i>
<h6>{{ messages_using_template|default:0 }}</h6>
<small class="text-muted">Messages using template</small>
</div>
</div>
<div class="col-md-3">
<div class="text-center p-3 bg-light rounded">
<i class="fas fa-code fa-2x text-info mb-2"></i>
<h6>{{ object.variables.count|default:0 }}</h6>
<small class="text-muted">Template variables</small>
</div>
</div>
<div class="col-md-3">
<div class="text-center p-3 bg-light rounded">
<i class="fas fa-language fa-2x text-success mb-2"></i>
<h6>{{ object.languages.count|default:1 }}</h6>
<small class="text-muted">Language versions</small>
</div>
</div>
<div class="col-md-3">
<div class="text-center p-3 bg-light rounded">
<i class="fas fa-chart-line fa-2x text-warning mb-2"></i>
<h6>All</h6>
<small class="text-muted">Usage statistics</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">
<div class="list-group-item">
<div class="d-flex w-100 justify-content-between">
<h6 class="mb-1">Deactivate Template</h6>
<small>Recommended</small>
</div>
<p class="mb-1">Keep the template but mark it as inactive so it can't be used for new messages.</p>
<button class="btn btn-sm btn-outline-warning" onclick="deactivateTemplate()">
<i class="fas fa-pause me-1"></i>Deactivate Instead
</button>
</div>
<div class="list-group-item">
<div class="d-flex w-100 justify-content-between">
<h6 class="mb-1">Archive Template</h6>
<small>Alternative</small>
</div>
<p class="mb-1">Move the template to archived status for future reference.</p>
<button class="btn btn-sm btn-outline-secondary" onclick="archiveTemplate()">
<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 Template</h6>
<small>Backup</small>
</div>
<p class="mb-1">Download template data before deletion for your records.</p>
<button class="btn btn-sm btn-outline-info" onclick="exportTemplate()">
<i class="fas fa-download me-1"></i>Export First
</button>
</div>
<div class="list-group-item">
<div class="d-flex w-100 justify-content-between">
<h6 class="mb-1">Create Copy</h6>
<small>Safe Option</small>
</div>
<p class="mb-1">Create a duplicate of this template before deletion.</p>
<button class="btn btn-sm btn-outline-success" onclick="duplicateTemplate()">
<i class="fas fa-copy me-1"></i>Duplicate First
</button>
</div>
</div>
</div>
<!-- Dependent Messages Warning -->
{% if messages_using_template > 0 %}
<div class="mt-4">
<div class="alert alert-danger" role="alert">
<div class="d-flex">
<div class="flex-shrink-0">
<i class="fas fa-exclamation-circle fa-2x"></i>
</div>
<div class="flex-grow-1 ms-3">
<h6 class="alert-heading">Active Dependencies Found!</h6>
<p class="mb-2">
This template is currently being used by <strong>{{ messages_using_template }}</strong> message(s).
Deleting this template may cause issues with:
</p>
<ul class="mb-0">
<li>Scheduled messages that reference this template</li>
<li>Automated workflows using this template</li>
<li>Message history and audit trails</li>
</ul>
</div>
</div>
</div>
</div>
{% endif %}
<!-- Confirmation Form -->
<form method="post" class="mt-4">
{% csrf_token %}
<!-- Confirmation Checkboxes -->
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="confirmUnderstand" required>
<label class="form-check-label fw-bold text-danger" for="confirmUnderstand">
I understand that this action is permanent and cannot be undone
</label>
</div>
{% if messages_using_template > 0 %}
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="confirmDependencies" required>
<label class="form-check-label fw-bold text-danger" for="confirmDependencies">
I acknowledge that {{ messages_using_template }} message(s) are using this template and may be affected
</label>
</div>
{% endif %}
<!-- Reason for Deletion -->
<div class="mb-3">
<label for="deletionReason" class="form-label">Reason for deletion (required):</label>
<select class="form-select" id="deletionReason" name="deletion_reason" required>
<option value="">Select a reason...</option>
<option value="duplicate">Duplicate template</option>
<option value="outdated">Outdated content</option>
<option value="incorrect">Incorrect template</option>
<option value="unused">No longer needed</option>
<option value="compliance">Compliance requirement</option>
<option value="restructure">System restructure</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:notification_template_detail' object.pk %}" class="btn btn-secondary">
<i class="fas fa-arrow-left me-1"></i>
Cancel
</a>
<a href="{% url 'communications:notification_template_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 Template Permanently
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block js %}
<script>
// Enable delete button only when all confirmations are checked
function updateDeleteButton() {
const confirmUnderstand = document.getElementById('confirmUnderstand').checked;
const confirmDependencies = document.getElementById('confirmDependencies');
const dependenciesChecked = !confirmDependencies || confirmDependencies.checked;
const reasonSelected = document.getElementById('deletionReason').value !== '';
document.getElementById('deleteButton').disabled = !(confirmUnderstand && dependenciesChecked && reasonSelected);
}
document.getElementById('confirmUnderstand').addEventListener('change', updateDeleteButton);
document.getElementById('deletionReason').addEventListener('change', updateDeleteButton);
{% if messages_using_template > 0 %}
document.getElementById('confirmDependencies').addEventListener('change', updateDeleteButton);
{% endif %}
// Alternative action functions
function deactivateTemplate() {
if (confirm('Deactivate this template instead of deleting it?')) {
fetch(`{% url 'communications:notification_template_detail' object.pk %}toggle/`, {
method: 'POST',
headers: {
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value,
'Content-Type': 'application/json',
},
body: JSON.stringify({ active: false })
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.location.href = '{% url "communications:notification_template_list" %}';
} else {
alert('Error deactivating template: ' + data.error);
}
});
}
}
function archiveTemplate() {
if (confirm('Archive this template instead of deleting it?')) {
fetch(`{% url 'communications:notification_template_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:notification_template_list" %}';
} else {
alert('Error archiving template: ' + data.error);
}
});
}
}
function exportTemplate() {
window.open(`{% url 'communications:notification_template_detail' object.pk %}export/`, '_blank');
}
function duplicateTemplate() {
if (confirm('Create a copy of this template before deletion?')) {
window.location.href = '{% url "communications:notification_template_create" %}?duplicate={{ object.id }}';
}
}
// Form submission with additional validation
document.querySelector('form').addEventListener('submit', function(e) {
const reason = document.getElementById('deletionReason').value;
if (!reason) {
e.preventDefault();
alert('Please select a reason for deletion.');
return;
}
const finalConfirm = confirm(
'FINAL CONFIRMATION:\n\n' +
'Are you absolutely sure you want to delete this template?\n\n' +
'Template: {{ object.template_name|escapejs }}\n' +
'Category: {{ object.get_category_display|escapejs }}\n' +
{% if messages_using_template > 0 %}'Messages affected: {{ messages_using_template }}\n' +{% endif %}
'\nThis action CANNOT be undone!'
);
if (!finalConfirm) {
e.preventDefault();
}
});
</script>
{% endblock %}