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

353 lines
20 KiB
HTML

{% extends "base.html" %}
{% load static %}
{% block title %}Delete Channel - {{ object.name }}{% 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 Communication Channel</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:communication_channel_list' %}">Channels</a></li>
<li class="breadcrumb-item"><a href="{% url 'communications:communication_channel_detail' object.pk %}">{{ object.name }}</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">
<!-- Warning Card -->
<div class="card border-danger">
<div class="card-header bg-danger text-white">
<div class="d-flex align-items-center">
<i class="fas fa-exclamation-triangle fa-2x me-3"></i>
<div>
<h5 class="card-title mb-0">Confirm Channel Deletion</h5>
<small class="opacity-75">This action cannot be undone</small>
</div>
</div>
</div>
<div class="card-body">
<!-- Channel Information -->
<div class="alert alert-warning" role="alert">
<div class="d-flex">
<div class="flex-shrink-0">
<i class="fas fa-info-circle fa-lg"></i>
</div>
<div class="flex-grow-1 ms-3">
<h6 class="alert-heading">You are about to delete:</h6>
<div class="d-flex align-items-center mb-2">
<div class="avatar-sm me-3">
<div class="avatar-title bg-soft-{% if object.channel_type == 'EMAIL' %}primary{% elif object.channel_type == 'SMS' %}success{% elif object.channel_type == 'PUSH' %}warning{% elif object.channel_type == 'WEBHOOK' %}info{% elif object.channel_type == 'SLACK' %}secondary{% else %}dark{% endif %} text-{% if object.channel_type == 'EMAIL' %}primary{% elif object.channel_type == 'SMS' %}success{% elif object.channel_type == 'PUSH' %}warning{% elif object.channel_type == 'WEBHOOK' %}info{% elif object.channel_type == 'SLACK' %}secondary{% else %}dark{% endif %} rounded">
<i class="fas fa-{% if object.channel_type == 'EMAIL' %}envelope{% elif object.channel_type == 'SMS' %}sms{% elif object.channel_type == 'PUSH' %}bell{% elif object.channel_type == 'WEBHOOK' %}link{% elif object.channel_type == 'SLACK' %}slack{% elif object.channel_type == 'TEAMS' %}microsoft{% else %}broadcast-tower{% endif %}"></i>
</div>
</div>
<div>
<h6 class="mb-0">{{ object.name }}</h6>
<small class="text-muted">{{ object.get_channel_type_display }} Channel</small>
</div>
</div>
{% if object.description %}
<p class="mb-0"><strong>Description:</strong> {{ object.description }}</p>
{% endif %}
</div>
</div>
</div>
<!-- Impact Assessment -->
<div class="row mb-4">
<div class="col-md-6">
<div class="card bg-light">
<div class="card-body text-center">
<i class="fas fa-envelope fa-2x text-muted mb-2"></i>
<h4 class="mb-1">{{ object.message_count|default:0 }}</h4>
<p class="text-muted mb-0">Total Messages Sent</p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card bg-light">
<div class="card-body text-center">
<i class="fas fa-exclamation-triangle fa-2x text-warning mb-2"></i>
<h4 class="mb-1">{{ active_alert_rules|default:0 }}</h4>
<p class="text-muted mb-0">Active Alert Rules</p>
</div>
</div>
</div>
</div>
<!-- Consequences -->
<div class="alert alert-danger" role="alert">
<h6 class="alert-heading">
<i class="fas fa-exclamation-circle me-2"></i>
Deletion Consequences
</h6>
<ul class="mb-0">
<li><strong>Channel Configuration:</strong> All channel settings and credentials will be permanently deleted</li>
<li><strong>Message History:</strong> Historical message logs will be preserved but marked as orphaned</li>
{% if active_alert_rules > 0 %}
<li><strong>Alert Rules:</strong> {{ active_alert_rules }} active alert rule(s) using this channel will be disabled</li>
{% endif %}
{% if pending_messages > 0 %}
<li><strong>Pending Messages:</strong> {{ pending_messages }} pending message(s) will fail to deliver</li>
{% endif %}
<li><strong>Future Messages:</strong> No new messages can be sent through this channel</li>
<li><strong>Integrations:</strong> Any external integrations using this channel will stop working</li>
</ul>
</div>
<!-- Affected Alert Rules -->
{% if affected_alert_rules %}
<div class="mb-4">
<h6 class="text-muted mb-2">Affected Alert Rules:</h6>
<div class="table-responsive">
<table class="table table-sm table-bordered">
<thead class="table-light">
<tr>
<th>Rule Name</th>
<th>Category</th>
<th>Severity</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{% for rule in affected_alert_rules %}
<tr>
<td>
<a href="{% url 'communications:alert_rule_detail' rule.pk %}" target="_blank">
{{ rule.rule_name }}
</a>
</td>
<td>{{ rule.get_category_display }}</td>
<td>
<span class="badge bg-{% if rule.severity == 'CRITICAL' %}danger{% elif rule.severity == 'HIGH' %}warning{% elif rule.severity == 'MEDIUM' %}info{% else %}secondary{% endif %}">
{{ rule.get_severity_display }}
</span>
</td>
<td>
<span class="badge bg-{% if rule.is_active %}success{% else %}secondary{% endif %}">
{% if rule.is_active %}Active{% else %}Inactive{% endif %}
</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
<!-- Alternative Actions -->
<div class="card bg-light mb-4">
<div class="card-header">
<h6 class="card-title mb-0">
<i class="fas fa-lightbulb me-2"></i>
Consider These Alternatives
</h6>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="d-flex align-items-start mb-3">
<div class="flex-shrink-0">
<div class="avatar-xs">
<div class="avatar-title bg-soft-warning text-warning rounded">
<i class="fas fa-pause"></i>
</div>
</div>
</div>
<div class="flex-grow-1 ms-2">
<h6 class="mb-1">Disable Channel</h6>
<p class="text-muted mb-0">Temporarily stop using this channel without losing configuration</p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="d-flex align-items-start mb-3">
<div class="flex-shrink-0">
<div class="avatar-xs">
<div class="avatar-title bg-soft-info text-info rounded">
<i class="fas fa-archive"></i>
</div>
</div>
</div>
<div class="flex-grow-1 ms-2">
<h6 class="mb-1">Archive Channel</h6>
<p class="text-muted mb-0">Keep configuration for future use but mark as inactive</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="d-flex align-items-start mb-3">
<div class="flex-shrink-0">
<div class="avatar-xs">
<div class="avatar-title bg-soft-success text-success rounded">
<i class="fas fa-exchange-alt"></i>
</div>
</div>
</div>
<div class="flex-grow-1 ms-2">
<h6 class="mb-1">Migrate to New Channel</h6>
<p class="text-muted mb-0">Create a replacement channel and transfer alert rules</p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="d-flex align-items-start mb-3">
<div class="flex-shrink-0">
<div class="avatar-xs">
<div class="avatar-title bg-soft-primary text-primary rounded">
<i class="fas fa-download"></i>
</div>
</div>
</div>
<div class="flex-grow-1 ms-2">
<h6 class="mb-1">Export Configuration</h6>
<p class="text-muted mb-0">Save channel settings before deletion for future reference</p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Confirmation Form -->
<form method="post" id="deleteForm">
{% csrf_token %}
<!-- Confirmation Checkbox -->
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="confirmDeletion" required>
<label class="form-check-label fw-bold" for="confirmDeletion">
I understand the consequences and want to permanently delete this communication channel
</label>
</div>
<!-- Confirmation Text Input -->
<div class="mb-3">
<label for="confirmationText" class="form-label fw-bold">
Type <code>{{ object.name }}</code> to confirm deletion:
</label>
<input type="text" class="form-control" id="confirmationText"
placeholder="Enter channel name to confirm" required>
<div class="form-text">This ensures you're deleting the correct channel</div>
</div>
<!-- Reason for Deletion -->
<div class="mb-4">
<label for="deletionReason" class="form-label">Reason for deletion (optional):</label>
<textarea class="form-control" id="deletionReason" name="deletion_reason" rows="3"
placeholder="Provide a reason for this deletion for audit purposes..."></textarea>
</div>
<!-- Action Buttons -->
<div class="d-flex justify-content-between">
<div>
<a href="{% url 'communications:communication_channel_detail' object.pk %}" class="btn btn-outline-secondary">
<i class="fas fa-arrow-left me-1"></i>
Cancel
</a>
<button type="button" class="btn btn-outline-warning ms-2" onclick="disableChannel()">
<i class="fas fa-pause me-1"></i>
Disable Instead
</button>
</div>
<div>
<button type="button" class="btn btn-outline-info me-2" onclick="exportConfiguration()">
<i class="fas fa-download me-1"></i>
Export Config
</button>
<button type="submit" class="btn btn-danger" id="deleteButton" disabled>
<i class="fas fa-trash me-1"></i>
Delete Channel Permanently
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block js %}
<script>
document.addEventListener('DOMContentLoaded', function() {
const confirmCheckbox = document.getElementById('confirmDeletion');
const confirmationText = document.getElementById('confirmationText');
const deleteButton = document.getElementById('deleteButton');
const channelName = '{{ object.name|escapejs }}';
function validateForm() {
const isChecked = confirmCheckbox.checked;
const textMatches = confirmationText.value.trim() === channelName;
deleteButton.disabled = !(isChecked && textMatches);
if (textMatches) {
confirmationText.classList.remove('is-invalid');
confirmationText.classList.add('is-valid');
} else if (confirmationText.value.trim() !== '') {
confirmationText.classList.remove('is-valid');
confirmationText.classList.add('is-invalid');
} else {
confirmationText.classList.remove('is-valid', 'is-invalid');
}
}
confirmCheckbox.addEventListener('change', validateForm);
confirmationText.addEventListener('input', validateForm);
// Form submission confirmation
document.getElementById('deleteForm').addEventListener('submit', function(e) {
if (!confirm('Are you absolutely sure you want to delete this communication channel? This action cannot be undone.')) {
e.preventDefault();
} else {
// Show loading state
deleteButton.innerHTML = '<i class="fas fa-spinner fa-spin me-1"></i>Deleting...';
deleteButton.disabled = true;
}
});
});
function disableChannel() {
if (confirm('Disable this channel instead of deleting it?')) {
fetch('{% url "communications:communication_channel_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) {
alert('Channel has been disabled successfully.');
window.location.href = '{% url "communications:communication_channel_detail" object.pk %}';
} else {
alert('Error disabling channel: ' + data.error);
}
});
}
}
function exportConfiguration() {
window.open('{% url "communications:communication_channel_detail" object.pk %}export/', '_blank');
}
</script>
{% endblock %}