hospital-management/templates/integration/systems/external_system_confirm_delete.html
2025-08-12 13:33:25 +03:00

462 lines
22 KiB
HTML

{% extends "base.html" %}
{% load static %}
{% block title %}Delete {{ object.name }} - {{ block.super }}{% endblock %}
{% block content %}
<div class="container-fluid">
<!-- Page Header -->
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<h1 class="h3 mb-1 text-danger">
<i class="fas fa-exclamation-triangle me-2"></i>Delete External System
</h1>
<nav aria-label="breadcrumb">
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item"><a href="{% url 'integration:dashboard' %}">Integration</a></li>
<li class="breadcrumb-item"><a href="{% url 'integration:external_system_list' %}">External Systems</a></li>
<li class="breadcrumb-item"><a href="{% url 'integration:external_system_detail' object.system_id %}">{{ object.name }}</a></li>
<li class="breadcrumb-item active">Delete</li>
</ol>
</nav>
</div>
</div>
<div class="row justify-content-center">
<div class="col-lg-8">
<!-- Warning Card -->
<div class="card border-danger mb-4">
<div class="card-header bg-danger text-white">
<h5 class="mb-0">
<i class="fas fa-exclamation-triangle me-2"></i>Confirm System Deletion
</h5>
</div>
<div class="card-body">
<div class="alert alert-danger d-flex align-items-center" role="alert">
<i class="fas fa-exclamation-triangle fa-2x me-3"></i>
<div>
<h6 class="alert-heading mb-1">Warning: This action cannot be undone!</h6>
<p class="mb-0">You are about to permanently delete the external system <strong>"{{ object.name }}"</strong>. This will remove all associated data and configurations.</p>
</div>
</div>
<!-- System Information -->
<div class="row mb-4">
<div class="col-md-6">
<h6 class="text-muted mb-3">System Details</h6>
<table class="table table-borderless table-sm">
<tr>
<td class="text-muted" width="100">Name:</td>
<td class="fw-semibold">{{ object.name }}</td>
</tr>
<tr>
<td class="text-muted">Type:</td>
<td>
<span class="badge bg-secondary">{{ object.get_system_type_display }}</span>
</td>
</tr>
<tr>
<td class="text-muted">Vendor:</td>
<td>{{ object.vendor|default:"Not specified" }}</td>
</tr>
<tr>
<td class="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="text-muted">Created:</td>
<td>{{ object.created_at|date:"M d, Y" }}</td>
</tr>
</table>
</div>
<div class="col-md-6">
<h6 class="text-muted mb-3">Connection Details</h6>
<table class="table table-borderless table-sm">
{% if object.base_url %}
<tr>
<td class="text-muted" width="100">Base URL:</td>
<td><code class="small">{{ object.base_url|truncatechars:40 }}</code></td>
</tr>
{% endif %}
{% if object.host %}
<tr>
<td class="text-muted">Host:</td>
<td><code class="small">{{ object.host }}{% if object.port %}:{{ object.port }}{% endif %}</code></td>
</tr>
{% endif %}
<tr>
<td class="text-muted">Auth Type:</td>
<td>
<span class="badge bg-info small">{{ object.get_authentication_type_display }}</span>
</td>
</tr>
{% if object.database_name %}
<tr>
<td class="text-muted">Database:</td>
<td><code class="small">{{ object.database_name }}</code></td>
</tr>
{% endif %}
</table>
</div>
</div>
<!-- Impact Assessment -->
<div class="card border-warning mb-4">
<div class="card-header bg-warning text-dark">
<h6 class="mb-0">
<i class="fas fa-impact me-2"></i>Deletion Impact Assessment
</h6>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-3 text-center mb-3">
<div class="bg-primary bg-gradient rounded-circle d-flex align-items-center justify-content-center mx-auto mb-2" style="width: 60px; height: 60px;">
<i class="fas fa-link fa-lg text-white"></i>
</div>
<h4 class="text-primary mb-0">{{ related_endpoints_count }}</h4>
<small class="text-muted">Endpoints</small>
{% if related_endpoints_count > 0 %}
<div class="text-danger small mt-1">Will be deleted</div>
{% endif %}
</div>
<div class="col-md-3 text-center mb-3">
<div class="bg-info bg-gradient rounded-circle d-flex align-items-center justify-content-center mx-auto mb-2" style="width: 60px; height: 60px;">
<i class="fas fa-exchange-alt fa-lg text-white"></i>
</div>
<h4 class="text-info mb-0">{{ related_mappings_count }}</h4>
<small class="text-muted">Data Mappings</small>
{% if related_mappings_count > 0 %}
<div class="text-danger small mt-1">Will be deleted</div>
{% endif %}
</div>
<div class="col-md-3 text-center mb-3">
<div class="bg-success bg-gradient rounded-circle d-flex align-items-center justify-content-center mx-auto mb-2" style="width: 60px; height: 60px;">
<i class="fas fa-play fa-lg text-white"></i>
</div>
<h4 class="text-success mb-0">{{ related_executions_count }}</h4>
<small class="text-muted">Executions</small>
{% if related_executions_count > 0 %}
<div class="text-warning small mt-1">History preserved</div>
{% endif %}
</div>
<div class="col-md-3 text-center mb-3">
<div class="bg-secondary bg-gradient rounded-circle d-flex align-items-center justify-content-center mx-auto mb-2" style="width: 60px; height: 60px;">
<i class="fas fa-file-alt fa-lg text-white"></i>
</div>
<h4 class="text-secondary mb-0">{{ related_logs_count }}</h4>
<small class="text-muted">Log Entries</small>
{% if related_logs_count > 0 %}
<div class="text-warning small mt-1">History preserved</div>
{% endif %}
</div>
</div>
{% if related_endpoints_count > 0 or related_mappings_count > 0 %}
<div class="alert alert-warning mt-3" role="alert">
<i class="fas fa-exclamation-triangle me-2"></i>
<strong>Data Loss Warning:</strong>
Deleting this system will permanently remove {{ related_endpoints_count }} endpoint{{ related_endpoints_count|pluralize }}
and {{ related_mappings_count }} data mapping{{ related_mappings_count|pluralize }}.
This action cannot be undone.
</div>
{% endif %}
{% if object.is_active %}
<div class="alert alert-danger mt-3" role="alert">
<i class="fas fa-exclamation-circle me-2"></i>
<strong>Active System Warning:</strong>
This system is currently active and may be processing integrations.
Consider deactivating it first to prevent disruption.
</div>
{% endif %}
</div>
</div>
<!-- Related Data Preview -->
{% if related_endpoints_count > 0 %}
<div class="card border-info mb-4">
<div class="card-header bg-light">
<h6 class="mb-0">
<i class="fas fa-link me-2"></i>Related Endpoints ({{ related_endpoints_count }})
</h6>
</div>
<div class="card-body">
<div class="row">
{% for endpoint in related_endpoints|slice:":6" %}
<div class="col-md-6 mb-2">
<div class="d-flex align-items-center">
<i class="fas fa-link text-primary me-2"></i>
<div>
<div class="fw-semibold small">{{ endpoint.name }}</div>
<div class="text-muted small">{{ endpoint.get_method_display }} {{ endpoint.endpoint_path|truncatechars:30 }}</div>
</div>
</div>
</div>
{% endfor %}
</div>
{% if related_endpoints_count > 6 %}
<div class="text-muted small mt-2">
... and {{ related_endpoints_count|add:"-6" }} more endpoint{{ related_endpoints_count|add:"-6"|pluralize }}
</div>
{% endif %}
</div>
</div>
{% endif %}
<!-- Confirmation Requirements -->
<div class="card border-dark">
<div class="card-header bg-dark text-white">
<h6 class="mb-0">
<i class="fas fa-check-square me-2"></i>Confirmation Requirements
</h6>
</div>
<div class="card-body">
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="confirmUnderstand" required>
<label class="form-check-label" for="confirmUnderstand">
I understand that this action will permanently delete the external system and all associated configurations
</label>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="confirmDataLoss" required>
<label class="form-check-label" for="confirmDataLoss">
I acknowledge that {{ related_endpoints_count }} endpoint{{ related_endpoints_count|pluralize }} and {{ related_mappings_count }} data mapping{{ related_mappings_count|pluralize }} will be permanently deleted
</label>
</div>
{% if object.is_active %}
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="confirmActive" required>
<label class="form-check-label" for="confirmActive">
I understand that this system is currently active and deleting it may disrupt ongoing integrations
</label>
</div>
{% endif %}
<div class="form-check mb-4">
<input class="form-check-input" type="checkbox" id="confirmNoUndo" required>
<label class="form-check-label" for="confirmNoUndo">
I confirm that this action cannot be undone and I have backed up any necessary data
</label>
</div>
<div class="mb-3">
<label for="confirmationText" class="form-label">
Type <strong>"{{ object.name }}"</strong> to confirm deletion:
</label>
<input type="text" class="form-control" id="confirmationText"
placeholder="Enter system name exactly as shown" required>
<div class="form-text">This helps prevent accidental deletions</div>
</div>
</div>
</div>
</div>
</div>
<!-- Action Buttons -->
<div class="card">
<div class="card-body">
<form method="post" id="deleteForm">
{% csrf_token %}
<div class="d-flex justify-content-between align-items-center">
<div>
<a href="{% url 'integration:external_system_detail' object.system_id %}" class="btn btn-outline-secondary">
<i class="fas fa-arrow-left me-2"></i>Cancel
</a>
{% if object.is_active %}
<a href="{% url 'integration:external_system_update' object.system_id %}" class="btn btn-outline-warning">
<i class="fas fa-pause me-2"></i>Deactivate Instead
</a>
{% endif %}
</div>
<div>
<button type="button" class="btn btn-outline-info me-2" onclick="exportSystemData()">
<i class="fas fa-download me-2"></i>Export Data First
</button>
<button type="submit" class="btn btn-danger" id="deleteButton" disabled>
<i class="fas fa-trash me-2"></i>Delete System Permanently
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
// External system delete confirmation functionality
document.addEventListener('DOMContentLoaded', function() {
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
const confirmationText = document.getElementById('confirmationText');
const deleteButton = document.getElementById('deleteButton');
const deleteForm = document.getElementById('deleteForm');
const systemName = '{{ object.name }}';
function validateForm() {
const allChecked = Array.from(checkboxes).every(cb => cb.checked);
const textMatches = confirmationText.value.trim() === systemName;
deleteButton.disabled = !(allChecked && textMatches);
if (allChecked && textMatches) {
deleteButton.classList.remove('btn-danger');
deleteButton.classList.add('btn-outline-danger');
} else {
deleteButton.classList.remove('btn-outline-danger');
deleteButton.classList.add('btn-danger');
}
}
// Add event listeners
checkboxes.forEach(checkbox => {
checkbox.addEventListener('change', validateForm);
});
confirmationText.addEventListener('input', validateForm);
// Form submission with final confirmation
deleteForm.addEventListener('submit', function(e) {
e.preventDefault();
if (!deleteButton.disabled) {
const finalConfirm = confirm(
`FINAL CONFIRMATION\n\n` +
`You are about to permanently delete "${systemName}".\n\n` +
`This will remove:\n` +
`• {{ related_endpoints_count }} endpoint{{ related_endpoints_count|pluralize }}\n` +
`• {{ related_mappings_count }} data mapping{{ related_mappings_count|pluralize }}\n` +
`• All system configurations\n\n` +
`This action CANNOT be undone.\n\n` +
`Are you absolutely sure you want to proceed?`
);
if (finalConfirm) {
// Show loading state
deleteButton.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Deleting...';
deleteButton.disabled = true;
// Submit the form
this.submit();
}
}
});
// Initial validation
validateForm();
});
function exportSystemData() {
const systemId = '{{ object.system_id }}';
fetch(`/integration/systems/${systemId}/export-full/`, {
method: 'GET',
headers: {
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value,
},
})
.then(response => response.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = `{{ object.name|slugify }}-full-export.json`;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
alert('System data exported successfully. You can now proceed with deletion if needed.');
})
.catch(error => {
console.error('Error exporting system data:', error);
alert('Error exporting system data. Please try again.');
});
}
// Prevent accidental page navigation
window.addEventListener('beforeunload', function(e) {
const checkboxes = document.querySelectorAll('input[type="checkbox"]:checked');
const confirmationText = document.getElementById('confirmationText');
if (checkboxes.length > 0 || confirmationText.value.trim() !== '') {
e.preventDefault();
e.returnValue = '';
return 'You have unsaved changes. Are you sure you want to leave?';
}
});
</script>
<style>
.bg-gradient {
background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0));
}
.table-borderless td {
border: none;
padding: 0.25rem 0;
}
.form-check-label {
cursor: pointer;
line-height: 1.4;
}
.form-check-input:checked {
background-color: #dc3545;
border-color: #dc3545;
}
.alert-heading {
font-weight: 600;
}
code {
background-color: #f8f9fa;
padding: 0.25rem 0.5rem;
border-radius: 0.25rem;
font-size: 0.875rem;
}
.card-header.bg-danger {
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}
.card-header.bg-warning {
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
.card-header.bg-dark {
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}
@media (max-width: 768px) {
.d-flex.justify-content-between {
flex-direction: column;
gap: 1rem;
}
.btn-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.col-md-3 {
margin-bottom: 1rem;
}
}
</style>
{% endblock %}