-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhtmlExercise1.html
136 lines (127 loc) · 4.96 KB
/
htmlExercise1.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
table, tr, th, td{
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<center>
<div>
<input type="text" name="username" id="username" placeholder="Username">
<input type="password" name="password" id="password" placeholder="Password">
<button onclick="login()">
Log In
</button>
</div>
<br>
<br>
<br>
<div id="tableContainer" style="display: none;">
<table>
<thead>
<tr>
<th>ID</th>
<th>Activity</th>
<th>Day</th>
<th>Image</th>
<th colspan="2" id="actionTh">Action</th>
</tr>
</thead>
<tbody id="tableContent">
</tbody>
</table>
</div>
<div>
<h4 id="output"></h4>
</div>
</center>
</body>
<script>
class Activity{
constructor(nama,hari,image){
this.nama = nama,
this.hari = hari,
this.image = image
}
}
let data = [
new Activity('Lari','Senin','https://static.duniaku.net/2019/06/D9VoZlrVAAAJqp3.jpg'),
new Activity('Estafet','Selasa','https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2F2.bp.blogspot.com%2F-07ECHstGxyk%2FT-dWKhQ-uCI%2FAAAAAAAAB2U%2FciVfMgHKdUo%2Fs1600%2FCat%2Bsleeping%2Bon%2Bguitar.jpg&f=1&nofb=1'),
new Activity('Basket','Rabu','https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2F2.bp.blogspot.com%2F_Cc3gulUhlvs%2FTOsoFb7qtAI%2FAAAAAAAACr0%2FDkQKKvMpbUU%2Fs1600%2Fgambar-binatang.jpg&f=1&nofb=1'),
new Activity('Tinju','Kamis','https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2F4.bp.blogspot.com%2F-mOOAG-Irdxg%2FUMq6P7qvJ3I%2FAAAAAAAAGQg%2F5oY1UfrdnZ8%2Fs1600%2Fgambar%2Bayam%2Bkate%2B%2B9.JPG&f=1&nofb=1'),
]
let logged;
let users = [
{ username: 'lian', password: 'abc', role: 'user' },
{ username: 'bambang', password: '123', role: 'admin' },
]
function login(){
let username = document.getElementById("username").value; //"lian"
let password = document.getElementById("password").value; // "abc"
// for(var i = 0; i<users.length; i++){
// if(username === users[i].username && password === users[i].password){
// return document.getElementById("output").innerHTML = `Login sebagai: ${users[i].username}`;
// }
// }
// return document.getElementById("output").innerHTML = `User tidak ditemukan`;
logged = users.find((val) => {
return val.username === username && val.password === password
});
console.log(logged);
if(logged){
document.getElementById("tableContainer").style.display = "inline";
showList();
return document.getElementById("output").innerHTML = `Login sebagai: ${logged.username} : ${logged.role}`
}else{
document.getElementById("tableContainer").style.display = "none";
return document.getElementById("output").innerHTML = `User tidak ditemukan`
}
}
function showList(){
let newArr;
newArr = data.map((val, index) => {
return(
`
<tr>
<td>${index + 1}</td>
<td>${val.nama}</td>
<td>${val.hari}</td>
<td><img src="${val.image}" alt="image${index}" height="200px" width="400px"></td>
${logged.role === 'admin' ? "<td><button>Edit</button></td><td><button>Delete</button></td>" : "<td></td>"}
</tr>
`
)
});
let addTd = `
<tr>
<td></td>
<td><input type="text" placeholder="Nama aktifitas"></td>
<td>
<select>
<option>Senin</option>
<option>Selasa</option>
<option>Rabu</option>
<option>Kamis</option>
<option>Jumat</option>
<option>Sabtu</option>
<option>Minggu</option>
</select>
</td>
<td><input type="text" placeholder="URL gambar"></td>
<td colspan="2"><button>Add</button></td>
</tr>`
if(logged.role === "admin"){
return document.getElementById("tableContent").innerHTML = newArr.join("") + addTd;
}else{
return document.getElementById("tableContent").innerHTML = newArr.join("");
}
}
</script>
</html>