-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAdmin-add.html
288 lines (265 loc) · 10.4 KB
/
Admin-add.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200" />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap"
rel="stylesheet">
<title>Masai Connect</title>
<link rel="stylesheet" href="/Project/Admin/add.css">
</head>
<body>
<div id="main">
<div id="left">
<div>
<div>
<img src="/Project/Images/Logo.png" id="logo" alt="Masai Connect">
</div>
<div id="dashboard">
<span class="material-symbols-outlined">
grid_view
</span>
<p>Dashboard</p>
</div>
<div id="search">
<span class="material-symbols-outlined">
person_search
</span>
<p>Search</p>
</div>
<div id="students">
<span class="material-symbols-outlined">
groups
</span>
<p>Students</p>
</div>
<div id="employee">
<span class="material-symbols-outlined">
person
</span>
<p>Employee</p>
</div>
</div>
<div>
<div></div>
<div id="logout">
<span class="material-symbols-outlined">
logout
</span>
<p>Logout</p>
</div>
</div>
</div>
<div id="right">
<div id="r1">
<div>
<span class="material-symbols-outlined" id="slide" class="icon">
keyboard_double_arrow_right
</span>
</div>
<div>
<img src="/Project/Images/dark theme icon/moon.png" alt="" id="darkmode_btn" class="icon">
<img src="/Project/Images/man.png" alt="" id="profile">
</div>
</div>
<hr>
<div id="forms">
<div>
<h3>ADD A MANAGER</h3>
<form action="" id="employeeform">
<input type="text" placeholder="Enter Manager Name" id="name" required>
<input type="email" placeholder="Enter Employee Email ID" id="email" required>
<input type="password" placeholder="Enter Employee Password" id="password" required>
<input type="submit" class="submit" id="employeesubmit">
</form>
<span id="emplyeestatus"></span>
</div>
<div>
<h3>ADD A STUDENT</h3>
<form action="" id="studentform">
<input type="text" placeholder="Enter Student Name" required id="sname">
<input type="email" placeholder="Enter Student Email ID" required id="semail">
<input type="text" placeholder="Enter Student Student Code" required id="sscode">
<input type="password" placeholder="Enter Student Password" required id="spass">
<input type="submit" class="submit" id="studentsubmit">
</form>
<span id="studentstatus"></span>
</div>
</div>
</div>
</div>
</body>
<script>
let visible = true;
let left = document.getElementById("left");
let right = document.getElementById("right");
let status = document.getElementById("status");
document.getElementById("slide").addEventListener("click", function () {
if (visible == true) {
left.style.display = "none";
right.style.width = "100%";
visible = false;
}
else {
left.style.display = "flex";
right.style.width = "80%";
visible = true;
}
})
let name = document.getElementById("name");
let email = document.getElementById("email");
let pass = document.getElementById("password");
let employeesubmitbtn = document.getElementById("employeesubmit");
let estatus = document.getElementById("emplyeestatus");
const url = new URL('https://64b63253df0839c97e151a61.mockapi.io/api/admin/users');
employeesubmitbtn.addEventListener("click", function (e) {
e.preventDefault();
let newemployee = {
"name": name.value,
"email": email.value,
"password": pass.value
};
fetch(url, {
method: 'GET',
headers: { 'content-type': 'application/json' },
}).then(res => {
return res.json();
}).then(data => {
let emailExists = data.some(item => item.email === email.value);
console.log(data.length);
console.log(emailExists);
if (emailExists == true) {
estatus.innerText = "This Email Id is already exist in our System";
estatus.style.color = "red";
} else {
fetch(url, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(newemployee)
}).then(res => {
return res.json();
}).then(data => {
console.log(data);
estatus.innerText = "Manager is added successfully";
estatus.style.color = "green";
}).catch(error => {
console.log(error);
});
}
setTimeout(() => {
estatus.innerHTML = "";
}, 4000)
name.value = "";
email.value = "";
pass.value = "";
}).catch(error => {
console.log(error);
});
});
let sname = document.getElementById("sname");
let seamil = document.getElementById("semail");
let sscode = document.getElementById("sscode");
let spass = document.getElementById("spass");
let sbtn = document.getElementById("studentsubmit");
let sstatus = document.getElementById("studentstatus");
const url1 = new URL('https://64b63253df0839c97e151a61.mockapi.io/Students');
sbtn.addEventListener("click", function (e) {
e.preventDefault();
let newStudent = {
"name": sname.value,
"student_code": sscode.value,
"email": semail.value,
"password": spass.value,
"todo": []
};
fetch(url1, {
method: 'GET',
headers: { 'content-type': 'application/json' },
}).then(res => {
return res.json();
}).then(data => {
let emailExists = data.some(item => item.email === semail.value);
console.log(data.length);
console.log(emailExists);
if (emailExists == true) {
sstatus.innerText = "This Email Id is already exist in our System";
sstatus.style.color = "red";
} else {
fetch(url1, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(newStudent)
}).then(res => {
return res.json();
}).then(data => {
console.log(data);
sstatus.innerText = "Student is added successfully";
sstatus.style.color = "green";
}).catch(error => {
console.log(error);
});
}
setTimeout(() => {
sstatus.innerHTML = "";
}, 4000)
sname.value = "";
semail.value = "";
spass.value = "";
sscode.value = "";
}).catch(error => {
console.log(error);
});
});
document.getElementById("dashboard").addEventListener("click", function () {
window.location.href = "/Admin-admin.html";
})
document.getElementById("search").addEventListener("click", function () {
window.location.href = "/Admin-search.html";
})
document.getElementById("students").addEventListener("click", function () {
window.location.href = "/Admin-student.html";
})
document.getElementById("employee").addEventListener("click", function () {
window.location.href = "/Admin-employee.html";
})
document.getElementById("logout").addEventListener("click",function(){
window.location.href = "/index.html"
})
function enableDarkMode() {
document.body.classList.add("dark-mode");
const darkButton = document.getElementById("darkmode_btn");
const slideBtn = document.getElementById("slide");
darkButton.src = "/Project/Images/dark theme icon/sun.png";
slideBtn.style.color = "white";
}
function disableDarkMode() {
document.body.classList.remove("dark-mode");
const darkButton = document.getElementById("darkmode_btn");
const slideBtn = document.getElementById("slide");
darkButton.src = "/Project/Images/dark theme icon/moon.png";
slideBtn.style.color = "black";
}
function toggleDarkMode() {
if (localStorage.getItem("darkmode")==="true") {
enableDarkMode();
} else {
disableDarkMode();
}
}
document.getElementById("darkmode_btn").addEventListener("click", function(){
if (localStorage.getItem("darkmode")==="false"){
localStorage.setItem("darkmode","true")
enableDarkMode();
} else if (localStorage.getItem("darkmode")==="true"){
localStorage.setItem("darkmode","false")
disableDarkMode();
}
toggleDarkMode();
});
toggleDarkMode();
</script>
</html>