-
Notifications
You must be signed in to change notification settings - Fork 0
/
favorit.html
124 lines (106 loc) · 4.35 KB
/
favorit.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Football</title>
<meta name="description" content="My first PWA" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="/css/materialize.min.css" />
<link rel="manifest" href="/manifest.json" />
<meta name="theme-color" content="#0000FF" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>
</head>
<body>
<!-- Navigasi -->
<nav class="teal lighten-1" role="navigation">
<div class="nav-wrapper container">
<a href="#" class="brand-logo" id="logo-container">Football News</a>
<a href="index.html" class="sidenav-trigger" data-target="nav-mobile">
<i class="material-icons">arrow_back</i>
</a>
<ul class="topnav right hide-on-med-and-down"></ul>
<ul class="sidenav" id="nav-mobile"></ul>
</div>
</nav>
<!-- Akhir Navigasi -->
<h4>Favorit Team</h4>
<div class="row">
<div class="container" id="body-content"></div>
</div>
<script
type="text/javascript"
src="https://unpkg.com/snarkdown@1.0.2/dist/snarkdown.umd.js"
></script>
<script src="/js/materialize.min.js"></script>
<script src="/js/api.js"></script>
<script src="/js/idb.js"></script>
<script src="/js/db.js"></script>
<script>
var dbPromise = idb.open("Football News", 1, function(upgradeDb) {
var articlesObjectStore = upgradeDb.createObjectStore("team", {
keyPath: "id"
});
articlesObjectStore.createIndex("team", "team", { unique: false });
});
document.addEventListener("DOMContentLoaded", function () {
getAllTeam();
});
function getAllTeam() {
dbPromise.then(function (db) {
var tx = db.transaction('team', 'readonly');
var store = tx.objectStore('team');
return store.getAll();
}).then(function (teams) {
console.log('Data berhasil fetch : ', teams);
var favoritHTML = "";
teams.forEach(function (data) {
favoritHTML += `
<div class="card">
<table class="highlight centered">
<thead>
<tr>
<div class="center"><img width="100" height="100" src="${data.crestUrl}"></div>
<h4 class="center">${data.name}</h4>
</tr>
</thead>
<tbody>
<tr>
<h6 class="center">Address : ${data.address}</h6 class="center">
<h6 class="center">Phone : ${data.phone}</h6 class="center">
<h6 class="center">Email : ${data.email}</h6 class="center">
<h6 class="center">Website : ${data.website}</h6 class="center">
<h6 class="center">Founded : ${data.founded}</h6 class="center">
<td><a class="waves-effect waves-light btn-small blue" onclick="hapusTeam((${data.id}))"><i class="material-icons left">delete</i>Hapus</a></td>
</tr>
</tbody>
</table>
`
});
document.getElementById('body-content').innerHTML = favoritHTML;
}).catch(function () {
});
}
function hapusTeam(id) {
dbPromise.then(function (db) {
if ('PushManager' in window) {
navigator.serviceWorker.getRegistration()
.then(function (reg) {
reg.showNotification(`Team Favorit telah dihapus`);
});
}
var tx = db.transaction('team', 'readwrite');
var store = tx.objectStore('team');
store.delete(id);
return tx.complete;
}).then(function () {
M.toast({html: 'Berhasil menghapus Team'})
window.location.href = "index.html";
console.log('Team telah dihapus');
}).catch(function (error) {
alert('gagal menghapus tim :(');
console.log(error);
});
}
</script>
</body>
</html>