Mar 06 2026: fixed time attendance records page, update search by id 3

This commit is contained in:
2026-03-06 17:59:37 -05:00
parent 67524d5107
commit f4e67726fd
+272 -142
View File
@@ -4,51 +4,154 @@
{% block extra_head %} {% block extra_head %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/time_attendance.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/time_attendance.css') }}">
<style> <style>
/* ── Employee autocomplete for time-attendance records filter ── */ /* ── Autocomplete widget styles (mirrors attendance.css — not loaded on this page) ── */
.ta-autocomplete-container { .autocomplete-container-filter { position: relative; }
position: relative;
.autocomplete-results-filter {
position: fixed;
background: white;
border: 1px solid #ddd;
border-top: none;
border-radius: 0 0 4px 4px;
max-height: 250px;
overflow-y: auto;
z-index: 9999;
display: none;
box-shadow: 0 4px 8px rgba(0,0,0,.15);
margin-top: 0;
} }
.ta-autocomplete-results { .autocomplete-results-filter.show { display: block; }
display: none;
position: fixed; .autocomplete-item-filter {
z-index: 9999; padding: 0.75rem;
background: #fff; cursor: pointer;
border: 1px solid #e2e8f0; border-bottom: 1px solid #f0f0f0;
border-radius: 8px; transition: background-color 0.2s;
box-shadow: 0 4px 16px rgba(0,0,0,.12);
max-height: 240px;
overflow-y: auto;
} }
.ta-autocomplete-results.show { display: block; } .autocomplete-item-filter:last-child { border-bottom: none; }
.ta-autocomplete-item { .autocomplete-item-filter:hover { background-color: #f8f9fa; }
padding: 10px 14px;
cursor: pointer; .employee-info-filter {
border-bottom: 1px solid #f1f5f9; display: flex;
display: flex; justify-content: space-between;
justify-content: space-between; align-items: center;
align-items: center;
gap: 8px;
} }
.ta-autocomplete-item:last-child { border-bottom: none; } .employee-name-filter { font-weight: 600; color: #333; }
.ta-autocomplete-item:hover { background: #f8fafc; } .employee-id-filter { color: #666; font-size: 0.9rem; }
.ta-emp-name { font-weight: 500; color: #0f172a; font-size: .875rem; }
.ta-emp-id { font-size: .75rem; color: #64748b; white-space: nowrap; } .clear-employee-filter {
.ta-clear-btn { position: absolute;
display: none; right: 8px;
position: absolute; top: 50%;
right: 8px; transform: translateY(-50%);
top: 50%; background: #dc3545;
transform: translateY(-50%); color: white;
background: none; border: none;
border: none; border-radius: 50%;
cursor: pointer; width: 24px;
color: #94a3b8; height: 24px;
padding: 2px 6px; cursor: pointer;
font-size: .85rem; display: flex;
line-height: 1; align-items: center;
justify-content: center;
transition: background-color 0.2s;
padding: 0;
}
.clear-employee-filter:hover { background: #c82333; }
.clear-employee-filter i { font-size: 0.75rem; }
.filter-input { padding-right: 35px !important; }
/* ── Mirror attendance.css filter layout on this page ── */
.filters-section { margin-bottom: 2rem; }
.filters-card {
background: #ffffff;
border-radius: 0.75rem;
box-shadow: 0 1px 3px rgba(0,0,0,.1);
overflow: hidden;
}
.filters-header {
padding: 1.25rem 1.5rem;
border-bottom: 1px solid #e2e8f0;
background: #f8fafc;
}
.filters-header h3 {
font-size: 1rem;
font-weight: 600;
color: #0f172a;
margin: 0;
display: flex;
align-items: center;
gap: 0.5rem;
}
.filters-header h3 i { color: #2563eb; }
.filters-form { padding: 1.5rem; }
.filter-row {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 1rem;
align-items: end;
}
.filter-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
min-width: 0;
}
.filter-group label {
font-size: 0.875rem;
font-weight: 600;
color: #374151;
display: flex;
align-items: center;
gap: 0.5rem;
}
.filter-group label i { color: #2563eb; font-size: 0.75rem; }
.filter-group input,
.filter-group select {
padding: 0.625rem 0.875rem;
border: 2px solid #e2e8f0;
border-radius: 0.5rem;
font-size: 0.875rem;
background-color: #ffffff;
transition: border-color 0.2s, box-shadow 0.2s;
width: 100%;
box-sizing: border-box;
}
.filter-group input:focus,
.filter-group select:focus {
outline: none;
border-color: #2563eb;
box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.filter-actions {
grid-column: 1 / -1;
display: flex;
gap: 0.75rem;
justify-content: flex-start;
align-items: end;
margin-top: 0.5rem;
}
@media (max-width: 1200px) {
.filter-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 768px) {
.filter-row { grid-template-columns: 1fr 1fr; }
.filter-actions { grid-column: 1 / -1; }
} }
.ta-autocomplete-container:hover .ta-clear-btn,
.ta-clear-btn:focus { display: block; }
</style> </style>
{% endblock %} {% endblock %}
@@ -92,87 +195,112 @@
</div> </div>
<!-- Filters Section --> <!-- Filters Section -->
<div class="filter-section"> <div class="filters-section">
<div class="filter-header"> <div class="filters-card">
<h3> <div class="filters-header">
<i class="fas fa-filter"></i> <h3>
Filter Records <i class="fas fa-filter"></i>
</h3> Filter Records
</div> </h3>
<div class="filter-body" id="filterBody"> </div>
<form method="GET" action="{{ url_for('time_attendance_records') }}" class="filter-form"> <div class="filters-form">
<div class="form-group"> <form method="GET" action="{{ url_for('time_attendance_records') }}">
<label for="ta_employee_search" class="form-label">Employee</label> <div class="filter-row">
<div class="ta-autocomplete-container">
<input type="text"
id="ta_employee_search"
class="form-input"
placeholder="Search by ID or Name..."
value="{{ employee_display_name }}"
autocomplete="off">
<input type="hidden"
id="employee_id"
name="employee_id"
value="{{ employee_filter }}">
<div id="ta_autocomplete_results" class="ta-autocomplete-results"></div>
{% if employee_filter %}
<button type="button"
class="ta-clear-btn"
onclick="taClearEmployee()"
title="Clear employee filter">
<i class="fas fa-times"></i>
</button>
{% endif %}
</div>
</div>
<div class="form-group"> <div class="filter-group">
<label for="project_id" class="form-label">Project</label> <label for="start_date">
<select id="project_id" name="project_id" class="form-select"> <i class="fas fa-calendar-alt"></i>
<option value="">All Projects</option> Start Date
{% for project in projects %} </label>
<option value="{{ project.id }}" {% if request.args.get('project_id') == project.id|string %}selected{% endif %}> <input type="date"
{{ project.name }} id="start_date"
</option> name="start_date"
{% endfor %} value="{{ request.args.get('start_date', '') }}">
</select> </div>
</div>
<div class="filter-group">
<div class="form-group"> <label for="end_date">
<label for="location_name" class="form-label">Location</label> <i class="fas fa-calendar-alt"></i>
<select id="location_name" name="location_name" class="form-select"> End Date
<option value="">All Locations</option> </label>
{% for location in unique_locations %} <input type="date"
<option value="{{ location[0] }}" {% if request.args.get('location_name') == location[0] %}selected{% endif %}> id="end_date"
{{ location[0] }} name="end_date"
</option> value="{{ request.args.get('end_date', '') }}">
{% endfor %} </div>
</select>
</div> <div class="filter-group">
<label for="project_id">
<div class="form-group"> <i class="fas fa-project-diagram"></i>
<label for="start_date" class="form-label">Start Date</label> Project
<input type="date" id="start_date" name="start_date" class="form-input" </label>
value="{{ request.args.get('start_date', '') }}"> <select id="project_id" name="project_id">
</div> <option value="">All Projects</option>
{% for project in projects %}
<div class="form-group"> <option value="{{ project.id }}" {% if request.args.get('project_id') == project.id|string %}selected{% endif %}>
<label for="end_date" class="form-label">End Date</label> {{ project.name }}
<input type="date" id="end_date" name="end_date" class="form-input" </option>
value="{{ request.args.get('end_date', '') }}"> {% endfor %}
</div> </select>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary"> <div class="filter-group">
<i class="fas fa-search"></i> <label for="location_name">
Apply Filters <i class="fas fa-map-marker-alt"></i>
</button> Location
<a href="{{ url_for('time_attendance_records') }}" class="btn btn-secondary"> </label>
<i class="fas fa-times"></i> <select id="location_name" name="location_name">
Clear <option value="">All Locations</option>
</a> {% for location in unique_locations %}
</div> <option value="{{ location[0] }}" {% if request.args.get('location_name') == location[0] %}selected{% endif %}>
</form> {{ location[0] }}
</option>
{% endfor %}
</select>
</div>
<div class="filter-group">
<label for="ta_employee_search">
<i class="fas fa-user-search"></i>
Employee
</label>
<div class="autocomplete-container-filter">
<input type="text"
id="ta_employee_search"
class="filter-input"
placeholder="Search by ID or Name..."
value="{{ employee_display_name }}"
autocomplete="off">
<input type="hidden"
id="employee_id"
name="employee_id"
value="{{ employee_filter }}">
<div id="ta_autocomplete_results" class="autocomplete-results-filter"></div>
{% if employee_filter %}
<button type="button"
class="clear-employee-filter"
onclick="taClearEmployee()"
title="Clear employee filter">
<i class="fas fa-times"></i>
</button>
{% endif %}
</div>
</div>
<div class="filter-actions">
<button type="submit" class="btn btn-primary">
<i class="fas fa-search"></i>
Apply Filters
</button>
<button type="button" onclick="taClearAllFilters()" class="btn btn-outline">
<i class="fas fa-times"></i>
Clear
</button>
</div>
</div>
</form>
</div>
</div> </div>
</div> </div>
@@ -466,18 +594,13 @@ document.addEventListener('keydown', function(event) {
} }
}); });
// Initialize filters state - Always visible // Filters are always visible — no toggle needed
document.addEventListener('DOMContentLoaded', function() {
const filterBody = document.getElementById('filterBody');
// Always ensure the filter section is visible
filterBody.style.display = 'block';
});
// ── Employee autocomplete ────────────────────────────────────────────────── // ── Employee autocomplete ──────────────────────────────────────────────────
(function () { (function () {
const searchInput = document.getElementById('ta_employee_search'); const searchInput = document.getElementById('ta_employee_search');
const hiddenInput = document.getElementById('employee_id'); const hiddenInput = document.getElementById('employee_id');
const dropdown = document.getElementById('ta_autocomplete_results'); const dropdown = document.getElementById('ta_autocomplete_results');
let debounceTimer; let debounceTimer;
if (!searchInput) return; if (!searchInput) return;
@@ -514,19 +637,18 @@ document.addEventListener('DOMContentLoaded', function() {
}); });
document.addEventListener('click', function (e) { document.addEventListener('click', function (e) {
if (!e.target.closest('.ta-autocomplete-container')) { if (!e.target.closest('.autocomplete-container-filter')) {
dropdown.classList.remove('show'); dropdown.classList.remove('show');
} }
}); });
function renderDropdown(employees) { function renderDropdown(employees) {
// Clear and rebuild — use createElement + addEventListener to avoid // Use createElement + addEventListener — safe with apostrophes in names
// any quoting/escaping issues with names that contain apostrophes.
dropdown.innerHTML = ''; dropdown.innerHTML = '';
if (employees.length === 0) { if (employees.length === 0) {
const noResult = document.createElement('div'); const noResult = document.createElement('div');
noResult.className = 'ta-autocomplete-item'; noResult.className = 'autocomplete-item-filter';
noResult.style.cssText = 'cursor:default;color:#999;'; noResult.style.cssText = 'cursor:default;color:#999;';
noResult.textContent = 'No employees found'; noResult.textContent = 'No employees found';
dropdown.appendChild(noResult); dropdown.appendChild(noResult);
@@ -538,10 +660,13 @@ document.addEventListener('DOMContentLoaded', function() {
: emp.lastName + ', ' + emp.firstName; : emp.lastName + ', ' + emp.firstName;
const item = document.createElement('div'); const item = document.createElement('div');
item.className = 'ta-autocomplete-item'; item.className = 'autocomplete-item-filter';
const info = document.createElement('div');
info.className = 'employee-info-filter';
const nameSpan = document.createElement('span'); const nameSpan = document.createElement('span');
nameSpan.className = 'ta-emp-name'; nameSpan.className = 'employee-name-filter';
if (isUnregistered) { if (isUnregistered) {
nameSpan.textContent = 'ID: ' + emp.id + ' '; nameSpan.textContent = 'ID: ' + emp.id + ' ';
const em = document.createElement('em'); const em = document.createElement('em');
@@ -553,13 +678,14 @@ document.addEventListener('DOMContentLoaded', function() {
} }
const idSpan = document.createElement('span'); const idSpan = document.createElement('span');
idSpan.className = 'ta-emp-id'; idSpan.className = 'employee-id-filter';
idSpan.textContent = 'ID: ' + emp.id; idSpan.textContent = 'ID: ' + emp.id;
item.appendChild(nameSpan); info.appendChild(nameSpan);
item.appendChild(idSpan); info.appendChild(idSpan);
item.appendChild(info);
// Capture values in closure — safe regardless of special characters // Closure captures values safely regardless of special characters
item.addEventListener('click', (function (id, name) { item.addEventListener('click', (function (id, name) {
return function () { taSelectEmployee(id, name); }; return function () { taSelectEmployee(id, name); };
}(String(emp.id), displayName))); }(String(emp.id), displayName)));
@@ -579,8 +705,8 @@ document.addEventListener('DOMContentLoaded', function() {
} }
window.taSelectEmployee = function (id, displayName) { window.taSelectEmployee = function (id, displayName) {
hiddenInput.value = id; hiddenInput.value = id;
searchInput.value = displayName; searchInput.value = displayName;
dropdown.classList.remove('show'); dropdown.classList.remove('show');
}; };
@@ -590,6 +716,10 @@ document.addEventListener('DOMContentLoaded', function() {
searchInput.closest('form').submit(); searchInput.closest('form').submit();
}; };
window.taClearAllFilters = function () {
window.location.href = '{{ url_for("time_attendance_records") }}';
};
window.addEventListener('scroll', function () { window.addEventListener('scroll', function () {
if (dropdown.classList.contains('show')) positionDropdown(); if (dropdown.classList.contains('show')) positionDropdown();
}, true); }, true);