HH/templates/px_sources/source_user_create_complaint.html
2026-03-09 16:10:24 +03:00

373 lines
19 KiB
HTML

{% extends "layouts/source_user_base.html" %}
{% load i18n %}
{% block title %}{% trans "Create Complaint" %} - {{ source.name_en }}{% endblock %}
{% block extra_css %}
<style>
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.animate-in {
animation: fadeIn 0.5s ease-out forwards;
}
</style>
{% endblock %}
{% block content %}
<div class="p-6 md:p-8 bg-gradient-to-br from-light to-blue-50 min-h-screen">
<!-- Page Header -->
<div class="flex flex-wrap justify-between items-center gap-4 mb-8 animate-in">
<div class="flex items-center gap-3">
<div class="flex items-center justify-center w-14 h-14 bg-gradient-to-br from-orange-400 to-orange-500 rounded-2xl shadow-lg shadow-orange-200">
<i data-lucide="plus-circle" class="w-8 h-8 text-white"></i>
</div>
<div>
<h1 class="text-2xl font-bold text-navy">
{% trans "Create Complaint" %}
</h1>
<p class="text-slate text-sm">
{% trans "Submit a new complaint from" %} <strong>{{ source.name_en }}</strong>
</p>
</div>
</div>
<a href="{% url 'px_sources:source_user_complaint_list' %}"
class="inline-flex items-center gap-2 px-5 py-2.5 bg-white border-2 border-blue-200 text-navy rounded-xl font-semibold hover:bg-blue-50 transition">
<i data-lucide="arrow-left" class="w-4 h-4"></i>
{% trans "Back to Complaints" %}
</a>
</div>
<!-- Info Banner -->
<div class="bg-blue-50 border border-blue-200 rounded-2xl p-4 mb-8 animate-in">
<div class="flex items-start gap-3">
<i data-lucide="info" class="w-5 h-5 text-blue-600 mt-0.5 flex-shrink-0"></i>
<div>
<p class="text-sm font-bold text-blue-800 mb-1">{% trans "Source Information" %}</p>
<p class="text-sm text-blue-700">
{% trans "This complaint will be automatically linked to" %} <strong>{{ source.name_en }}</strong>.
{% trans "All required fields are marked with" %} <span class="text-red-500">*</span>
</p>
</div>
</div>
</div>
<!-- Form -->
<div class="bg-white rounded-2xl shadow-sm border border-blue-100 overflow-hidden animate-in">
<form method="post" novalidate>
{% csrf_token %}
<div class="p-6 md:p-8">
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<!-- Complainant Name -->
<div>
<label for="{{ form.complainant_name.id_for_label }}" class="block text-sm font-bold text-navy mb-2">
{{ form.complainant_name.label }} <span class="text-red-500">*</span>
</label>
{{ form.complainant_name }}
{% if form.complainant_name.errors %}
<div class="flex items-center gap-2 mt-2 text-red-600 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4"></i>
{% for error in form.complainant_name.errors %}{{ error }}{% endfor %}
</div>
{% endif %}
</div>
<!-- Mobile Number -->
<div>
<label for="{{ form.mobile_number.id_for_label }}" class="block text-sm font-bold text-navy mb-2">
{{ form.mobile_number.label }} <span class="text-red-500">*</span>
</label>
{{ form.mobile_number }}
{% if form.mobile_number.errors %}
<div class="flex items-center gap-2 mt-2 text-red-600 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4"></i>
{% for error in form.mobile_number.errors %}{{ error }}{% endfor %}
</div>
{% endif %}
</div>
<!-- Email -->
<div>
<label for="{{ form.email.id_for_label }}" class="block text-sm font-bold text-navy mb-2">
{{ form.email.label }}
</label>
{{ form.email }}
{% if form.email.errors %}
<div class="flex items-center gap-2 mt-2 text-red-600 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4"></i>
{% for error in form.email.errors %}{{ error }}{% endfor %}
</div>
{% endif %}
</div>
<!-- Relation to Patient -->
<div>
<label for="{{ form.relation_to_patient.id_for_label }}" class="block text-sm font-bold text-navy mb-2">
{{ form.relation_to_patient.label }} <span class="text-red-500">*</span>
</label>
{{ form.relation_to_patient }}
{% if form.relation_to_patient.errors %}
<div class="flex items-center gap-2 mt-2 text-red-600 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4"></i>
{% for error in form.relation_to_patient.errors %}{{ error }}{% endfor %}
</div>
{% endif %}
</div>
<!-- Patient Name -->
<div>
<label for="{{ form.patient_name.id_for_label }}" class="block text-sm font-bold text-navy mb-2">
{{ form.patient_name.label }} <span class="text-red-500">*</span>
</label>
{{ form.patient_name }}
{% if form.patient_name.errors %}
<div class="flex items-center gap-2 mt-2 text-red-600 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4"></i>
{% for error in form.patient_name.errors %}{{ error }}{% endfor %}
</div>
{% endif %}
</div>
<!-- National ID -->
<div>
<label for="{{ form.national_id.id_for_label }}" class="block text-sm font-bold text-navy mb-2">
{{ form.national_id.label }} <span class="text-red-500">*</span>
</label>
{{ form.national_id }}
{% if form.national_id.errors %}
<div class="flex items-center gap-2 mt-2 text-red-600 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4"></i>
{% for error in form.national_id.errors %}{{ error }}{% endfor %}
</div>
{% endif %}
</div>
<!-- Incident Date -->
<div>
<label for="{{ form.incident_date.id_for_label }}" class="block text-sm font-bold text-navy mb-2">
{{ form.incident_date.label }} <span class="text-red-500">*</span>
</label>
{{ form.incident_date }}
{% if form.incident_date.errors %}
<div class="flex items-center gap-2 mt-2 text-red-600 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4"></i>
{% for error in form.incident_date.errors %}{{ error }}{% endfor %}
</div>
{% endif %}
</div>
<!-- Staff Name -->
<div>
<label for="{{ form.staff_name.id_for_label }}" class="block text-sm font-bold text-navy mb-2">
{{ form.staff_name.label }}
</label>
{{ form.staff_name }}
<p class="text-xs text-slate mt-1">{% trans "Optional - Name of staff involved" %}</p>
{% if form.staff_name.errors %}
<div class="flex items-center gap-2 mt-2 text-red-600 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4"></i>
{% for error in form.staff_name.errors %}{{ error }}{% endfor %}
</div>
{% endif %}
</div>
<!-- Hospital -->
<div>
<label for="{{ form.hospital.id_for_label }}" class="block text-sm font-bold text-navy mb-2">
{{ form.hospital.label }} <span class="text-red-500">*</span>
</label>
{{ form.hospital }}
{% if form.hospital.errors %}
<div class="flex items-center gap-2 mt-2 text-red-600 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4"></i>
{% for error in form.hospital.errors %}{{ error }}{% endfor %}
</div>
{% endif %}
</div>
<!-- Location -->
<div>
<label for="{{ form.location.id_for_label }}" class="block text-sm font-bold text-navy mb-2">
{{ form.location.label }} <span class="text-red-500">*</span>
</label>
{{ form.location }}
{% if form.location.errors %}
<div class="flex items-center gap-2 mt-2 text-red-600 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4"></i>
{% for error in form.location.errors %}{{ error }}{% endfor %}
</div>
{% endif %}
</div>
<!-- Main Section -->
<div>
<label for="{{ form.main_section.id_for_label }}" class="block text-sm font-bold text-navy mb-2">
{{ form.main_section.label }} <span class="text-red-500">*</span>
</label>
{{ form.main_section }}
{% if form.main_section.errors %}
<div class="flex items-center gap-2 mt-2 text-red-600 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4"></i>
{% for error in form.main_section.errors %}{{ error }}{% endfor %}
</div>
{% endif %}
</div>
<!-- Subsection -->
<div>
<label for="{{ form.subsection.id_for_label }}" class="block text-sm font-bold text-navy mb-2">
{{ form.subsection.label }} <span class="text-red-500">*</span>
</label>
{{ form.subsection }}
{% if form.subsection.errors %}
<div class="flex items-center gap-2 mt-2 text-red-600 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4"></i>
{% for error in form.subsection.errors %}{{ error }}{% endfor %}
</div>
{% endif %}
</div>
<!-- Complaint Details (Description) -->
<div class="md:col-span-2">
<label for="{{ form.complaint_details.id_for_label }}" class="block text-sm font-bold text-navy mb-2">
{{ form.complaint_details.label }} <span class="text-red-500">*</span>
</label>
{{ form.complaint_details }}
{% if form.complaint_details.errors %}
<div class="flex items-center gap-2 mt-2 text-red-600 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4"></i>
{% for error in form.complaint_details.errors %}{{ error }}{% endfor %}
</div>
{% endif %}
</div>
<!-- Expected Result -->
<div class="md:col-span-2">
<label for="{{ form.expected_result.id_for_label }}" class="block text-sm font-bold text-navy mb-2">
{{ form.expected_result.label }}
</label>
{{ form.expected_result }}
<p class="text-xs text-slate mt-1">{% trans "What do you expect as a resolution? (Optional)" %}</p>
{% if form.expected_result.errors %}
<div class="flex items-center gap-2 mt-2 text-red-600 text-sm">
<i data-lucide="alert-circle" class="w-4 h-4"></i>
{% for error in form.expected_result.errors %}{{ error }}{% endfor %}
</div>
{% endif %}
</div>
</div>
</div>
<!-- Form Actions -->
<div class="px-6 py-4 bg-gradient-to-r from-blue-50 to-transparent border-t border-blue-100 flex gap-3">
<button type="submit"
class="inline-flex items-center gap-2 px-6 py-3 bg-gradient-to-r from-navy to-blue text-white rounded-xl font-semibold hover:from-navy hover:to-blue transition shadow-lg shadow-blue-200">
<i data-lucide="check" class="w-5 h-5"></i>
{% trans "Submit Complaint" %}
</button>
<a href="{% url 'px_sources:source_user_complaint_list' %}"
class="inline-flex items-center gap-2 px-6 py-3 bg-white border-2 border-slate-200 text-slate-700 rounded-xl font-semibold hover:bg-slate-50 transition">
<i data-lucide="x" class="w-5 h-5"></i>
{% trans "Cancel" %}
</a>
</div>
</form>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
lucide.createIcons();
// Set max date for incident date to today
const incidentDateInput = document.getElementById('{{ form.incident_date.id_for_label }}');
if (incidentDateInput) {
const today = new Date().toISOString().split('T')[0];
incidentDateInput.setAttribute('max', today);
}
// Cascading dropdowns for Location → Section → Subsection
const locationSelect = document.getElementById('{{ form.location.id_for_label }}');
const mainSectionSelect = document.getElementById('{{ form.main_section.id_for_label }}');
const subsectionSelect = document.getElementById('{{ form.subsection.id_for_label }}');
// Load sections when location changes
if (locationSelect && mainSectionSelect) {
locationSelect.addEventListener('change', function() {
const locationId = this.value;
// Clear and disable dependent dropdowns
mainSectionSelect.innerHTML = '<option value="">Select Section</option>';
subsectionSelect.innerHTML = '<option value="">Select Subsection</option>';
mainSectionSelect.disabled = true;
subsectionSelect.disabled = true;
if (locationId) {
// Fetch sections for this location using the AJAX endpoint
fetch(`/organizations/ajax/main-sections/?location_id=${locationId}`)
.then(response => response.json())
.then(data => {
if (data.sections && data.sections.length > 0) {
data.sections.forEach(section => {
const option = document.createElement('option');
option.value = section.id;
option.textContent = section.name_en || section.name;
mainSectionSelect.appendChild(option);
});
mainSectionSelect.disabled = false;
}
})
.catch(error => {
console.error('Error loading sections:', error);
});
}
});
// Trigger change on page load if location is pre-selected
if (locationSelect.value) {
locationSelect.dispatchEvent(new Event('change'));
}
}
// Load subsections when main section changes
if (mainSectionSelect && subsectionSelect) {
mainSectionSelect.addEventListener('change', function() {
const locationId = locationSelect ? locationSelect.value : null;
const sectionId = this.value;
// Clear and disable subsection dropdown
subsectionSelect.innerHTML = '<option value="">Select Subsection</option>';
subsectionSelect.disabled = true;
if (locationId && sectionId) {
// Fetch subsections for this location and section
fetch(`/organizations/ajax/subsections/?location_id=${locationId}&main_section_id=${sectionId}`)
.then(response => response.json())
.then(data => {
if (data.subsections && data.subsections.length > 0) {
data.subsections.forEach(subsection => {
const option = document.createElement('option');
option.value = subsection.id;
option.textContent = subsection.name_en || subsection.name;
subsectionSelect.appendChild(option);
});
subsectionSelect.disabled = false;
}
})
.catch(error => {
console.error('Error loading subsections:', error);
});
}
});
// Trigger change on page load if section is pre-selected
if (mainSectionSelect.value) {
mainSectionSelect.dispatchEvent(new Event('change'));
}
}
});
</script>
{% endblock %}