Django_Basic_Manufacturing_3/templates/database_management/restore.html
2025-08-22 17:05:22 +07:00

153 lines
6.5 KiB
HTML

{% extends 'base.html' %}
{% block title %}{{ module_title }} - Manufacturing App{% endblock %}
{% block content %}
<div class="container-fluid mt-4">
<div class="row">
<div class="col-md-8 offset-md-2">
<div class="card">
<div class="card-header">
<h4 class="mb-0">
<i class="fas fa-upload"></i> Restore Database
</h4>
</div>
<div class="card-body">
<div class="alert alert-danger">
<i class="fas fa-exclamation-triangle"></i>
<strong>Warning: Destructive Operation</strong>
<ul class="mb-0 mt-2">
<li>This operation will replace the current database with the uploaded backup</li>
<li>All current data will be permanently lost</li>
<li>A backup of the current database will be created automatically before restore</li>
<li>This action cannot be undone</li>
</ul>
</div>
<div class="alert alert-info">
<i class="fas fa-info-circle"></i>
<strong>Restore Process:</strong>
<ol class="mb-0 mt-2">
<li>Upload a valid SQLite database backup file (.db or .sqlite3)</li>
<li>Current database will be backed up automatically</li>
<li>Uploaded backup will replace the current database</li>
<li>System will verify the backup file integrity</li>
<li>Restore completion notification will be shown</li>
</ol>
</div>
<form method="post" enctype="multipart/form-data" id="restore-form">
{% csrf_token %}
<div class="mb-4">
<h5>Backup File Upload</h5>
<div class="mb-3">
<label for="backup_file" class="form-label">Select Backup File</label>
<input type="file" class="form-control" id="backup_file" name="backup_file"
accept=".db,.sqlite3" required>
<div class="form-text">
Only SQLite database files (.db, .sqlite3) are accepted.
</div>
</div>
<div class="mb-3">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="confirm-restore" required>
<label class="form-check-label" for="confirm-restore">
<strong>I understand that this will replace all current data and cannot be undone.</strong>
</label>
</div>
</div>
</div>
<div class="alert alert-success">
<i class="fas fa-shield-alt"></i>
<strong>Safety Measures:</strong> A backup of the current database will be created automatically before the restore operation.
</div>
<div class="d-flex justify-content-between">
<a href="{% url 'database_management:dashboard' %}" class="btn btn-secondary">
<i class="fas fa-times"></i> Cancel
</a>
<button type="submit" class="btn btn-warning" id="restore-btn">
<i class="fas fa-upload"></i> Restore Database
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- File Upload Progress Modal -->
<div class="modal fade" id="uploadProgressModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Uploading Backup File</h5>
</div>
<div class="modal-body">
<div class="progress mb-3">
<div class="progress-bar" role="progressbar" style="width: 0%"></div>
</div>
<p class="text-center mb-0">Please wait while the backup file is being uploaded...</p>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('restore-form');
const restoreBtn = document.getElementById('restore-btn');
const confirmCheckbox = document.getElementById('confirm-restore');
const fileInput = document.getElementById('backup_file');
// Enable/disable restore button based on confirmation checkbox
confirmCheckbox.addEventListener('change', function() {
restoreBtn.disabled = !this.checked;
});
// Validate file type
fileInput.addEventListener('change', function() {
const file = this.files[0];
if (file) {
const validExtensions = ['.db', '.sqlite3'];
const fileName = file.name.toLowerCase();
const isValid = validExtensions.some(ext => fileName.endsWith(ext));
if (!isValid) {
alert('Please select a valid SQLite database file (.db or .sqlite3)');
this.value = '';
}
}
});
form.addEventListener('submit', function(e) {
if (!confirmCheckbox.checked) {
e.preventDefault();
alert('Please confirm that you understand the restore operation.');
return;
}
if (!fileInput.files[0]) {
e.preventDefault();
alert('Please select a backup file to restore.');
return;
}
// Show progress modal
const progressModal = new bootstrap.Modal(document.getElementById('uploadProgressModal'));
progressModal.show();
restoreBtn.disabled = true;
restoreBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Restoring...';
// Allow form to submit normally
});
});
</script>
{% endblock %}