Spaces:
Sleeping
Sleeping
Download templates/hr.html from alisaleem97/NexLab_System: direct link, hf CLI and curl.
- Browser
- Download file 31.2 kB
-
https://huggingface.co/spaces/alisaleem97/NexLab_System/resolve/main/templates/hr.html
- Command line
-
hf download hf://spaces/alisaleem97/NexLab_System/templates/hr.html
-
curl -L -o hr.html https://huggingface.co/spaces/alisaleem97/NexLab_System/resolve/main/templates/hr.html
31.2 kB
| {% extends "base.html" %} | |
| {% block title %}HR - Employees{% endblock %} | |
| {% block page_title %}HR & Staff{% endblock %} | |
| {% block content %} | |
| <div class="p-6"> | |
| <!-- Header --> | |
| <div class="flex justify-between items-center mb-6"> | |
| <div> | |
| <h2 class="text-2xl font-bold text-slate-800">Employees</h2> | |
| <p class="text-sm text-slate-500">Manage lab staff and their details</p> | |
| </div> | |
| <button onclick="openEmployeeModal()" class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition-colors flex items-center shadow-sm"> | |
| <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path></svg> | |
| Add Employee | |
| </button> | |
| </div> | |
| <!-- Alert Messages --> | |
| {% if message_success %} | |
| <div class="mb-6 p-4 rounded-lg bg-emerald-50 text-emerald-800 border border-emerald-200 flex items-center shadow-sm"> | |
| <svg class="w-5 h-5 mr-3 text-emerald-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg> | |
| {{ message_success }} | |
| </div> | |
| {% endif %} | |
| {% if message_error %} | |
| <div class="mb-6 p-4 rounded-lg bg-red-50 text-red-800 border border-red-200 flex items-center shadow-sm"> | |
| <svg class="w-5 h-5 mr-3 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg> | |
| {{ message_error }} | |
| </div> | |
| {% endif %} | |
| <!-- Employee Cards Grid --> | |
| <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6"> | |
| {% for emp in employees %} | |
| <div class="bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden flex flex-col transition-shadow hover:shadow-md"> | |
| <!-- Card Header --> | |
| <div class="p-6 flex flex-col items-center border-b border-slate-100 bg-slate-50/50"> | |
| <div class="w-24 h-24 rounded-full overflow-hidden mb-4 border-4 border-white shadow-sm bg-slate-200 flex items-center justify-center"> | |
| {% if emp.photo_path %} | |
| <img src="{{ emp.photo_path }}" alt="{{ emp.full_name }}" class="w-full h-full object-cover"> | |
| {% else %} | |
| <span class="text-3xl text-slate-400 font-bold">{{ emp.full_name[0] }}</span> | |
| {% endif %} | |
| </div> | |
| <h3 class="text-xl font-bold text-slate-800 text-center">{{ emp.full_name }}</h3> | |
| <p class="text-sm text-slate-500 font-medium mt-1">{% if emp.username %}@{{ emp.username }}{% else %}Employee{% endif %}</p> | |
| </div> | |
| <!-- Card Body --> | |
| <div class="p-5 flex-1 flex flex-col"> | |
| <div class="space-y-3 text-sm flex-1"> | |
| <div class="flex justify-between items-center py-1 border-b border-slate-50"> | |
| <span class="text-slate-500">Phone</span> | |
| <span class="text-slate-800 font-medium">{{ emp.phone or '-' }}</span> | |
| </div> | |
| <div class="flex justify-between items-center py-1 border-b border-slate-50"> | |
| <span class="text-slate-500">Working Life</span> | |
| <span class="text-slate-800 font-medium"> | |
| <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-semibold bg-indigo-100 text-indigo-800"> | |
| {{ emp.working_life_months }} Months | |
| </span> | |
| </span> | |
| </div> | |
| <div class="flex justify-between items-center py-1 border-b border-slate-50"> | |
| <span class="text-slate-500">Start Date</span> | |
| <span class="text-slate-800 font-medium">{{ emp.start_date.strftime('%d %b, %Y') }}</span> | |
| </div> | |
| </div> | |
| <!-- Actions --> | |
| <div class="mt-6 flex gap-2 justify-center"> | |
| <button onclick='viewEmployee(employeesData[{{ emp.id }}])' class="p-2 text-indigo-600 bg-indigo-50 hover:bg-indigo-100 rounded-lg transition-colors" title="View Details"> | |
| <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"></path></svg> | |
| </button> | |
| <button onclick='openAttachmentsModal({{ emp.id }}, "{{ emp.full_name }}")' class="p-2 text-blue-600 bg-blue-50 hover:bg-blue-100 rounded-lg transition-colors" title="Attachments"> | |
| <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"></path></svg> | |
| </button> | |
| <button onclick='editEmployee(employeesData[{{ emp.id }}])' class="p-2 text-amber-600 bg-amber-50 hover:bg-amber-100 rounded-lg transition-colors" title="Edit"> | |
| <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path></svg> | |
| </button> | |
| <form action="/api/hr/employees/{{ emp.id }}/delete" method="POST" class="inline" onsubmit="return confirm('Are you sure you want to delete {{ emp.full_name }}?');"> | |
| <button type="submit" class="p-2 text-red-600 bg-red-50 hover:bg-red-100 rounded-lg transition-colors" title="Delete"> | |
| <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg> | |
| </button> | |
| </form> | |
| </div> | |
| </div> | |
| </div> | |
| {% else %} | |
| <div class="col-span-full py-12 flex flex-col items-center justify-center text-slate-400 bg-white rounded-2xl border border-slate-200 border-dashed"> | |
| <svg class="w-16 h-16 mb-4 text-slate-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path></svg> | |
| <p class="text-lg font-medium">No employees found.</p> | |
| <button onclick="openEmployeeModal()" class="mt-4 text-indigo-600 font-medium hover:text-indigo-700">Add an employee</button> | |
| </div> | |
| {% endfor %} | |
| </div> | |
| </div> | |
| <!-- Add/Edit Employee Modal --> | |
| <div id="employeeModal" class="fixed inset-0 bg-slate-900/50 backdrop-blur-sm z-50 hidden flex items-center justify-center"> | |
| <div class="bg-white rounded-xl shadow-xl w-full max-w-3xl max-h-[90vh] flex flex-col m-4 animate-[modalSlideIn_0.2s_ease-out]"> | |
| <div class="flex justify-between items-center p-6 border-b border-slate-100"> | |
| <h3 id="employeeModalTitle" class="text-xl font-bold text-slate-800">Add Employee</h3> | |
| <button onclick="closeEmployeeModal()" class="text-slate-400 hover:text-slate-600 transition-colors"> | |
| <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg> | |
| </button> | |
| </div> | |
| <div class="p-6 overflow-y-auto custom-scrollbar"> | |
| <form id="employeeForm" method="POST" action="/api/hr/employees" enctype="multipart/form-data" class="space-y-6"> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-6"> | |
| <!-- Column 1 --> | |
| <div class="space-y-4"> | |
| <div> | |
| <label class="block text-sm font-medium text-slate-700 mb-1">Full Name <span class="text-red-500">*</span></label> | |
| <input type="text" name="full_name" id="full_name" required class="w-full border border-slate-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-slate-700 mb-1">Username</label> | |
| <input type="text" name="username" id="username" class="w-full border border-slate-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"> | |
| </div> | |
| <div class="grid grid-cols-2 gap-4"> | |
| <div> | |
| <label class="block text-sm font-medium text-slate-700 mb-1">Age</label> | |
| <input type="number" name="age" id="age" min="16" max="100" class="w-full border border-slate-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-slate-700 mb-1">Phone</label> | |
| <input type="text" name="phone" id="phone" class="w-full border border-slate-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"> | |
| </div> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-slate-700 mb-1">Address</label> | |
| <input type="text" name="address" id="address" class="w-full border border-slate-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-slate-700 mb-1">Photo Profile</label> | |
| <input type="file" name="photo" id="photo" accept="image/*" class="w-full border border-slate-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 text-sm file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-indigo-50 file:text-indigo-700 hover:file:bg-indigo-100"> | |
| <p class="text-xs text-slate-500 mt-1">Upload a square image for best results.</p> | |
| </div> | |
| </div> | |
| <!-- Column 2 --> | |
| <div class="space-y-4"> | |
| <div> | |
| <label class="block text-sm font-medium text-slate-700 mb-1">Start Date <span class="text-red-500">*</span></label> | |
| <input type="date" name="start_date" id="start_date" required class="w-full border border-slate-300 rounded-lg px-4 py-2 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-slate-700 mb-1">Salary</label> | |
| <div class="relative"> | |
| <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none"> | |
| <span class="text-slate-500">$</span> | |
| </div> | |
| <input type="number" step="0.01" name="salary" id="salary" class="w-full border border-slate-300 rounded-lg pl-8 pr-4 py-2 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"> | |
| </div> | |
| </div> | |
| <div class="bg-slate-50 p-4 rounded-lg border border-slate-200 mt-6"> | |
| <h4 class="text-sm font-bold text-slate-800 mb-3 flex items-center"> | |
| <svg class="w-4 h-4 mr-1 text-slate-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg> | |
| Working Time | |
| </h4> | |
| <div class="mb-3"> | |
| <label class="block text-sm font-medium text-slate-700 mb-1">Working Days</label> | |
| <input type="text" name="working_days" id="working_days" placeholder="e.g. Mon, Tue, Wed, Thu, Fri" class="w-full border border-slate-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"> | |
| </div> | |
| <div class="grid grid-cols-2 gap-4"> | |
| <div> | |
| <label class="block text-sm font-medium text-slate-700 mb-1">From</label> | |
| <input type="time" name="working_hours_start" id="working_hours_start" class="w-full border border-slate-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"> | |
| </div> | |
| <div> | |
| <label class="block text-sm font-medium text-slate-700 mb-1">To</label> | |
| <input type="time" name="working_hours_end" id="working_hours_end" class="w-full border border-slate-300 rounded-lg px-4 py-2 text-sm focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="pt-4 border-t border-slate-100 flex justify-end gap-3 mt-8"> | |
| <button type="button" onclick="closeEmployeeModal()" class="px-5 py-2 border border-slate-300 text-slate-700 rounded-lg hover:bg-slate-50 font-medium transition-colors">Cancel</button> | |
| <button type="submit" id="saveBtn" class="px-5 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 font-medium shadow-sm transition-colors">Save Employee</button> | |
| </div> | |
| </form> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- View Employee Modal (Full Details) --> | |
| <div id="viewModal" class="fixed inset-0 bg-slate-900/50 backdrop-blur-sm z-50 hidden flex items-center justify-center"> | |
| <div class="bg-white rounded-xl shadow-xl w-full max-w-2xl max-h-[90vh] flex flex-col m-4 animate-[modalSlideIn_0.2s_ease-out]"> | |
| <div class="flex justify-between items-center p-6 border-b border-slate-100"> | |
| <h3 class="text-xl font-bold text-slate-800">Employee Details</h3> | |
| <button onclick="closeViewModal()" class="text-slate-400 hover:text-slate-600 transition-colors"> | |
| <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg> | |
| </button> | |
| </div> | |
| <div class="p-0 overflow-y-auto custom-scrollbar flex-1"> | |
| <div class="bg-slate-50 p-8 flex flex-col items-center border-b border-slate-200"> | |
| <div class="w-28 h-28 rounded-full overflow-hidden mb-4 border-4 border-white shadow-md bg-slate-200 flex items-center justify-center" id="view_photo_container"> | |
| <!-- injected dynamically --> | |
| </div> | |
| <h2 id="view_name" class="text-2xl font-bold text-slate-800"></h2> | |
| <p id="view_username" class="text-indigo-600 font-medium"></p> | |
| </div> | |
| <div class="p-6"> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-6"> | |
| <div> | |
| <p class="text-sm text-slate-500 mb-1">Age</p> | |
| <p class="font-medium text-slate-800" id="view_age"></p> | |
| </div> | |
| <div> | |
| <p class="text-sm text-slate-500 mb-1">Phone</p> | |
| <p class="font-medium text-slate-800" id="view_phone"></p> | |
| </div> | |
| <div class="md:col-span-2"> | |
| <p class="text-sm text-slate-500 mb-1">Address</p> | |
| <p class="font-medium text-slate-800" id="view_address"></p> | |
| </div> | |
| <hr class="md:col-span-2 border-slate-100"> | |
| <div> | |
| <p class="text-sm text-slate-500 mb-1">Start Date</p> | |
| <p class="font-medium text-slate-800" id="view_start_date"></p> | |
| </div> | |
| <div> | |
| <p class="text-sm text-slate-500 mb-1">Working Life</p> | |
| <p class="font-bold text-indigo-600 bg-indigo-50 px-2 py-1 rounded inline-block" id="view_working_life"></p> | |
| </div> | |
| <div> | |
| <p class="text-sm text-slate-500 mb-1">Working Days</p> | |
| <p class="font-medium text-slate-800" id="view_working_days"></p> | |
| </div> | |
| <div> | |
| <p class="text-sm text-slate-500 mb-1">Working Hours</p> | |
| <p class="font-medium text-slate-800" id="view_working_hours"></p> | |
| </div> | |
| <div class="md:col-span-2"> | |
| <p class="text-sm text-slate-500 mb-1">Salary</p> | |
| <p class="font-bold text-emerald-600 text-lg" id="view_salary"></p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="p-6 border-t border-slate-100 flex justify-end"> | |
| <button onclick="closeViewModal()" class="px-6 py-2 bg-slate-800 text-white rounded-lg hover:bg-slate-900 font-medium transition-colors">Close</button> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Attachments Modal --> | |
| <div id="attachmentsModal" class="fixed inset-0 bg-slate-900/50 backdrop-blur-sm z-50 hidden flex items-center justify-center"> | |
| <div class="bg-white rounded-xl shadow-xl w-full max-w-2xl max-h-[90vh] flex flex-col m-4 animate-[modalSlideIn_0.2s_ease-out]"> | |
| <div class="flex justify-between items-center p-6 border-b border-slate-100"> | |
| <h3 class="text-xl font-bold text-slate-800" id="attachmentsModalTitle">Employee Attachments</h3> | |
| <button onclick="closeAttachmentsModal()" class="text-slate-400 hover:text-slate-600 transition-colors"> | |
| <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg> | |
| </button> | |
| </div> | |
| <div class="p-6 overflow-y-auto custom-scrollbar flex-1 bg-slate-50"> | |
| <!-- Upload area --> | |
| <div class="bg-white p-5 rounded-lg border border-slate-200 shadow-sm mb-6"> | |
| <h4 class="text-sm font-bold text-slate-800 mb-3">Upload New Attachment</h4> | |
| <div class="flex items-end gap-3"> | |
| <div class="flex-1"> | |
| <input type="file" id="attachmentFile" class="w-full border border-slate-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 file:mr-4 file:py-1 file:px-3 file:rounded file:border-0 file:text-sm file:font-semibold file:bg-indigo-50 file:text-indigo-700 hover:file:bg-indigo-100"> | |
| </div> | |
| <button onclick="uploadAttachment()" id="uploadBtn" class="bg-indigo-600 hover:bg-indigo-700 text-white px-5 py-2 rounded-lg text-sm font-medium transition-colors shadow-sm flex items-center"> | |
| <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"></path></svg> | |
| Upload | |
| </button> | |
| </div> | |
| </div> | |
| <!-- List --> | |
| <h4 class="text-sm font-bold text-slate-800 mb-3">Saved Attachments</h4> | |
| <div id="attachmentsList" class="space-y-3"> | |
| <!-- Injected via JS --> | |
| <div class="text-center text-slate-500 py-4 text-sm">Loading...</div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| const employeesData = {{ employees_json | tojson | safe }}; | |
| let currentEmployeeId = null; | |
| function openEmployeeModal() { | |
| document.getElementById('employeeModalTitle').textContent = 'Add Employee'; | |
| document.getElementById('employeeForm').action = '/api/hr/employees'; | |
| document.getElementById('employeeForm').reset(); | |
| document.getElementById('saveBtn').textContent = 'Save Employee'; | |
| document.getElementById('employeeModal').classList.remove('hidden'); | |
| } | |
| function editEmployee(emp) { | |
| document.getElementById('employeeModalTitle').textContent = 'Edit Employee'; | |
| document.getElementById('employeeForm').action = `/api/hr/employees/${emp.id}/update`; | |
| document.getElementById('saveBtn').textContent = 'Update Employee'; | |
| document.getElementById('full_name').value = emp.full_name || ''; | |
| document.getElementById('username').value = emp.username || ''; | |
| document.getElementById('age').value = emp.age || ''; | |
| document.getElementById('phone').value = emp.phone || ''; | |
| document.getElementById('address').value = emp.address || ''; | |
| if (emp.start_date) { | |
| document.getElementById('start_date').value = emp.start_date.split('T')[0]; | |
| } | |
| document.getElementById('salary').value = emp.salary || ''; | |
| document.getElementById('working_days').value = emp.working_days || ''; | |
| document.getElementById('working_hours_start').value = emp.working_hours_start || ''; | |
| document.getElementById('working_hours_end').value = emp.working_hours_end || ''; | |
| document.getElementById('employeeModal').classList.remove('hidden'); | |
| } | |
| function closeEmployeeModal() { | |
| document.getElementById('employeeModal').classList.add('hidden'); | |
| } | |
| function viewEmployee(emp) { | |
| document.getElementById('view_name').textContent = emp.full_name; | |
| document.getElementById('view_username').textContent = emp.username ? `@${emp.username}` : ''; | |
| const photoContainer = document.getElementById('view_photo_container'); | |
| if (emp.photo_path) { | |
| photoContainer.innerHTML = `<img src="${emp.photo_path}" class="w-full h-full object-cover">`; | |
| } else { | |
| photoContainer.innerHTML = `<span class="text-4xl text-slate-400 font-bold">${emp.full_name[0]}</span>`; | |
| } | |
| document.getElementById('view_age').textContent = emp.age ? `${emp.age} years` : '-'; | |
| document.getElementById('view_phone').textContent = emp.phone || '-'; | |
| document.getElementById('view_address').textContent = emp.address || '-'; | |
| if (emp.start_date) { | |
| const sd = new Date(emp.start_date); | |
| document.getElementById('view_start_date').textContent = sd.toLocaleDateString('en-GB', {day: 'numeric', month: 'short', year: 'numeric'}); | |
| } else { | |
| document.getElementById('view_start_date').textContent = '-'; | |
| } | |
| document.getElementById('view_working_life').textContent = `${emp.working_life_months || 0} Months`; | |
| document.getElementById('view_working_days').textContent = emp.working_days || '-'; | |
| let hrs = '-'; | |
| if (emp.working_hours_start && emp.working_hours_end) { | |
| hrs = `${emp.working_hours_start} to ${emp.working_hours_end}`; | |
| } else if (emp.working_hours_start) { | |
| hrs = `From ${emp.working_hours_start}`; | |
| } | |
| document.getElementById('view_working_hours').textContent = hrs; | |
| document.getElementById('view_salary').textContent = emp.salary ? `$${emp.salary.toLocaleString()}` : '-'; | |
| document.getElementById('viewModal').classList.remove('hidden'); | |
| } | |
| function closeViewModal() { | |
| document.getElementById('viewModal').classList.add('hidden'); | |
| } | |
| // --- ATTACHMENTS --- | |
| function openAttachmentsModal(employeeId, employeeName) { | |
| currentEmployeeId = employeeId; | |
| document.getElementById('attachmentsModalTitle').textContent = `Attachments: ${employeeName}`; | |
| document.getElementById('attachmentsModal').classList.remove('hidden'); | |
| document.getElementById('attachmentFile').value = ''; | |
| fetchAttachments(); | |
| } | |
| function closeAttachmentsModal() { | |
| document.getElementById('attachmentsModal').classList.add('hidden'); | |
| currentEmployeeId = null; | |
| } | |
| async function fetchAttachments() { | |
| if (!currentEmployeeId) return; | |
| const listEl = document.getElementById('attachmentsList'); | |
| listEl.innerHTML = '<div class="text-center text-slate-500 py-4 text-sm">Loading...</div>'; | |
| try { | |
| const res = await fetch(`/api/hr/employees/${currentEmployeeId}/attachments`); | |
| const data = await res.json(); | |
| if (!data.attachments || data.attachments.length === 0) { | |
| listEl.innerHTML = ` | |
| <div class="bg-white p-6 rounded-lg border border-slate-200 border-dashed text-center text-slate-500 text-sm"> | |
| No attachments found for this employee. | |
| </div>`; | |
| return; | |
| } | |
| let html = ''; | |
| data.attachments.forEach(att => { | |
| const date = new Date(att.uploaded_at).toLocaleDateString('en-GB', {day: 'numeric', month: 'short', year: 'numeric'}); | |
| html += ` | |
| <div class="bg-white p-4 rounded-lg border border-slate-200 flex justify-between items-center hover:shadow-sm transition-shadow"> | |
| <div class="flex items-center"> | |
| <div class="bg-indigo-100 text-indigo-600 p-2 rounded-lg mr-4"> | |
| <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"></path></svg> | |
| </div> | |
| <div> | |
| <p class="font-medium text-slate-800 text-sm truncate max-w-xs" title="${att.file_name}">${att.file_name}</p> | |
| <p class="text-xs text-slate-500 mt-0.5">Uploaded on ${date}</p> | |
| </div> | |
| </div> | |
| <div class="flex gap-2"> | |
| <a href="${att.file_path}" target="_blank" class="p-2 text-indigo-600 bg-indigo-50 hover:bg-indigo-100 rounded-md transition-colors" title="View/Download"> | |
| <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"></path></svg> | |
| </a> | |
| <button onclick="deleteAttachment(${att.id})" class="p-2 text-red-600 bg-red-50 hover:bg-red-100 rounded-md transition-colors" title="Delete"> | |
| <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg> | |
| </button> | |
| </div> | |
| </div>`; | |
| }); | |
| listEl.innerHTML = html; | |
| } catch (e) { | |
| listEl.innerHTML = `<div class="text-red-500 text-sm text-center py-4">Failed to load attachments.</div>`; | |
| } | |
| } | |
| async function uploadAttachment() { | |
| const fileInput = document.getElementById('attachmentFile'); | |
| if (!fileInput.files || fileInput.files.length === 0) { | |
| alert('Please select a file first.'); | |
| return; | |
| } | |
| const formData = new FormData(); | |
| formData.append('file', fileInput.files[0]); | |
| const btn = document.getElementById('uploadBtn'); | |
| const ogText = btn.innerHTML; | |
| btn.innerHTML = 'Uploading...'; | |
| btn.disabled = true; | |
| try { | |
| const res = await fetch(`/api/hr/employees/${currentEmployeeId}/attachments`, { | |
| method: 'POST', | |
| body: formData | |
| }); | |
| const data = await res.json(); | |
| if (data.success) { | |
| fileInput.value = ''; | |
| fetchAttachments(); | |
| } else { | |
| alert('Upload failed: ' + data.error); | |
| } | |
| } catch (e) { | |
| alert('Upload failed.'); | |
| } finally { | |
| btn.innerHTML = ogText; | |
| btn.disabled = false; | |
| } | |
| } | |
| async function deleteAttachment(id) { | |
| if (!confirm('Delete this attachment?')) return; | |
| try { | |
| const res = await fetch(`/api/hr/employees/attachments/${id}`, { method: 'DELETE' }); | |
| const data = await res.json(); | |
| if (data.success) { | |
| fetchAttachments(); | |
| } else { | |
| alert('Delete failed: ' + data.error); | |
| } | |
| } catch (e) { | |
| alert('Delete failed.'); | |
| } | |
| } | |
| </script> | |
| {% endblock %} | |