143 lines
6.3 KiB
HTML
143 lines
6.3 KiB
HTML
{% extends "layouts/base.html" %}
|
|
{% load i18n static %}
|
|
|
|
{% block title %}{% trans "New Appreciation" %} - PX360{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="max-w-2xl mx-auto">
|
|
<header class="mb-6">
|
|
<div class="flex items-center justify-between">
|
|
<div>
|
|
<h1 class="text-2xl font-bold text-navy flex items-center gap-2">
|
|
<i data-lucide="heart" class="w-6 h-6 text-amber-500"></i>
|
|
{% trans "New Appreciation" %}
|
|
</h1>
|
|
<p class="text-sm text-slate mt-1">{% trans "Recognize a department for excellent service or care." %}</p>
|
|
</div>
|
|
<a href="{% url 'appreciation:appreciation_list' %}" class="text-slate hover:text-navy px-3 py-2 text-sm font-semibold flex items-center gap-2 border rounded-lg hover:bg-light transition">
|
|
<i data-lucide="arrow-left" class="w-4 h-4"></i> {% trans "Back" %}
|
|
</a>
|
|
</div>
|
|
</header>
|
|
|
|
<form method="post" class="bg-white rounded-2xl shadow-sm border border-slate-100 p-6 space-y-5">
|
|
{% csrf_token %}
|
|
|
|
{% if form.errors %}
|
|
<div class="bg-red-50 border border-red-200 text-red-700 rounded-xl p-4 space-y-1">
|
|
<p class="font-bold text-sm">{% trans "Please correct the errors below." %}</p>
|
|
<ul class="text-sm list-disc list-inside">
|
|
{% for field in form %}
|
|
{% for error in field.errors %}
|
|
<li><strong>{{ field.label }}</strong>: {{ error }}</li>
|
|
{% endfor %}
|
|
{% endfor %}
|
|
{% for error in form.non_field_errors %}
|
|
<li>{{ error }}</li>
|
|
{% endfor %}
|
|
</ul>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<div>
|
|
<label class="block text-sm font-semibold text-navy mb-2" for="{{ form.department.id_for_label }}">
|
|
{{ form.department.label }} <span class="text-red-500">*</span>
|
|
</label>
|
|
{{ form.department }}
|
|
{% if form.department.errors %}
|
|
<div class="mt-1 text-sm text-red-600">
|
|
{% for error in form.department.errors %}{{ error }}{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-semibold text-navy mb-2" for="{{ form.national_id.id_for_label }}">
|
|
{{ form.national_id.label }} <span class="text-red-500">*</span>
|
|
</label>
|
|
{{ form.national_id }}
|
|
{% if form.national_id.errors %}
|
|
<div class="mt-1 text-sm text-red-600">
|
|
{% for error in form.national_id.errors %}{{ error }}{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-semibold text-navy mb-2" for="staff_id">
|
|
{% trans "Staff Member" %} <span class="text-slate-400 font-normal">({% trans "optional" %})</span>
|
|
</label>
|
|
<select name="staff_id" id="staff_id" disabled
|
|
class="w-full px-4 py-3 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-navy/20 outline-none bg-slate-50">
|
|
<option value="">{% trans "Select department first" %}</option>
|
|
</select>
|
|
<p class="text-xs text-slate-400 mt-1">{% trans "Select the specific staff member, or leave blank for the department." %}</p>
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-semibold text-navy mb-2" for="{{ form.message_en.id_for_label }}">
|
|
{% trans "Message" %} <span class="text-red-500">*</span>
|
|
</label>
|
|
{{ form.message_en }}
|
|
{% if form.message_en.errors %}
|
|
<div class="mt-1 text-sm text-red-600">
|
|
{% for error in form.message_en.errors %}{{ error }}{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<div class="flex gap-3 pt-4 border-t border-slate-100">
|
|
<button type="submit" class="flex-1 bg-navy text-white px-5 py-3 rounded-xl font-bold text-sm hover:bg-blue transition flex items-center justify-center gap-2">
|
|
<i data-lucide="check" class="w-4 h-4"></i> {% trans "Create Appreciation" %}
|
|
</button>
|
|
<a href="{% url 'appreciation:appreciation_list' %}" class="px-5 py-3 border border-slate-200 text-slate-600 rounded-xl font-semibold text-sm hover:bg-slate-50 transition">
|
|
{% trans "Cancel" %}
|
|
</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block extra_js %}
|
|
<script>
|
|
var deptSelect = document.getElementById('{{ form.department.id_for_label }}');
|
|
var staffSelect = document.getElementById('staff_id');
|
|
|
|
function loadCreateStaff(deptId) {
|
|
if (!staffSelect) return;
|
|
if (!deptId) {
|
|
staffSelect.innerHTML = '<option value="">{% trans "Select department first" %}</option>';
|
|
staffSelect.disabled = true;
|
|
staffSelect.classList.add('bg-slate-50');
|
|
return;
|
|
}
|
|
staffSelect.innerHTML = '<option value="">{% trans "Loading..." %}</option>';
|
|
fetch('/organizations/dropdowns/department-staff/' + encodeURIComponent(deptId) + '/')
|
|
.then(function (r) { return r.json(); })
|
|
.then(function (items) {
|
|
var html = '<option value="">{% trans "Select staff (optional)" %}</option>';
|
|
(items || []).forEach(function (it) {
|
|
var id = it.staff_id || (it.staff && it.staff.id);
|
|
var name = it.name || (it.staff && it.staff.name) || id;
|
|
if (id) html += '<option value="' + id + '">' + name + '</option>';
|
|
});
|
|
staffSelect.innerHTML = html;
|
|
staffSelect.disabled = false;
|
|
staffSelect.classList.remove('bg-slate-50');
|
|
})
|
|
.catch(function () {
|
|
staffSelect.innerHTML = '<option value="">{% trans "Select staff (optional)" %}</option>';
|
|
staffSelect.disabled = false;
|
|
staffSelect.classList.remove('bg-slate-50');
|
|
});
|
|
}
|
|
|
|
if (deptSelect) {
|
|
deptSelect.addEventListener('change', function() { loadCreateStaff(this.value); });
|
|
if (deptSelect.value) loadCreateStaff(deptSelect.value);
|
|
}
|
|
|
|
if (typeof lucide !== 'undefined') lucide.createIcons();
|
|
</script>
|
|
{% endblock %}
|