Spaces:
Running
Running
File size: 19,584 Bytes
f96bf3b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Database</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
/* Custom scrollbar */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: #555;
}
/* Fade-in animation */
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.fade-in {
animation: fadeIn 0.3s ease-in-out;
}
/* Modal styling */
.modal-overlay {
background-color: rgba(0, 0, 0, 0.5);
}
</style>
</head>
<body class="bg-gray-100 min-h-screen">
<div class="container mx-auto px-4 py-8">
<!-- Header -->
<header class="mb-8 text-center">
<h1 class="text-4xl font-bold text-indigo-700 mb-2">Employee Database</h1>
<p class="text-gray-600">Manage your employee records with ease</p>
</header>
<!-- Add Employee Form -->
<div class="bg-white rounded-lg shadow-md p-6 mb-8 fade-in">
<h2 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center">
<i class="fas fa-user-plus mr-2 text-indigo-600"></i> Add New Employee
</h2>
<form id="employeeForm" class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label for="name" class="block text-sm font-medium text-gray-700 mb-1">Full Name</label>
<input type="text" id="name" required
class="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<div>
<label for="fatherName" class="block text-sm font-medium text-gray-700 mb-1">Father's Name</label>
<input type="text" id="fatherName" required
class="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<div>
<label for="motherName" class="block text-sm font-medium text-gray-700 mb-1">Mother's Name</label>
<input type="text" id="motherName" required
class="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<div>
<label for="dob" class="block text-sm font-medium text-gray-700 mb-1">Date of Birth</label>
<input type="date" id="dob" required
class="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<div class="md:col-span-2 flex justify-end">
<button type="submit"
class="px-6 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition flex items-center">
<i class="fas fa-save mr-2"></i> Save Employee
</button>
</div>
</form>
</div>
<!-- Employee List -->
<div class="bg-white rounded-lg shadow-md p-6 fade-in">
<div class="flex flex-col md:flex-row md:items-center justify-between mb-6">
<h2 class="text-2xl font-semibold text-gray-800 mb-2 md:mb-0 flex items-center">
<i class="fas fa-users mr-2 text-indigo-600"></i> Employee Records
</h2>
<div class="relative">
<input type="text" id="searchInput" placeholder="Search employees..."
class="w-full md:w-64 px-4 py-2 pl-10 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
<i class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
</div>
</div>
<!-- Table -->
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
#
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Name
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Father's Name
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Mother's Name
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Date of Birth
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Actions
</th>
</tr>
</thead>
<tbody id="employeeTableBody" class="bg-white divide-y divide-gray-200">
<!-- Employee data will be inserted here by JavaScript -->
<tr id="noEmployeesRow" class="text-center">
<td colspan="6" class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
No employees found. Please add some employees.
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- Edit Modal -->
<div id="editModal" class="fixed inset-0 z-50 hidden overflow-y-auto">
<div class="flex items-center justify-center min-h-screen pt-4 px-4 pb-20 text-center modal-overlay">
<div class="inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full fade-in">
<div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
<h3 class="text-xl font-semibold text-gray-900 mb-4 flex items-center">
<i class="fas fa-user-edit mr-2 text-indigo-600"></i> Edit Employee
</h3>
<form id="editForm" class="space-y-4">
<input type="hidden" id="editId">
<div>
<label for="editName" class="block text-sm font-medium text-gray-700">Full Name</label>
<input type="text" id="editName" required
class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<label for="editFatherName" class="block text-sm font-medium text-gray-700">Father's Name</label>
<input type="text" id="editFatherName" required
class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<label for="editMotherName" class="block text-sm font-medium text-gray-700">Mother's Name</label>
<input type="text" id="editMotherName" required
class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<label for="editDob" class="block text-sm font-medium text-gray-700">Date of Birth</label>
<input type="date" id="editDob" required
class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
</div>
</form>
</div>
<div class="bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
<button type="button" id="saveEditBtn"
class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-indigo-600 text-base font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:ml-3 sm:w-auto sm:text-sm">
Save Changes
</button>
<button type="button" id="cancelEditBtn"
class="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm">
Cancel
</button>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Selectors
const employeeForm = document.getElementById('employeeForm');
const employeeTableBody = document.getElementById('employeeTableBody');
const noEmployeesRow = document.getElementById('noEmployeesRow');
const searchInput = document.getElementById('searchInput');
const editModal = document.getElementById('editModal');
const editForm = document.getElementById('editForm');
const saveEditBtn = document.getElementById('saveEditBtn');
const cancelEditBtn = document.getElementById('cancelEditBtn');
// State
let employees = JSON.parse(localStorage.getItem('employees')) || [];
// Initialize the app
renderEmployees();
// Event Listeners
employeeForm.addEventListener('submit', handleSubmit);
searchInput.addEventListener('input', handleSearch);
saveEditBtn.addEventListener('click', saveEdit);
cancelEditBtn.addEventListener('click', closeModal);
// Functions
function handleSubmit(e) {
e.preventDefault();
const name = document.getElementById('name').value;
const fatherName = document.getElementById('fatherName').value;
const motherName = document.getElementById('motherName').value;
const dob = document.getElementById('dob').value;
const newEmployee = {
id: Date.now(),
name,
fatherName,
motherName,
dob
};
employees.push(newEmployee);
saveToLocalStorage();
renderEmployees();
employeeForm.reset();
// Show success toast
showToast('Employee added successfully!', 'success');
}
function renderEmployees(filteredEmployees = null) {
const employeesToRender = filteredEmployees || employees;
if (employeesToRender.length === 0) {
noEmployeesRow.style.display = 'table-row';
employeeTableBody.innerHTML = '';
employeeTableBody.appendChild(noEmployeesRow);
return;
}
noEmployeesRow.style.display = 'none';
employeeTableBody.innerHTML = '';
employeesToRender.forEach((employee, index) => {
const row = document.createElement('tr');
row.className = 'hover:bg-gray-50';
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${index + 1}</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm font-medium text-gray-900">${employee.name}</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm text-gray-500">${employee.fatherName}</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm text-gray-500">${employee.motherName}</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm text-gray-500">${formatDate(employee.dob)}</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<button onclick="editEmployee(${employee.id})" class="text-indigo-600 hover:text-indigo-900 mr-3">
<i class="fas fa-edit"></i>
</button>
<button onclick="deleteEmployee(${employee.id})" class="text-red-600 hover:text-red-900">
<i class="fas fa-trash-alt"></i>
</button>
</td>
`;
employeeTableBody.appendChild(row);
});
}
function formatDate(dateString) {
const options = { year: 'numeric', month: 'long', day: 'numeric' };
return new Date(dateString).toLocaleDateString(undefined, options);
}
function saveToLocalStorage() {
localStorage.setItem('employees', JSON.stringify(employees));
}
function handleSearch(e) {
const searchTerm = e.target.value.toLowerCase();
if (searchTerm.trim() === '') {
renderEmployees();
return;
}
const filteredEmployees = employees.filter(employee =>
employee.name.toLowerCase().includes(searchTerm) ||
employee.fatherName.toLowerCase().includes(searchTerm) ||
employee.motherName.toLowerCase().includes(searchTerm)
);
renderEmployees(filteredEmployees);
}
window.deleteEmployee = function(id) {
if (confirm('Are you sure you want to delete this employee?')) {
employees = employees.filter(employee => employee.id !== id);
saveToLocalStorage();
renderEmployees();
// Show success toast
showToast('Employee deleted successfully!', 'success');
}
}
window.editEmployee = function(id) {
const employee = employees.find(emp => emp.id === id);
if (!employee) return;
document.getElementById('editId').value = employee.id;
document.getElementById('editName').value = employee.name;
document.getElementById('editFatherName').value = employee.fatherName;
document.getElementById('editMotherName').value = employee.motherName;
document.getElementById('editDob').value = employee.dob;
editModal.classList.remove('hidden');
}
function saveEdit() {
const id = parseInt(document.getElementById('editId').value);
const name = document.getElementById('editName').value;
const fatherName = document.getElementById('editFatherName').value;
const motherName = document.getElementById('editMotherName').value;
const dob = document.getElementById('editDob').value;
employees = employees.map(employee => {
if (employee.id === id) {
return { id, name, fatherName, motherName, dob };
}
return employee;
});
saveToLocalStorage();
renderEmployees();
closeModal();
// Show success toast
showToast('Employee updated successfully!', 'success');
}
function closeModal() {
editModal.classList.add('hidden');
}
function showToast(message, type) {
const toast = document.createElement('div');
toast.className = `fixed top-4 right-4 px-4 py-2 rounded-md shadow-lg text-white ${
type === 'success' ? 'bg-green-500' : 'bg-red-500'
} flex items-center`;
toast.innerHTML = `
<i class="fas ${type === 'success' ? 'fa-check-circle' : 'fa-exclamation-circle'} mr-2"></i>
${message}
`;
document.body.appendChild(toast);
setTimeout(() => {
toast.classList.add('opacity-0', 'transition-opacity', 'duration-300');
setTimeout(() => {
toast.remove();
}, 300);
}, 3000);
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Monirbd2025/office-tool" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |