444 lines
15 KiB
HTML
444 lines
15 KiB
HTML
{% extends "base.html" %}
|
|
{% load static i18n crispy_forms_tags %}
|
|
|
|
{% block title %}Update {{ person.get_full_name }} - {{ block.super }}{% endblock %}
|
|
|
|
{% block customCSS %}
|
|
<style>
|
|
/* UI Variables for the KAAT-S Theme */
|
|
:root {
|
|
--kaauh-teal: #00636e;
|
|
--kaauh-teal-dark: #004a53;
|
|
--kaauh-border: #eaeff3;
|
|
--kaauh-gray-light: #f8f9fa;
|
|
}
|
|
|
|
/* Form Container Styling */
|
|
.form-container {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
/* Card Styling */
|
|
.card {
|
|
border: 1px solid var(--kaauh-border);
|
|
border-radius: 0.75rem;
|
|
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
|
|
}
|
|
|
|
/* Main Action Button Style */
|
|
.btn-main-action {
|
|
background-color: var(--kaauh-teal);
|
|
border-color: var(--kaauh-teal);
|
|
color: white;
|
|
font-weight: 600;
|
|
transition: all 0.2s ease;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.4rem;
|
|
padding: 0.5rem 1.5rem;
|
|
}
|
|
|
|
.btn-main-action:hover {
|
|
background-color: var(--kaauh-teal-dark);
|
|
border-color: var(--kaauh-teal-dark);
|
|
box-shadow: 0 4px 8px rgba(0,0,0,0.15);
|
|
}
|
|
|
|
/* Secondary Button Style */
|
|
.btn-outline-secondary {
|
|
color: var(--kaauh-teal-dark);
|
|
border-color: var(--kaauh-teal);
|
|
}
|
|
.btn-outline-secondary:hover {
|
|
background-color: var(--kaauh-teal-dark);
|
|
color: white;
|
|
border-color: var(--kaauh-teal-dark);
|
|
}
|
|
|
|
/* Form Field Styling */
|
|
.form-control:focus {
|
|
border-color: var(--kaauh-teal);
|
|
box-shadow: 0 0 0 0.2rem rgba(0, 99, 110, 0.25);
|
|
}
|
|
|
|
.form-select:focus {
|
|
border-color: var(--kaauh-teal);
|
|
box-shadow: 0 0 0 0.2rem rgba(0, 99, 110, 0.25);
|
|
}
|
|
|
|
/* Profile Image Upload Styling */
|
|
.profile-image-upload {
|
|
border: 2px dashed var(--kaauh-border);
|
|
border-radius: 0.5rem;
|
|
padding: 2rem;
|
|
text-align: center;
|
|
transition: all 0.3s ease;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.profile-image-upload:hover {
|
|
border-color: var(--kaauh-teal);
|
|
background-color: var(--kaauh-gray-light);
|
|
}
|
|
|
|
.profile-image-preview {
|
|
width: 120px;
|
|
height: 120px;
|
|
object-fit: cover;
|
|
border-radius: 50%;
|
|
border: 3px solid var(--kaauh-teal);
|
|
margin: 0 auto 1rem;
|
|
}
|
|
|
|
.current-image {
|
|
width: 100px;
|
|
height: 100px;
|
|
object-fit: cover;
|
|
border-radius: 50%;
|
|
border: 2px solid var(--kaauh-teal);
|
|
margin-right: 1rem;
|
|
}
|
|
|
|
/* Breadcrumb Styling */
|
|
.breadcrumb {
|
|
background-color: transparent;
|
|
padding: 0;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.breadcrumb-item + .breadcrumb-item::before {
|
|
content: ">";
|
|
color: var(--kaauh-teal);
|
|
}
|
|
|
|
/* Alert Styling */
|
|
.alert {
|
|
border-radius: 0.5rem;
|
|
border: none;
|
|
}
|
|
|
|
/* Loading State */
|
|
.btn.loading {
|
|
position: relative;
|
|
pointer-events: none;
|
|
opacity: 0.8;
|
|
}
|
|
|
|
.btn.loading::after {
|
|
content: "";
|
|
position: absolute;
|
|
width: 16px;
|
|
height: 16px;
|
|
margin: auto;
|
|
border: 2px solid transparent;
|
|
border-top-color: #ffffff;
|
|
border-radius: 50%;
|
|
animation: spin 1s linear infinite;
|
|
top: 0;
|
|
bottom: 0;
|
|
left: 0;
|
|
right: 0;
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
|
|
/* Current Profile Section */
|
|
.current-profile {
|
|
background-color: var(--kaauh-gray-light);
|
|
border-radius: 0.5rem;
|
|
padding: 1rem;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.current-profile h6 {
|
|
color: var(--kaauh-teal-dark);
|
|
font-weight: 600;
|
|
margin-bottom: 0.75rem;
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="container-fluid py-4">
|
|
<div class="form-container">
|
|
<!-- Breadcrumb Navigation -->
|
|
<nav aria-label="breadcrumb">
|
|
<ol class="breadcrumb">
|
|
<li class="breadcrumb-item">
|
|
<a href="{% url 'person_list' %}" class="text-decoration-none text-secondary">
|
|
<i class="fas fa-user-friends me-1"></i> {% trans "People" %}
|
|
</a>
|
|
</li>
|
|
<li class="breadcrumb-item">
|
|
<a href="{% url 'person_detail' person.slug %}" class="text-decoration-none text-secondary">
|
|
{{ person.full_name }}
|
|
</a>
|
|
</li>
|
|
<li class="breadcrumb-item active" aria-current="page"
|
|
style="
|
|
color: #F43B5E; /* Rosy Accent Color */
|
|
font-weight: 600;">{% trans "Update" %}</li>
|
|
</ol>
|
|
</nav>
|
|
|
|
<!-- Header -->
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 style="color: var(--kaauh-teal-dark); font-weight: 700;">
|
|
<i class="fas fa-user-edit me-2"></i> {% trans "Update Applicant" %}
|
|
</h1>
|
|
<div class="d-flex gap-2">
|
|
<a href="{% url 'person_detail' person.slug %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-eye me-1"></i> {% trans "View Details" %}
|
|
</a>
|
|
<a href="{% url 'person_list' %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-arrow-left me-1"></i> {% trans "Back to List" %}
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Current Profile Info -->
|
|
<div class="card shadow-sm mb-4">
|
|
<div class="card-body">
|
|
<div class="current-profile">
|
|
<h6><i class="fas fa-info-circle me-2"></i>{% trans "Currently Editing" %}</h6>
|
|
<div class="d-flex align-items-center">
|
|
{% if person.profile_image %}
|
|
<img src="{{ person.profile_image.url }}" alt="{{ person.get_full_name }}"
|
|
class="current-image">
|
|
{% else %}
|
|
<div class="current-image d-flex align-items-center justify-content-center bg-light">
|
|
<i class="fas fa-user text-muted"></i>
|
|
</div>
|
|
{% endif %}
|
|
<div>
|
|
<h5 class="mb-1">{{ person.get_full_name }}</h5>
|
|
{% if person.email %}
|
|
<p class="text-muted mb-0">{{ person.email }}</p>
|
|
{% endif %}
|
|
<small class="text-muted">
|
|
{% trans "Created" %}: {{ person.created_at|date:"d M Y" }} •
|
|
{% trans "Last Updated" %}: {{ person.updated_at|date:"d M Y" }}
|
|
</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Form Card -->
|
|
<div class="card shadow-sm">
|
|
<div class="card-body p-4">
|
|
{% if form.non_field_errors %}
|
|
<div class="alert alert-danger" role="alert">
|
|
<h5 class="alert-heading">
|
|
<i class="fas fa-exclamation-triangle me-2"></i>{% trans "Error" %}
|
|
</h5>
|
|
{% for error in form.non_field_errors %}
|
|
<p class="mb-0">{{ error }}</p>
|
|
{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
|
|
{% if messages %}
|
|
{% for message in messages %}
|
|
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
|
|
{{ message }}
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="{% trans 'Close' %}"></button>
|
|
</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
|
|
<form method="post" action="{% url 'person_update' person.slug %}" enctype="multipart/form-data" id="person-form">
|
|
{% csrf_token %}
|
|
{{form|crispy}}
|
|
</form>
|
|
<div class="d-flex gap-2">
|
|
<button form="person-form" type="submit" class="btn btn-main-action">
|
|
<i class="fas fa-save me-1"></i> {% trans "Update" %}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block customJS %}
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Profile Image Preview
|
|
const profileImageInput = document.getElementById('id_profile_image');
|
|
const imagePreviewContainer = document.getElementById('image-preview-container');
|
|
const originalImage = imagePreviewContainer.innerHTML;
|
|
|
|
profileImageInput.addEventListener('change', function(e) {
|
|
const file = e.target.files[0];
|
|
if (file && file.type.startsWith('image/')) {
|
|
const reader = new FileReader();
|
|
reader.onload = function(e) {
|
|
imagePreviewContainer.innerHTML = `
|
|
<img src="${e.target.result}" alt="Profile Preview" class="profile-image-preview">
|
|
<h5 class="text-muted mt-3">${file.name}</h5>
|
|
<p class="text-muted small">{% trans "New photo selected" %}</p>
|
|
`;
|
|
};
|
|
reader.readAsDataURL(file);
|
|
} else if (!file) {
|
|
// Reset to original if no file selected
|
|
imagePreviewContainer.innerHTML = originalImage;
|
|
}
|
|
});
|
|
|
|
// Form Validation
|
|
const form = document.getElementById('person-form');
|
|
form.addEventListener('submit', function(e) {
|
|
const submitBtn = form.querySelector('button[type="submit"]');
|
|
submitBtn.classList.add('loading');
|
|
submitBtn.disabled = true;
|
|
|
|
// Basic validation
|
|
const firstName = document.getElementById('id_first_name').value.trim();
|
|
const lastName = document.getElementById('id_last_name').value.trim();
|
|
const email = document.getElementById('id_email').value.trim();
|
|
|
|
if (!firstName || !lastName) {
|
|
e.preventDefault();
|
|
submitBtn.classList.remove('loading');
|
|
submitBtn.disabled = false;
|
|
alert('{% trans "First name and last name are required." %}');
|
|
return;
|
|
}
|
|
|
|
if (email && !isValidEmail(email)) {
|
|
e.preventDefault();
|
|
submitBtn.classList.remove('loading');
|
|
submitBtn.disabled = false;
|
|
alert('{% trans "Please enter a valid email address." %}');
|
|
return;
|
|
}
|
|
});
|
|
|
|
// Email validation helper
|
|
function isValidEmail(email) {
|
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
return emailRegex.test(email);
|
|
}
|
|
|
|
// LinkedIn URL validation
|
|
const linkedinInput = document.getElementById('id_linkedin_profile');
|
|
linkedinInput.addEventListener('blur', function() {
|
|
const value = this.value.trim();
|
|
if (value && !isValidLinkedInURL(value)) {
|
|
this.classList.add('is-invalid');
|
|
if (!this.nextElementSibling || !this.nextElementSibling.classList.contains('invalid-feedback')) {
|
|
const feedback = document.createElement('div');
|
|
feedback.className = 'invalid-feedback';
|
|
feedback.textContent = '{% trans "Please enter a valid LinkedIn URL" %}';
|
|
this.parentNode.appendChild(feedback);
|
|
}
|
|
} else {
|
|
this.classList.remove('is-invalid');
|
|
const feedback = this.parentNode.querySelector('.invalid-feedback');
|
|
if (feedback) feedback.remove();
|
|
}
|
|
});
|
|
|
|
function isValidLinkedInURL(url) {
|
|
const linkedinRegex = /^https?:\/\/(www\.)?linkedin\.com\/.+/i;
|
|
return linkedinRegex.test(url);
|
|
}
|
|
|
|
// Drag and Drop functionality
|
|
const uploadArea = document.querySelector('.profile-image-upload');
|
|
|
|
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
|
uploadArea.addEventListener(eventName, preventDefaults, false);
|
|
});
|
|
|
|
function preventDefaults(e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
}
|
|
|
|
['dragenter', 'dragover'].forEach(eventName => {
|
|
uploadArea.addEventListener(eventName, highlight, false);
|
|
});
|
|
|
|
['dragleave', 'drop'].forEach(eventName => {
|
|
uploadArea.addEventListener(eventName, unhighlight, false);
|
|
});
|
|
|
|
function highlight(e) {
|
|
uploadArea.style.borderColor = 'var(--kaauh-teal)';
|
|
uploadArea.style.backgroundColor = 'var(--kaauh-gray-light)';
|
|
}
|
|
|
|
function unhighlight(e) {
|
|
uploadArea.style.borderColor = 'var(--kaauh-border)';
|
|
uploadArea.style.backgroundColor = 'transparent';
|
|
}
|
|
|
|
uploadArea.addEventListener('drop', handleDrop, false);
|
|
|
|
function handleDrop(e) {
|
|
const dt = e.dataTransfer;
|
|
const files = dt.files;
|
|
|
|
if (files.length > 0) {
|
|
profileImageInput.files = files;
|
|
const event = new Event('change', { bubbles: true });
|
|
profileImageInput.dispatchEvent(event);
|
|
}
|
|
}
|
|
|
|
// Reset button functionality
|
|
const resetBtn = form.querySelector('button[type="reset"]');
|
|
resetBtn.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
|
|
// Reset form fields
|
|
form.reset();
|
|
|
|
// Reset image preview
|
|
imagePreviewContainer.innerHTML = originalImage;
|
|
|
|
// Clear any validation states
|
|
form.querySelectorAll('.is-invalid').forEach(element => {
|
|
element.classList.remove('is-invalid');
|
|
});
|
|
|
|
// Remove any invalid feedback messages
|
|
form.querySelectorAll('.invalid-feedback').forEach(element => {
|
|
element.remove();
|
|
});
|
|
});
|
|
|
|
// Warn before leaving if changes are made
|
|
let formChanged = false;
|
|
const formInputs = form.querySelectorAll('input, select, textarea');
|
|
|
|
formInputs.forEach(input => {
|
|
input.addEventListener('change', function() {
|
|
formChanged = true;
|
|
});
|
|
});
|
|
|
|
window.addEventListener('beforeunload', function(e) {
|
|
if (formChanged) {
|
|
e.preventDefault();
|
|
e.returnValue = '{% trans "You have unsaved changes. Are you sure you want to leave?" %}';
|
|
return e.returnValue;
|
|
}
|
|
});
|
|
|
|
form.addEventListener('submit', function() {
|
|
formChanged = false;
|
|
});
|
|
});
|
|
</script>
|
|
{% endblock %}
|