-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.js
160 lines (130 loc) · 5.61 KB
/
project.js
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
function openNav(evt, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
// To save data
// Array to store user objects
const users = [];
// Function to add a user
function addUser() {
// Get form values
const firstName = document.getElementById('firstName').value;
const lastName = document.getElementById('lastName').value;
const name = firstName+ " " + lastName;
const dateOfBirth = document.getElementById('dateOfBirth').value;
const placeOfBirth= document.getElementById('placeOfBirth').value;
const gender = document.getElementById('gender').value;
const department = document.getElementById('department').value;
const status = document.getElementById('status').value;
// Check if fields are filled
if (firstName === '' || lastName === '' || dateOfBirth === '' || placeOfBirth === '' ) {
alert('Please check inputs again, information are required.');
return;
}
// Create a user object with initial attendance set to 'Absent' and date/time as null
const user = {
name:name,
dateOfBirth : dateOfBirth,
placeOfBirth:placeOfBirth,
gender:gender,
department:department,
status:status,
attendance: 'Absent', // Default attendance
date: 'null', // Placeholder for date
time: 'null' // Placeholder for time
};
// Add the user object to the users array
users.push(user);
// Update the user select dropdown
updateUserSelect();
// Clear form fields
document.getElementById('register-staff-form').reset();
// Display the updated list of users in the main table
displayMainUserTable();
}
// Function to update the user select dropdown
function updateUserSelect() {
const userSelect = document.getElementById('userSelect');
userSelect.innerHTML = '<option value="">-- Select a User --</option>'; // Reset options
users.forEach((user, index) => {
const option = document.createElement('option');
option.value = index;
option.textContent = user.name;
userSelect.appendChild(option);
});
}
// Function to show the selected user details and update their status
function showSelectedUser() {
const selectedIndex = document.getElementById('userSelect').value;
if (selectedIndex !== '') {
// Update the selected user's attendance to 'Present' and set date and time
const now = new Date();
users[selectedIndex].attendance = 'Present';
users[selectedIndex].date = now.toLocaleDateString();
users[selectedIndex].time = now.toLocaleTimeString();
// Display the updated list of all users, showing the selected user with 'Present' and others with 'Absent'
displaySelectedUsersTable();
// } else {
// alert('Please select a user first.');
}
}
// Function to display all users in the main table (Name and Email only)
function displayMainUserTable() {
const tableBody = document.querySelector('#infoTable tbody');
tableBody.innerHTML = ''; // Clear existing rows
users.forEach(user => {
const row = document.createElement('tr');
const nameCell = document.createElement('td');
const dateOfBirthCell = document.createElement('td');
const placeOfBirthCell = document.createElement('td');
const genderCell = document.createElement('td');
const departmentCell = document.createElement('td');
const statusCell = document.createElement('td');
nameCell.textContent = user.name;
dateOfBirthCell.textContent = user.dateOfBirth;
placeOfBirthCell.textContent = user.placeOfBirth;
genderCell.textContent = user.gender;
departmentCell.textContent = user.department;
statusCell.textContent = user.status;
row.appendChild(nameCell);
row.appendChild(dateOfBirthCell);
row.appendChild(placeOfBirthCell);
row.appendChild(genderCell);
row.appendChild(departmentCell);
row.appendChild(statusCell);
tableBody.appendChild(row);
});
}
// Function to display all users in the selected user details table
function displaySelectedUsersTable() {
const tableBody = document.querySelector('#attendanceTable tbody');
tableBody.innerHTML = ''; // Clear existing rows
users.forEach(user => {
const row = document.createElement('tr');
const nameCell = document.createElement('td');
const dateOfBirthCell = document.createElement('td');
const attendanceCell = document.createElement('td');
const dateCell = document.createElement('td');
const timeCell = document.createElement('td');
nameCell.textContent = user.name;
dateOfBirthCell.textContent = user.status;
attendanceCell.textContent = user.attendance;
dateCell.textContent = user.date;
timeCell.textContent = user.time;
row.appendChild(nameCell);
row.appendChild(dateOfBirthCell);
row.appendChild(attendanceCell);
row.appendChild(dateCell);
row.appendChild(timeCell);
tableBody.appendChild(row);
});
}