-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
182 lines (159 loc) · 4.42 KB
/
admin.html
File metadata and controls
182 lines (159 loc) · 4.42 KB
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
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<title>User Management</title>
<style>
/* ==============================
General Body Styles
============================== */
body {
direction: rtl; /* Right-to-left text direction */
font-family: shabnam;
background: #f9f9f9;
padding: 40px;
}
h1 {
color: #333;
text-align: center;
}
/* ==============================
Table Styles
============================== */
table {
width: 100%;
border-collapse: collapse;
margin-top: 30px;
}
th, td {
border: 1px solid #ccc;
padding: 10px;
text-align: center;
}
th {
background-color: #eee;
}
/* ==============================
Button Styles
============================== */
.btn {
padding: 6px 12px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
}
.btn-danger {
background-color: #ff4d4d; /* Red delete button */
color: white;
}
.btn-toggle {
background-color: #007bff; /* Blue toggle button */
color: white;
}
/* ==============================
Empty State Message
============================== */
.empty {
text-align: center;
margin-top: 40px;
color: #777;
}
</style>
</head>
<body>
<!-- ==============================
Page Title
============================== -->
<h1>Registered Users List</h1>
<!-- ==============================
Users Table
============================== -->
<table id="userTable">
<thead>
<tr>
<th>Full Name</th>
<th>Phone Number</th>
<th>Email</th>
<th>Password</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- Users will be dynamically loaded here -->
</tbody>
</table>
<!-- ==============================
Empty Users Message
============================== -->
<div class="empty" id="noUsers" style="display:none;">
No users have been registered.
</div>
<!-- ==============================
JavaScript for User Management
============================== -->
<script>
// Load users from localStorage or initialize empty array
let users = JSON.parse(localStorage.getItem("users")) || [];
const tableBody = document.querySelector("#userTable tbody");
const noUsers = document.getElementById("noUsers");
/**
* Render the list of users in the table
*/
function renderUsers() {
tableBody.innerHTML = ""; // Clear table rows
if (users.length === 0) {
// Show empty message if no users
document.getElementById("userTable").style.display = "none";
noUsers.style.display = "block";
return;
}
document.getElementById("userTable").style.display = "table";
noUsers.style.display = "none";
// Loop through users and create table rows
users.forEach((user, index) => {
const row = document.createElement("tr");
row.innerHTML = `
<td>${user.fullName}</td>
<td>${user.phone}</td>
<td>${user.email}</td>
<td>
<span class="password" id="pass-${index}">••••••</span>
<button class="btn btn-toggle" onclick="togglePassword(${index})">Show</button>
</td>
<td>
<button class="btn btn-danger" onclick="deleteUser(${index})">Delete</button>
</td>
`;
tableBody.appendChild(row);
});
}
/**
* Toggle password visibility for a user
* @param {number} index - Index of the user in the array
*/
function togglePassword(index) {
const span = document.getElementById(`pass-${index}`);
const user = users[index];
if (span.innerText === "••••••") {
span.innerText = user.password; // Show password
} else {
span.innerText = "••••••"; // Hide password
}
}
/**
* Delete a user from the list
* @param {number} index - Index of the user to delete
*/
function deleteUser(index) {
if (confirm("Are you sure you want to delete this user?")) {
users.splice(index, 1);
localStorage.setItem("users", JSON.stringify(users));
renderUsers(); // Re-render table
}
}
// Initial render on page load
renderUsers();
</script>
</body>
</html>