HH/templates/appreciation/appreciation_detail.html
2026-07-11 19:24:28 +03:00

447 lines
23 KiB
HTML

{% extends "layouts/base.html" %}
{% load i18n static %}
{% block title %}{% trans "Appreciation Detail" %} - PX360{% endblock %}
{% block extra_css %}
<style>
.tab-active {
border-bottom: 3px solid #005696;
color: #005696;
font-weight: 700;
}
.tab-inactive {
color: #64748b;
font-weight: 500;
}
.tab-inactive:hover {
color: #005696;
}
.toggle-switch {
position: relative;
width: 44px;
height: 24px;
background: #cbd5e1;
border-radius: 12px;
cursor: pointer;
transition: background 0.3s;
}
.toggle-switch.active {
background: #005696;
}
.toggle-switch::after {
content: '';
position: absolute;
top: 2px;
left: 2px;
width: 20px;
height: 20px;
background: white;
border-radius: 50%;
transition: transform 0.3s;
box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch.active::after {
transform: translateX(20px);
}
</style>
{% endblock %}
{% block content %}
<header class="mb-6">
<div class="flex items-center gap-2 text-sm text-slate mb-2">
<a href="{% url 'appreciation:appreciation_list' %}" class="hover:text-navy">{% trans "Appreciations" %}</a>
<i data-lucide="chevron-right" class="w-4 h-4"></i>
<span class="font-bold text-navy">{% trans "Detail" %}</span>
<span class="px-2.5 py-1 rounded-full text-[10px] font-bold uppercase
{% if appreciation.status == 'draft' %}bg-amber-100 text-amber-700
{% elif appreciation.status == 'activated' %}bg-blue-100 text-blue-700
{% elif appreciation.status == 'ai_analyzed' %}bg-purple-100 text-purple-700
{% elif appreciation.status == 'sent' %}bg-green-100 text-green-700
{% elif appreciation.status == 'acknowledged' %}bg-emerald-100 text-emerald-700
{% else %}bg-slate-100 text-slate-600{% endif %}">
{{ appreciation.get_status_display }}
</span>
{% if can_send %}
<span class="px-2 py-0.5 rounded-full text-[10px] font-bold uppercase bg-amber-100 text-amber-700">
<i data-lucide="alert-circle" class="w-3 h-3 inline"></i> {% trans "Not Sent to Dept" %}
</span>
{% endif %}
</div>
<div class="flex items-center justify-between">
<h1 class="text-2xl font-bold text-navy flex items-center gap-3">
<i data-lucide="heart" class="w-7 h-7 text-pink-500"></i>
{% trans "Appreciation Detail" %}
</h1>
<div class="flex items-center gap-3">
{% comment %} <a href="{% url 'appreciation:appreciation_pdf' pk=appreciation.pk %}" target="_blank"
class="inline-flex items-center gap-1.5 px-3 py-1.5 border border-slate-200 rounded-lg text-xs font-semibold text-slate hover:border-navy hover:text-navy transition">
<i data-lucide="file-text" class="w-3.5 h-3.5"></i> {% trans "PDF" %}
</a> {% endcomment %}
<span class="text-xs text-slate-400">
{{ appreciation.created_at|date:"Y-m-d H:i" }} &mdash; {{ appreciation.hospital.get_localized_name }}
</span>
</div>
</div>
</header>
<nav class="bg-white px-6 flex gap-6 border-b shadow-sm mb-6 rounded-t-2xl">
<button class="py-4 text-sm tab-active" onclick="switchTab('details')" id="tab-details">{% trans "Details" %}</button>
{% if appreciation.ai_analysis %}
<button class="py-4 text-sm tab-inactive" onclick="switchTab('ai')" id="tab-ai">{% trans "AI Analysis" %}</button>
{% endif %}
<button class="py-4 text-sm tab-inactive" onclick="switchTab('notes')" id="tab-notes">
{% trans "Notes" %}
{% if notes_count %}<span class="ml-1 px-1.5 py-0.5 bg-slate-100 text-slate-600 text-xs rounded-full">{{ notes_count }}</span>{% endif %}
</button>
</nav>
<main class="grid grid-cols-12 gap-6">
<div class="col-span-8 space-y-6">
<div id="panel-details" class="tab-panel">
<section class="bg-white rounded-2xl p-6 shadow-sm border border-slate-100 mb-6">
<h3 class="font-bold text-navy mb-4 flex items-center gap-2">
<i data-lucide="message-square" class="w-5 h-5 text-emerald-600"></i>
{% trans "Appreciation Message" %}
</h3>
<p class="text-slate-700 text-sm leading-relaxed">{{ appreciation.message_en|linebreaks }}</p>
{% if appreciation.message_ar %}
<div class="mt-4 pt-4 border-t border-slate-100">
<p class="text-xs font-bold text-slate uppercase tracking-wider mb-1">{% trans "Arabic" %}</p>
<p class="text-slate-700 text-sm leading-relaxed" dir="rtl">{{ appreciation.message_ar|linebreaks }}</p>
</div>
{% endif %}
</section>
{% if metadata %}
<section class="bg-white rounded-2xl p-6 shadow-sm border border-slate-100 mb-6">
<h3 class="font-bold text-navy mb-4 flex items-center gap-2">
<i data-lucide="user" class="w-5 h-5 text-blue-600"></i>
{% trans "Submitted By" %}
</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
{% if metadata.submitted_by_name %}
<div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Name" %}</p>
<p class="text-sm font-semibold text-navy">{{ metadata.submitted_by_name }}</p>
</div>
{% endif %}
{% if metadata.submitted_by_phone %}
<div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Phone" %}</p>
<p class="text-sm font-semibold text-navy">{{ metadata.submitted_by_phone }}</p>
</div>
{% endif %}
{% if metadata.submitted_by_email %}
<div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Email" %}</p>
<p class="text-sm font-semibold text-navy">{{ metadata.submitted_by_email }}</p>
</div>
{% endif %}
{% if metadata.staff_name_mentioned %}
<div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Staff Mentioned" %}</p>
<p class="text-sm font-semibold text-navy">{{ metadata.staff_name_mentioned }}</p>
</div>
{% endif %}
</div>
</section>
{% endif %}
{% if appreciation.recipient %}
<section class="bg-white rounded-2xl p-6 shadow-sm border border-slate-100 mb-6">
<h3 class="font-bold text-navy mb-4 flex items-center gap-2">
<i data-lucide="user-check" class="w-5 h-5 text-blue-600"></i>
{% trans "Appreciation For" %}
</h3>
<div class="flex items-center gap-3">
<div class="w-10 h-10 rounded-full bg-navy/10 flex items-center justify-center">
<i data-lucide="user" class="w-5 h-5 text-navy"></i>
</div>
<div>
<p class="text-sm font-bold text-navy">{{ appreciation.get_recipient_name }}</p>
{% if appreciation.department %}
<p class="text-xs text-slate">{{ appreciation.department.get_localized_name }}</p>
{% endif %}
</div>
</div>
</section>
{% endif %}
{% if appreciation.status == 'sent' or appreciation.status == 'acknowledged' %}
<section class="bg-white rounded-2xl p-6 shadow-sm border border-green-200 mb-6">
<h3 class="font-bold text-green-800 mb-4 flex items-center gap-2">
<i data-lucide="check-circle-2" class="w-5 h-5 text-green-600"></i>
{% trans "Sent" %}
</h3>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Sent At" %}</p>
<p class="text-sm font-semibold text-navy">{{ appreciation.sent_at|date:"Y-m-d H:i" }}</p>
</div>
{% comment %} <div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "To Manager" %}</p>
<p class="text-sm font-semibold {% if appreciation.send_to_manager %}text-green-600{% else %}text-slate{% endif %}">
{% if appreciation.send_to_manager %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}
</p>
</div> {% endcomment %}
{% comment %} <div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "To Department" %}</p>
<p class="text-sm font-semibold {% if appreciation.send_to_department %}text-green-600{% else %}text-slate{% endif %}">
{% if appreciation.send_to_department %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}
</p>
</div> {% endcomment %}
</div>
{% if appreciation.custom_message %}
<div class="mt-4 pt-4 border-t border-green-100">
<p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Custom Message" %}</p>
<p class="text-sm text-slate-700">{{ appreciation.custom_message }}</p>
</div>
{% endif %}
{% if appreciation.cc_list %}
<div class="mt-4 pt-4 border-t border-green-100">
<p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "CC" %}</p>
<div class="flex flex-wrap gap-1.5">
{% for email in appreciation.cc_list %}
<span class="px-2 py-0.5 rounded-full text-xs font-bold bg-green-100 text-green-700">{{ email }}</span>
{% endfor %}
</div>
</div>
{% endif %}
{% if appreciation.acknowledged_at %}
<div class="mt-4 pt-4 border-t border-green-100">
<div class="flex items-center gap-2">
<i data-lucide="check-circle" class="w-4 h-4 text-emerald-600"></i>
<p class="text-sm font-semibold text-emerald-700">{% trans "Acknowledged on" %} {{ appreciation.acknowledged_at|date:"Y-m-d H:i" }}</p>
</div>
</div>
{% endif %}
</section>
{% endif %}
</div>
{% if appreciation.ai_analysis %}
<div id="panel-ai" class="tab-panel hidden">
<section class="bg-white rounded-2xl p-6 shadow-sm border border-purple-200">
<h3 class="font-bold text-purple-800 mb-4 flex items-center gap-2">
<i data-lucide="sparkles" class="w-5 h-5 text-purple-600"></i>
{% trans "AI Analysis" %}
</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-5">
{% if appreciation.ai_analysis.summary_en %}
<div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Summary (EN)" %}</p>
<p class="text-sm text-slate-700">{{ appreciation.ai_analysis.summary_en }}</p>
</div>
{% endif %}
{% if appreciation.ai_analysis.summary_ar %}
<div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Summary (AR)" %}</p>
<p class="text-sm text-slate-700" dir="rtl">{{ appreciation.ai_analysis.summary_ar }}</p>
</div>
{% endif %}
{% if appreciation.ai_analysis.themes %}
<div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Themes" %}</p>
<div class="flex flex-wrap gap-1.5">
{% for theme in appreciation.ai_analysis.themes %}
<span class="px-2 py-0.5 rounded-full text-xs font-bold bg-purple-100 text-purple-700">{{ theme }}</span>
{% endfor %}
</div>
</div>
{% endif %}
{% if appreciation.ai_analysis.tone %}
<div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Tone" %}</p>
<span class="px-2.5 py-1 rounded-full text-xs font-bold capitalize bg-blue-100 text-blue-700">{{ appreciation.ai_analysis.tone }}</span>
</div>
{% endif %}
</div>
{% if appreciation.ai_analysis.suggested_response_en %}
<div class="mt-4 pt-4 border-t border-purple-100">
<p class="text-[10px] font-bold text-slate uppercase tracking-wider mb-1">{% trans "Suggested Response" %}</p>
<p class="text-sm text-slate-600 bg-purple-50 rounded-lg p-3">{{ appreciation.ai_analysis.suggested_response_en }}</p>
</div>
{% endif %}
</section>
</div>
{% endif %}
<div id="panel-notes" class="tab-panel hidden">
{% include "partials/notes_panel.html" %}
</div>
</div>
<div class="col-span-4 space-y-6">
{% if can_activate %}
<section class="bg-white rounded-2xl p-6 shadow-sm border border-emerald-200">
<h3 class="font-bold text-emerald-800 mb-4 text-sm flex items-center gap-2">
<i data-lucide="zap" class="w-4 h-4"></i> {% trans "Activate Appreciation" %}
</h3>
<form method="post" action="{% url 'appreciation:appreciation_activate' pk=appreciation.pk %}">
{% csrf_token %}
<p class="text-slate text-xs mb-4">{% trans "Activate this appreciation to make it ready for routing to a department." %}</p>
<button type="submit" class="w-full px-4 py-2.5 bg-emerald-600 text-white rounded-xl font-bold hover:bg-emerald-700 transition text-sm inline-flex items-center justify-center gap-2">
<i data-lucide="zap" class="w-4 h-4"></i> {% trans "Activate" %}
</button>
</form>
</section>
{% endif %}
{% if can_send %}
<section class="bg-white rounded-2xl p-6 shadow-sm border border-blue-200">
<h3 class="font-bold text-navy mb-4 text-sm flex items-center gap-2">
<i data-lucide="send" class="w-4 h-4"></i> {% trans "Send to Department" %}
</h3>
<p class="text-slate text-xs mb-4">{% trans "Route this appreciation to a department or a specific person for acknowledgment." %}</p>
<button onclick="document.getElementById('aprSendModal').style.display='flex'"
class="w-full px-4 py-2.5 bg-navy text-white rounded-xl font-bold hover:bg-blue transition text-sm inline-flex items-center justify-center gap-2">
<i data-lucide="send" class="w-4 h-4"></i> {% trans "Send to Department" %}
</button>
</section>
{% endif %}
</div>
</main>
<!-- Send to Department Modal (department + staff) -->
<div id="aprSendModal" style="display:none" class="fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4">
<div class="bg-white rounded-2xl shadow-2xl w-full max-w-md mx-4">
<div class="flex items-center justify-between p-5 border-b border-slate-100">
<h3 class="text-lg font-bold text-navy flex items-center gap-2"><i data-lucide="send" class="w-5 h-5"></i> {% trans "Send to Department" %}</h3>
<button type="button" onclick="document.getElementById('aprSendModal').style.display='none'" class="p-1.5 rounded-lg hover:bg-slate-100 text-slate-400"><i data-lucide="x" class="w-5 h-5"></i></button>
</div>
<form id="aprSendForm" onsubmit="handleAprSendSubmit(event)">
{% csrf_token %}
<div class="p-5 space-y-4">
<div id="aprSendError" class="hidden text-sm text-red-600 bg-red-50 border border-red-200 p-3 rounded-lg"></div>
<div>
<label class="block text-sm font-semibold text-slate-700 mb-1.5">{% trans "Department" %} <span class="text-red-500">*</span></label>
<select id="aprDeptSelect" name="department_id" onchange="loadAprStaff(this.value)"
class="w-full border border-slate-200 rounded-xl p-3 text-sm focus:ring-2 focus:ring-navy/20 outline-none" required>
<option value="">{% trans "Select Department" %}</option>
{% for dept in hospital_departments %}
<option value="{{ dept.id }}">{{ dept.get_localized_name }}</option>
{% endfor %}
</select>
</div>
<div>
<label class="block text-sm font-semibold text-slate-700 mb-1.5">{% trans "Staff" %} <span class="text-slate-400 font-normal">({% trans "optional" %})</span></label>
<select id="aprStaffSelect" name="staff_id"
class="w-full border border-slate-200 rounded-xl p-3 text-sm focus:ring-2 focus:ring-navy/20 outline-none">
<option value="">{% trans "Select department first" %}</option>
</select>
<p class="text-xs text-slate-400 mt-1">{% trans "The staff member, department champion and manager will be notified." %}</p>
</div>
<div>
<label class="block text-sm font-semibold text-slate-700 mb-1.5">{% trans "Note" %} <span class="text-slate-400 font-normal">({% trans "optional" %})</span></label>
<textarea name="note" rows="2" class="w-full border border-slate-200 rounded-xl p-3 text-sm focus:ring-2 focus:ring-navy/20 outline-none" placeholder="{% trans 'Add context...' %}"></textarea>
</div>
</div>
<div class="p-5 border-t border-slate-100 flex gap-3">
<button type="button" onclick="document.getElementById('aprSendModal').style.display='none'" class="flex-1 px-4 py-2.5 border border-slate-200 text-slate-600 rounded-xl font-semibold hover:bg-slate-50 transition">{% trans "Cancel" %}</button>
<button type="submit" id="aprSendBtn" class="flex-1 px-4 py-2.5 bg-navy text-white rounded-xl font-bold hover:bg-blue transition flex items-center justify-center gap-2">
<i data-lucide="send" class="w-4 h-4"></i> {% trans "Send" %}
</button>
</div>
</form>
</div>
</div>
<script>
function loadAprStaff(deptId) {
var staffSel = document.getElementById('aprStaffSelect');
if (!deptId) {
staffSel.innerHTML = '<option value="">{% trans "Select department first" %}</option>';
return;
}
staffSel.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>';
});
staffSel.innerHTML = html;
})
.catch(function () { staffSel.innerHTML = '<option value="">{% trans "Select staff (optional)" %}</option>'; });
}
function handleAprSendSubmit(event) {
event.preventDefault();
var deptId = document.getElementById('aprDeptSelect').value;
var err = document.getElementById('aprSendError');
var btn = document.getElementById('aprSendBtn');
if (!deptId) {
err.textContent = '{% trans "Please select a department." %}';
err.classList.remove('hidden');
return;
}
err.classList.add('hidden');
btn.disabled = true;
btn.innerHTML = '<span class="inline-block w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin mr-2"></span>{% trans "Sending..." %}';
fetch('{% url "appreciation:appreciation_send_to" pk=appreciation.pk %}', {
method: 'POST',
body: new FormData(event.target),
headers: { 'X-Requested-With': 'XMLHttpRequest', 'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value || '' }
})
.then(async function (r) {
var data = null;
try { data = await r.json(); } catch (e) {}
if (data && data.success === true) return data;
throw new Error((data && data.error) || (r.ok ? '{% trans "Failed to send." %}' : '{% trans "Server error" %} (' + r.status + ')'));
})
.then(function () { window.location.reload(); })
.catch(function (e) {
err.textContent = e.message;
err.classList.remove('hidden');
btn.disabled = false;
btn.innerHTML = '<i data-lucide="send" class="w-4 h-4"></i> {% trans "Send" %}';
if (window.lucide) lucide.createIcons();
});
}
</script>
<script>
function switchTab(tabName) {
document.querySelectorAll('.tab-panel').forEach(panel => panel.classList.add('hidden'));
document.getElementById('panel-' + tabName).classList.remove('hidden');
document.querySelectorAll('main nav button').forEach(tab => {
tab.classList.remove('tab-active');
tab.classList.add('tab-inactive');
});
document.getElementById('tab-' + tabName).classList.remove('tab-inactive');
document.getElementById('tab-' + tabName).classList.add('tab-active');
if (window.lucide) lucide.createIcons();
}
document.getElementById('id_staff')?.addEventListener('change', function() {
var selected = this.options[this.selectedIndex];
var deptId = selected.getAttribute('data-department');
var deptSelect = document.getElementById('id_department');
if (deptId) {
deptSelect.value = deptId;
if (deptSelect.tomselect) {
deptSelect.tomselect.setValue(deptId);
}
}
});
document.querySelectorAll('.toggle-switch').forEach(function(toggle) {
toggle.addEventListener('click', function() {
var checkbox = this.querySelector('input[type="checkbox"]');
if (checkbox) {
checkbox.checked = this.classList.contains('active');
}
});
});
document.addEventListener('DOMContentLoaded', function() {
if (typeof lucide !== 'undefined') lucide.createIcons();
});
</script>
{% endblock %}