HH/templates/organizations/staff_list.html
2026-02-22 08:35:53 +03:00

387 lines
22 KiB
HTML

{% extends "layouts/base.html" %}
{% load i18n %}
{% block title %}{% trans "Staff Management" %} - PX360{% endblock %}
{% block content %}
<!-- Header -->
<header class="mb-6">
<div class="flex justify-between items-start">
<div>
<h1 class="text-2xl font-bold text-navy">{% trans "Staff Management" %}</h1>
<p class="text-sm text-slate mt-1">{% trans "Manage hospital staff and their user accounts" %}</p>
</div>
{% if user.is_px_admin or user.is_hospital_admin %}
<a href="{% url 'organizations:staff_create' %}" class="bg-navy text-white px-5 py-2.5 rounded-xl text-sm font-bold shadow-lg shadow-navy/20 hover:bg-blue flex items-center gap-2 transition">
<i data-lucide="plus" class="w-4 h-4"></i> {% trans "Add New Staff" %}
</a>
{% endif %}
</div>
</header>
<!-- Filters -->
<div class="bg-white p-5 rounded-2xl shadow-sm border border-slate-100 mb-6">
<form method="get" class="flex flex-wrap gap-4 items-end">
<div class="flex items-center gap-2">
<label class="text-xs font-bold text-slate uppercase">{% trans "Status" %}</label>
<select name="status" class="px-3 py-1.5 bg-white border border-slate-200 rounded-lg text-xs focus:outline-none focus:ring-2 focus:ring-navy">
<option value="">{% trans "All" %}</option>
<option value="active" {% if request.GET.status == 'active' %}selected{% endif %}>{% trans "Active" %}</option>
<option value="inactive" {% if request.GET.status == 'inactive' %}selected{% endif %}>{% trans "Inactive" %}</option>
</select>
</div>
<div class="flex items-center gap-2">
<label class="text-xs font-bold text-slate uppercase">{% trans "Type" %}</label>
<select name="staff_type" class="px-3 py-1.5 bg-white border border-slate-200 rounded-lg text-xs focus:outline-none focus:ring-2 focus:ring-navy">
<option value="">{% trans "All" %}</option>
<option value="physician" {% if request.GET.staff_type == 'physician' %}selected{% endif %}>{% trans "Physician" %}</option>
<option value="nurse" {% if request.GET.staff_type == 'nurse' %}selected{% endif %}>{% trans "Nurse" %}</option>
<option value="admin" {% if request.GET.staff_type == 'admin' %}selected{% endif %}>{% trans "Admin" %}</option>
<option value="other" {% if request.GET.staff_type == 'other' %}selected{% endif %}>{% trans "Other" %}</option>
</select>
</div>
<div class="flex items-center gap-2">
<label class="text-xs font-bold text-slate uppercase">{% trans "Department" %}</label>
<select name="department" class="px-3 py-1.5 bg-white border border-slate-200 rounded-lg text-xs focus:outline-none focus:ring-2 focus:ring-navy">
<option value="">{% trans "All" %}</option>
{% for dept in departments %}
<option value="{{ dept.id }}" {% if request.GET.department == dept.id|stringformat:"s" %}selected{% endif %}>{{ dept.name }}</option>
{% endfor %}
</select>
</div>
<div class="flex items-center gap-2">
<label class="text-xs font-bold text-slate uppercase">{% trans "Section" %}</label>
<select name="section" class="px-3 py-1.5 bg-white border border-slate-200 rounded-lg text-xs focus:outline-none focus:ring-2 focus:ring-navy">
<option value="">{% trans "All" %}</option>
{% for sec in sections %}
<option value="{{ sec }}" {% if request.GET.section == sec %}selected{% endif %}>{{ sec }}</option>
{% endfor %}
</select>
</div>
<div class="flex items-center gap-2">
<label class="text-xs font-bold text-slate uppercase">{% trans "Search" %}</label>
<input type="text" name="search" class="px-3 py-1.5 border border-slate-200 rounded-lg text-xs focus:outline-none focus:ring-2 focus:ring-navy w-40" placeholder="{% trans 'Name, ID...' %}" value="{{ request.GET.search|default:'' }}">
</div>
<div class="flex items-center gap-2">
<button type="submit" class="px-4 py-1.5 bg-navy text-white rounded-lg text-xs font-bold hover:bg-blue transition">{% trans "Apply" %}</button>
<a href="{% url 'organizations:staff_list' %}" class="px-4 py-1.5 border border-slate-200 rounded-lg text-xs font-semibold text-slate hover:bg-light transition">{% trans "Clear" %}</a>
</div>
</form>
</div>
<!-- Staff List -->
<div class="bg-white rounded-2xl shadow-sm border border-slate-100 overflow-hidden">
<div class="flex justify-between items-center p-5 border-b border-slate-100">
<h3 class="font-bold text-navy flex items-center gap-2 text-sm">
<i data-lucide="users" class="w-4 h-4"></i>
{% trans "Staff List" %}
</h3>
<div class="text-xs text-slate font-medium">
{% trans "Showing" %} <span class="font-bold text-navy">{{ staff.start_index|default:0 }}-{{ staff.end_index|default:0 }}</span> {% trans "of" %} <span class="font-bold text-navy">{{ staff.paginator.count|default:0 }}</span>
</div>
</div>
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-slate-50 border-b border-slate-100">
<tr class="text-xs font-bold text-slate uppercase tracking-wider">
<th class="px-5 py-3 text-left">{% trans "Name" %}</th>
<th class="px-5 py-3 text-left">{% trans "Type" %}</th>
<th class="px-5 py-3 text-left">{% trans "Job Title" %}</th>
<th class="px-5 py-3 text-left">{% trans "Department" %}</th>
<th class="px-5 py-3 text-left">{% trans "Manager" %}</th>
<th class="px-5 py-3 text-left">{% trans "User Account" %}</th>
<th class="px-5 py-3 text-left">{% trans "Status" %}</th>
<th class="px-5 py-3 text-left">{% trans "Actions" %}</th>
</tr>
</thead>
<tbody class="text-sm divide-y divide-slate-100">
{% for staff_member in staff.object_list %}
<tr class="hover:bg-light/30 transition cursor-pointer" onclick="window.location.href='{% url 'organizations:staff_detail' staff_member.id %}'">
<td class="px-5 py-4">
<div class="flex items-center gap-2">
<div class="w-8 h-8 bg-navy rounded-full flex items-center justify-center text-white font-bold text-xs">
{{ staff_member.first_name|first }}{{ staff_member.last_name|first }}
</div>
<div>
<div class="font-bold text-navy" title="{% if staff_member.first_name_ar and staff_member.last_name_ar %}{{ staff_member.first_name_ar }} {{ staff_member.last_name_ar }}{% endif %}">
{{ staff_member.get_full_name }}
</div>
{% if staff_member.license_number %}
<div class="text-xs text-slate">{{ staff_member.license_number }}</div>
{% endif %}
</div>
{% if staff_member.is_head %}
<span class="ml-2 bg-yellow-100 text-yellow-700 text-[10px] px-2 py-0.5 rounded-full font-bold" title="Department Head">
<i data-lucide="crown" class="w-3 h-3 inline"></i>
</span>
{% endif %}
</div>
</td>
<td class="px-5 py-4">
<span class="px-2 py-1 rounded-lg text-xs font-bold bg-light text-navy">
{{ staff_member.get_staff_type_display }}
</span>
</td>
<td class="px-5 py-4 text-slate-800">{{ staff_member.job_title|default:"-" }}</td>
<td class="px-5 py-4">
{% if staff_member.department %}
<span class="px-2 py-1 rounded-lg text-xs font-bold bg-slate-100 text-slate-600">{{ staff_member.department.name }}</span>
{% else %}
<span class="text-slate text-xs">-</span>
{% endif %}
</td>
<td class="px-5 py-4">
{% if staff_member.report_to %}
<a href="{% url 'organizations:staff_detail' staff_member.report_to.id %}" class="text-blue hover:underline text-xs" onclick="event.stopPropagation();">
{{ staff_member.report_to.get_full_name }}
</a>
{% else %}
<span class="text-slate text-xs">-</span>
{% endif %}
</td>
<td class="px-5 py-4" onclick="event.stopPropagation();">
{% if staff_member.user %}
<span class="px-2 py-1 rounded-lg text-xs font-bold bg-green-100 text-green-600 flex items-center gap-1 w-fit">
<i data-lucide="check" class="w-3 h-3"></i> {% trans "Linked" %}
</span>
{% else %}
<span class="px-2 py-1 rounded-lg text-xs font-bold bg-slate-100 text-slate-500">
{% trans "None" %}
</span>
{% endif %}
</td>
<td class="px-5 py-4">
{% if staff_member.status == 'active' %}
<span class="px-2 py-1 rounded-lg text-xs font-bold bg-green-100 text-green-600">{% trans "Active" %}</span>
{% else %}
<span class="px-2 py-1 rounded-lg text-xs font-bold bg-slate-100 text-slate-500">{% trans "Inactive" %}</span>
{% endif %}
</td>
<td class="px-5 py-4" onclick="event.stopPropagation();">
<div class="flex gap-1">
<a href="{% url 'organizations:staff_detail' staff_member.id %}" class="p-1.5 text-navy hover:bg-light rounded-lg transition" title="{% trans 'View' %}">
<i data-lucide="eye" class="w-4 h-4"></i>
</a>
{% if user.is_px_admin or user.is_hospital_admin %}
{% if not staff_member.user and staff_member.email %}
<button type="button" class="p-1.5 text-green-600 hover:bg-green-50 rounded-lg transition" onclick="createUserAccount('{{ staff_member.id }}', '{{ staff_member.get_full_name }}')" title="{% trans 'Create User' %}">
<i data-lucide="user-plus" class="w-4 h-4"></i>
</button>
{% endif %}
{% if staff_member.user %}
<button type="button" class="p-1.5 text-blue hover:bg-blue-50 rounded-lg transition" onclick="sendInvitation('{{ staff_member.id }}', '{{ staff_member.get_full_name }}')" title="{% trans 'Send Invite' %}">
<i data-lucide="mail" class="w-4 h-4"></i>
</button>
{% endif %}
{% endif %}
</div>
</td>
</tr>
{% empty %}
<tr>
<td colspan="8" class="px-5 py-12 text-center">
<i data-lucide="users" class="w-12 h-12 mx-auto mb-3 text-slate-300"></i>
<p class="text-slate font-medium">{% trans "No staff members found" %}</p>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Pagination -->
{% if staff.has_other_pages %}
<div class="bg-slate-50 px-6 py-4 flex items-center justify-between border-t border-slate-100">
<div class="flex items-center gap-4">
<span class="text-xs text-slate font-medium">
{% trans "Showing" %} <span class="font-bold text-navy">{{ staff.start_index }}-{{ staff.end_index }}</span> {% trans "of" %} <span class="font-bold text-navy">{{ staff.paginator.count }}</span> {% trans "entries" %}
</span>
<!-- Page Size Selector -->
<form method="get" class="flex items-center gap-2" id="pageSizeForm">
{% for key, value in request.GET.items %}
{% if key != 'page_size' and key != 'page' %}
<input type="hidden" name="{{ key }}" value="{{ value }}">
{% endif %}
{% endfor %}
<label class="text-xs text-slate">{% trans "Show" %}</label>
<select name="page_size" onchange="document.getElementById('pageSizeForm').submit()" class="px-2 py-1 bg-white border border-slate-200 rounded-lg text-xs focus:outline-none focus:ring-2 focus:ring-navy">
<option value="10" {% if staff.paginator.per_page == 10 %}selected{% endif %}>10</option>
<option value="25" {% if staff.paginator.per_page == 25 %}selected{% endif %}>25</option>
<option value="50" {% if staff.paginator.per_page == 50 %}selected{% endif %}>50</option>
<option value="100" {% if staff.paginator.per_page == 100 %}selected{% endif %}>100</option>
</select>
</form>
</div>
<div class="flex gap-1">
{% if staff.has_previous %}
<a href="?page={{ staff.previous_page_number }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}"
class="w-8 h-8 flex items-center justify-center rounded-lg border border-slate-200 bg-white hover:bg-slate-50 transition">
<i data-lucide="chevron-left" class="w-4 h-4 text-slate"></i>
</a>
{% else %}
<span class="w-8 h-8 flex items-center justify-center rounded-lg border border-slate-200 bg-slate-100 text-slate-300 cursor-not-allowed">
<i data-lucide="chevron-left" class="w-4 h-4"></i>
</span>
{% endif %}
{% for num in staff.paginator.page_range %}
{% if num == staff.number %}
<span class="w-8 h-8 flex items-center justify-center rounded-lg bg-navy text-white text-xs font-bold">{{ num }}</span>
{% elif num > staff.number|add:'-3' and num < staff.number|add:'3' %}
<a href="?page={{ num }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}"
class="w-8 h-8 flex items-center justify-center rounded-lg border border-slate-200 bg-white hover:bg-slate-50 text-xs font-bold text-slate transition">
{{ num }}
</a>
{% elif num == 1 or num == staff.paginator.num_pages %}
<a href="?page={{ num }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}"
class="w-8 h-8 flex items-center justify-center rounded-lg border border-slate-200 bg-white hover:bg-slate-50 text-xs font-bold text-slate transition">
{{ num }}
</a>
{% elif num == staff.number|add:'-3' or num == staff.number|add:'3' %}
<span class="w-8 h-8 flex items-center justify-center text-xs text-slate">...</span>
{% endif %}
{% endfor %}
{% if staff.has_next %}
<a href="?page={{ staff.next_page_number }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}"
class="w-8 h-8 flex items-center justify-center rounded-lg border border-slate-200 bg-white hover:bg-slate-50 transition">
<i data-lucide="chevron-right" class="w-4 h-4 text-slate"></i>
</a>
{% else %}
<span class="w-8 h-8 flex items-center justify-center rounded-lg border border-slate-200 bg-slate-100 text-slate-300 cursor-not-allowed">
<i data-lucide="chevron-right" class="w-4 h-4"></i>
</span>
{% endif %}
</div>
</div>
{% endif %}
</div>
<!-- Create User Modal -->
<div class="hidden fixed inset-0 bg-black/50 flex items-center justify-center z-50" id="createUserModal">
<div class="bg-white rounded-2xl shadow-2xl max-w-md w-full mx-4 overflow-hidden">
<div class="bg-navy text-white px-6 py-4 flex justify-between items-center">
<h5 class="font-bold text-lg">{% trans "Create User Account" %}</h5>
<button type="button" class="text-white hover:bg-blue rounded-full p-1 transition" onclick="closeModal('createUserModal')">
<i data-lucide="x" class="w-5 h-5"></i>
</button>
</div>
<div class="p-6">
<p class="text-slate mb-2">{% trans "Create a user account for" %} <strong class="text-navy" id="createUserName"></strong>?</p>
<p class="text-slate text-sm">{% trans "Credentials will be emailed to the staff member." %}</p>
</div>
<div class="px-6 py-4 bg-slate-50 flex justify-end gap-3">
<button type="button" class="px-4 py-2 border border-slate-200 text-slate rounded-xl font-semibold hover:bg-white transition" onclick="closeModal('createUserModal')">{% trans "Cancel" %}</button>
<button type="button" class="px-4 py-2 bg-navy text-white rounded-xl font-semibold hover:bg-blue transition" onclick="confirmCreateUser()">{% trans "Create" %}</button>
</div>
</div>
</div>
<!-- Send Invitation Modal -->
<div class="hidden fixed inset-0 bg-black/50 flex items-center justify-center z-50" id="sendInvitationModal">
<div class="bg-white rounded-2xl shadow-2xl max-w-md w-full mx-4 overflow-hidden">
<div class="bg-navy text-white px-6 py-4 flex justify-between items-center">
<h5 class="font-bold text-lg">{% trans "Send Invitation" %}</h5>
<button type="button" class="text-white hover:bg-blue rounded-full p-1 transition" onclick="closeModal('sendInvitationModal')">
<i data-lucide="x" class="w-5 h-5"></i>
</button>
</div>
<div class="p-6">
<p class="text-slate mb-2">{% trans "Send invitation email to" %} <strong class="text-navy" id="sendInvitationName"></strong>?</p>
<p class="text-slate text-sm">{% trans "A new password will be generated and emailed." %}</p>
</div>
<div class="px-6 py-4 bg-slate-50 flex justify-end gap-3">
<button type="button" class="px-4 py-2 border border-slate-200 text-slate rounded-xl font-semibold hover:bg-white transition" onclick="closeModal('sendInvitationModal')">{% trans "Cancel" %}</button>
<button type="button" class="px-4 py-2 bg-navy text-white rounded-xl font-semibold hover:bg-blue transition" onclick="confirmSendInvitation()">{% trans "Send" %}</button>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
let currentStaffId = null;
let currentStaffName = null;
function closeModal(modalId) {
document.getElementById(modalId).classList.add('hidden');
}
function showModal(modalId) {
document.getElementById(modalId).classList.remove('hidden');
}
function createUserAccount(staffId, staffName) {
currentStaffId = staffId;
currentStaffName = staffName;
document.getElementById('createUserName').textContent = staffName;
showModal('createUserModal');
}
function confirmCreateUser() {
const btn = event.target;
btn.disabled = true;
btn.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin inline"></i> {% trans "Creating..." %}';
fetch(`/organizations/api/staff/${currentStaffId}/create_user_account/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': getCookie('csrftoken')
},
body: JSON.stringify({})
})
.then(response => response.json())
.then(data => {
closeModal('createUserModal');
if (data.message) alert(data.message);
location.reload();
})
.catch(error => {
alert('Error: ' + error.message);
btn.disabled = false;
btn.innerHTML = '{% trans "Create" %}';
});
}
function sendInvitation(staffId, staffName) {
currentStaffId = staffId;
currentStaffName = staffName;
document.getElementById('sendInvitationName').textContent = staffName;
showModal('sendInvitationModal');
}
function confirmSendInvitation() {
const btn = event.target;
btn.disabled = true;
btn.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin inline"></i> {% trans "Sending..." %}';
fetch(`/organizations/api/staff/${currentStaffId}/send_invitation/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': getCookie('csrftoken')
},
body: JSON.stringify({})
})
.then(response => response.json())
.then(data => {
closeModal('sendInvitationModal');
if (data.message) alert(data.message);
location.reload();
})
.catch(error => {
alert('Error: ' + error.message);
btn.disabled = false;
btn.innerHTML = '{% trans "Send" %}';
});
}
// Re-initialize Lucide icons after modal content changes
document.addEventListener('DOMContentLoaded', function() {
lucide.createIcons();
});
</script>
{% endblock %}