-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAccount.html
327 lines (281 loc) · 10.7 KB
/
Account.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="/Project/Students/Account/Acc.css">
<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>
</head>
<body>
<div id="main">
<div id="left">
<div>
<div>
<img src="/Project/Images/Logo.png" id="logo" alt="Masai Connect">
</div>
<div><span class="material-symbols-outlined">
grid_view
<!-- </span><p><a href="/Project/Students/Dashboard/index.html">Dashboard</a></p></div> -->
</span><p><a href="/Dashboard.html">Dashboard</a></p></div>
<div > <span class="material-symbols-outlined">
person_search
</span><p><a href="/Search.html">Search</a></p></div>
<div><span class="material-symbols-outlined">
groups
</span><p><a href="#" id="must">Groups</a></p></div>
<div ><span class="material-symbols-outlined">
task_alt
</span><p><a href="/Tasks.html">Tasks</a></p></div>
<div ><span class="material-symbols-outlined">
chat
</span><p><a href="/Discussion.html">Discussion</a></p></div>
<div id="task123"><span class="material-symbols-outlined">
account_circle
</span><p><a href="#">Account</a></p></div>
</div>
<div>
<div><span class="material-symbols-outlined">
logout
</span><p><a href="" id="LogoutBtn">Logout</a></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>
<div>
<p>User Account</p>
</div>
<div class="account-setting">
<div class="profile">
<div class="image">
<img src="/Project/Images/man.png" alt="" id="p-image">
</div>
<div class="details">
<div class="details-info">
<label for="">NAME :</label>
<p id="p-name"></p>
</div>
<div class="details-info">
<label for="">EMAIL :</label>
<p id="p-email"></p>
</div>
<!-- <div class="details-info">
<label for="">Mobile :</label>
<p id="p-mobile">9807654321</p>
</div>
<div class="details-info">
<label for="">Student code :</label>
<p id="p-st-code">fw27_***</p>
</div> -->
<div class="details-info">
<button id="edit">EDIT</button>
</div>
</div>
</div>
<div class="update">
<!-- <input type="text" placeholder="ID" id="id"> -->
<p>NAME</p>
<input type="text" placeholder="Name" id="name">
<p>EMAIL</p>
<input type="text" placeholder="Email" id="email">
<p>PASSWORD</p>
<input type="text" placeholder="Password" id="password">
<!-- <input type="text" placeholder="Student code" id="student-code"> -->
<div class="update-buttons">
<button id="update-btn">UPDATE</button>
<button id="cancel">CANCEL</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<script>
let visible = true;
let slidebtn = document.getElementById("slide");
let slide = document.getElementById("left");
slidebtn.addEventListener("click", function () {
if (visible == true) {
slide.style.display = 'none'
visible = false;
right.style.width = '100%';
}
else if (visible == false) {
slide.style.display = 'flex'
visible = true;
right.style.width = '86%';
}
})
// profile-data-------------
let p_name=document.querySelector('#p-name')
let p_email=document.querySelector('#p-email')
let p_mobile=document.querySelector('#p-mobile')
let p_st_code=document.querySelector('#p-st-code')
let p_img=document.querySelector('#p-image')
// update-data----------------------
// let u_id=document.querySelector('#id')
let u_name=document.querySelector('#name')
let u_email=document.querySelector('#email')
let u_password=document.querySelector('#password')
let u_st_code=document.querySelector('#student-code')
let update=document.querySelector('.update')
// ---------------------------------------------
// data fetcing---------------------------------
// https://64b63253df0839c97e151a61.mockapi.io/api/admin/${a}/${id}
// https://64b63253df0839c97e151a61.mockapi.io/api/admin
let a=localStorage.getItem('current')
let id=localStorage.getItem('userid')
let must=document.getElementById("must");
if(a=="Students"){
must.href="/StudentGroup.html";
}else{
must.href="/Manager-Group.html";
}
async function fetchData(){
try{
let api = await fetch(`https://64b63253df0839c97e151a61.mockapi.io/api/admin/${a}/${id}`)
let res = await api.json()
console.log(res)
diplay(res)
}
catch(err){
console.log(err)
}
}
fetchData()
// diplay data----------------------------------
function diplay(data){
p_name.innerText=data.name
p_email.innerText=data.email.split("@").join(" @")
// edit-button-----------------------------
let edit=document.querySelector('#edit')
edit.addEventListener('click',function(){
let pos=-1290
let fun=setInterval(function(){
update.style.display='flex'
if(pos==0){
clearInterval(fun)
}
else{
pos=pos+10
update.style.marginLeft=pos+'px'
}
},0.1)
// u_id.value=data.id
u_name.value=data.name
u_email.value=data.email
u_password.value=data.password
})
// update-button------------------------------------
let update_btn=document.querySelector('#update-btn')
update_btn.addEventListener('click',function(){
// alert(`${u_id.value}${u_name.value}`)
let update_data={
name:u_name.value,
email:u_email.vlaue,
password:u_password.value
}
fetch(`https://64b63253df0839c97e151a61.mockapi.io/api/admin/${a}/${id}`,{
method:'PUT',
headers:{
'Content-type':'application/json'
},
body:JSON.stringify(update_data)
})
.then(res=>{res.json()})
.then(data=>{
console.log(data)
fetchData()
})
.catch(err=>{console.log(err)})
})
// cancel-button------------------------------------
let cancel=document.querySelector('#cancel')
cancel.addEventListener('click',function(){
let ps=0
let fun=setInterval(function(){
update.style.display='flex'
if(ps==-1290){
clearInterval(fun)
update.style.display='none'
u_name.value=''
u_email.value=''
u_password.value=''
update.style.marginRight='0px'
}
else{
ps=ps-10
update.style.marginRight=ps+'px'
}
},0.1)
})
}
// update-option -------------------------------
let LogoutBtn = document.getElementById("LogoutBtn");
LogoutBtn.addEventListener("click", async function (event) {
event.preventDefault();
let status = false;
try {
let res = await fetch(`https://64b63253df0839c97e151a61.mockapi.io/api/admin/${a}/${id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ active: status }),
});
window.location.href = "./index.html";
} catch (error) {
console.log(error);
}
});
// Dark Mode
if (localStorage.getItem("darkmode") === null) {
localStorage.setItem("darkmode", "false");
}
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>