479 lines
18 KiB
HTML
479 lines
18 KiB
HTML
{% extends "base.html" %}
|
|
{% load static i18n widget_tweaks %}
|
|
|
|
{% block title %}{{ title }} - {{ 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);
|
|
}
|
|
|
|
/* 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 'agency_list' %}" class="text-decoration-none text-secondary">
|
|
<i class="fas fa-building me-1"></i> {% trans "Agencies" %}
|
|
</a>
|
|
</li>
|
|
{% if agency %}
|
|
<li class="breadcrumb-item">
|
|
<a href="{% url 'agency_detail' agency.slug %}" class="text-decoration-none text-secondary">
|
|
{{ agency.name }}
|
|
</a>
|
|
</li>
|
|
<li class="breadcrumb-item active" aria-current="page"
|
|
style="
|
|
color: #F43B5E; /* Rosy Accent Color */
|
|
font-weight: 600;">{% trans "Update" %}</li>
|
|
{% else %}
|
|
<li class="breadcrumb-item active" aria-current="page"
|
|
style="
|
|
color: #F43B5E; /* Rosy Accent Color */
|
|
font-weight: 600;">{% trans "Create" %}</li>
|
|
{% endif %}
|
|
</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-building me-2"></i> {{ title }}
|
|
</h1>
|
|
<div class="d-flex gap-2">
|
|
{% if agency %}
|
|
<a href="{% url 'agency_detail' agency.slug %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-eye me-1"></i> {% trans "View Details" %}
|
|
</a>
|
|
<a href="{% url 'agency_delete' agency.slug %}" class="btn btn-danger">
|
|
<i class="fas fa-trash me-1"></i> {% trans "Delete" %}
|
|
</a>
|
|
{% endif %}
|
|
<a href="{% url 'agency_list' %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-arrow-left me-1"></i> {% trans "Back to List" %}
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
{% if agency %}
|
|
<!-- Current Agency 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">
|
|
<div class="current-image d-flex align-items-center justify-content-center bg-light">
|
|
<i class="fas fa-building text-muted"></i>
|
|
</div>
|
|
<div>
|
|
<h5 class="mb-1">{{ agency.name }}</h5>
|
|
{% if agency.contact_person %}
|
|
<p class="text-muted mb-0">{% trans "Contact" %}: {{ agency.contact_person }}</p>
|
|
{% endif %}
|
|
{% if agency.email %}
|
|
<p class="text-muted mb-0">{{ agency.email }}</p>
|
|
{% endif %}
|
|
<small class="text-muted">
|
|
{% trans "Created" %}: {{ agency.created_at|date:"d M Y" }} •
|
|
{% trans "Last Updated" %}: {{ agency.updated_at|date:"d M Y" }}
|
|
</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<!-- 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" novalidate id="agency-form">
|
|
{% csrf_token %}
|
|
|
|
<!-- Name -->
|
|
<div class="mb-3">
|
|
<label for="{{ form.name.id_for_label }}" class="form-label">
|
|
{{ form.name.label }} <span class="text-danger">*</span>
|
|
</label>
|
|
{{ form.name|add_class:"form-control" }}
|
|
{% if form.name.errors %}
|
|
{% for error in form.name.errors %}
|
|
<div class="invalid-feedback d-block">{{ error }}</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% if form.name.help_text %}
|
|
<div class="form-text">{{ form.name.help_text }}</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<!-- Contact Person and Phone -->
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="{{ form.contact_person.id_for_label }}" class="form-label">
|
|
{{ form.contact_person.label }}
|
|
</label>
|
|
{{ form.contact_person|add_class:"form-control" }}
|
|
{% if form.contact_person.errors %}
|
|
{% for error in form.contact_person.errors %}
|
|
<div class="invalid-feedback d-block">{{ error }}</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% if form.contact_person.help_text %}
|
|
<div class="form-text">{{ form.contact_person.help_text }}</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<div class="col-md-6 mb-3">
|
|
<label for="{{ form.phone.id_for_label }}" class="form-label">
|
|
{{ form.phone.label }}
|
|
</label>
|
|
{{ form.phone|add_class:"form-control" }}
|
|
{% if form.phone.errors %}
|
|
{% for error in form.phone.errors %}
|
|
<div class="invalid-feedback d-block">{{ error }}</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% if form.phone.help_text %}
|
|
<div class="form-text">{{ form.phone.help_text }}</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Email and Website -->
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="{{ form.email.id_for_label }}" class="form-label">
|
|
{{ form.email.label }}
|
|
</label>
|
|
{{ form.email|add_class:"form-control" }}
|
|
{% if form.email.errors %}
|
|
{% for error in form.email.errors %}
|
|
<div class="invalid-feedback d-block">{{ error }}</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% if form.email.help_text %}
|
|
<div class="form-text">{{ form.email.help_text }}</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<div class="col-md-6 mb-3">
|
|
<label for="{{ form.website.id_for_label }}" class="form-label">
|
|
{{ form.website.label }}
|
|
</label>
|
|
{{ form.website|add_class:"form-control" }}
|
|
{% if form.website.errors %}
|
|
{% for error in form.website.errors %}
|
|
<div class="invalid-feedback d-block">{{ error }}</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% if form.website.help_text %}
|
|
<div class="form-text">{{ form.website.help_text }}</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Address -->
|
|
<div class="mb-3">
|
|
<label for="{{ form.address.id_for_label }}" class="form-label">
|
|
{{ form.address.label }}
|
|
</label>
|
|
{{ form.address|add_class:"form-control" }}
|
|
{% if form.address.errors %}
|
|
{% for error in form.address.errors %}
|
|
<div class="invalid-feedback d-block">{{ error }}</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% if form.address.help_text %}
|
|
<div class="form-text">{{ form.address.help_text }}</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<!-- Country and City -->
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="{{ form.country.id_for_label }}" class="form-label">
|
|
{{ form.country.label }}
|
|
</label>
|
|
{{ form.country|add_class:"form-control" }}
|
|
{% if form.country.errors %}
|
|
{% for error in form.country.errors %}
|
|
<div class="invalid-feedback d-block">{{ error }}</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% if form.country.help_text %}
|
|
<div class="form-text">{{ form.country.help_text }}</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<div class="col-md-6 mb-3">
|
|
<label for="{{ form.city.id_for_label }}" class="form-label">
|
|
{{ form.city.label }}
|
|
</label>
|
|
{{ form.city|add_class:"form-control" }}
|
|
{% if form.city.errors %}
|
|
{% for error in form.city.errors %}
|
|
<div class="invalid-feedback d-block">{{ error }}</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% if form.city.help_text %}
|
|
<div class="form-text">{{ form.city.help_text }}</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Description -->
|
|
<div class="mb-4">
|
|
<label for="{{ form.description.id_for_label }}" class="form-label">
|
|
{{ form.description.label }}
|
|
</label>
|
|
{{ form.description|add_class:"form-control" }}
|
|
{% if form.description.errors %}
|
|
{% for error in form.description.errors %}
|
|
<div class="invalid-feedback d-block">{{ error }}</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% if form.description.help_text %}
|
|
<div class="form-text">{{ form.description.help_text }}</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<div class="d-flex gap-2">
|
|
<button form="agency-form" type="submit" class="btn btn-main-action">
|
|
<i class="fas fa-save me-1"></i> {{ button_text }}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block customJS %}
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Form Validation
|
|
const form = document.getElementById('agency-form');
|
|
if (form) {
|
|
form.addEventListener('submit', function(e) {
|
|
const submitBtn = form.querySelector('button[type="submit"]');
|
|
submitBtn.classList.add('loading');
|
|
submitBtn.disabled = true;
|
|
|
|
// Basic validation
|
|
const name = document.getElementById('id_name');
|
|
if (name && !name.value.trim()) {
|
|
e.preventDefault();
|
|
submitBtn.classList.remove('loading');
|
|
submitBtn.disabled = false;
|
|
alert('{% trans "Agency name is required." %}');
|
|
return;
|
|
}
|
|
|
|
const email = document.getElementById('id_email');
|
|
if (email && email.value.trim() && !isValidEmail(email.value.trim())) {
|
|
e.preventDefault();
|
|
submitBtn.classList.remove('loading');
|
|
submitBtn.disabled = false;
|
|
alert('{% trans "Please enter a valid email address." %}');
|
|
return;
|
|
}
|
|
|
|
const website = document.getElementById('id_website');
|
|
if (website && website.value.trim() && !isValidURL(website.value.trim())) {
|
|
e.preventDefault();
|
|
submitBtn.classList.remove('loading');
|
|
submitBtn.disabled = false;
|
|
alert('{% trans "Please enter a valid website URL." %}');
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
|
|
// Email validation helper
|
|
function isValidEmail(email) {
|
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
return emailRegex.test(email);
|
|
}
|
|
|
|
// URL validation helper
|
|
function isValidURL(url) {
|
|
try {
|
|
new URL(url);
|
|
return true;
|
|
} catch (_) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Warn before leaving if changes are made
|
|
let formChanged = false;
|
|
const formInputs = form ? 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;
|
|
}
|
|
});
|
|
|
|
if (form) {
|
|
form.addEventListener('submit', function() {
|
|
formChanged = false;
|
|
});
|
|
}
|
|
});
|
|
</script>
|
|
{% endblock %}
|