office-tool / index.html
Monirbd2025's picture
Make a Employee Database Program that can store Name, Father Name, Mother Name, Date of Birth - Initial Deployment
f96bf3b verified
<!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>