-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.js
More file actions
37 lines (28 loc) · 1.18 KB
/
Copy pathadmin.js
File metadata and controls
37 lines (28 loc) · 1.18 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
document.addEventListener('DOMContentLoaded', _ => {
let referrer = document.referrer;
let loginPage = window.location.origin + '/login.html';
if (!getCookie('canEnter')) {
window.location.replace('./login.html?error=login');
} else {
// lets make a little bit difficult to make more funny
fetch('./products.json').then(data => data.json()).then((json) => {
let tbody = document.getElementById('table-products');
tbody.innerHTML = '';
let numberOfRows = randomNumber(4, 10);
let items = json.items;
items = shuffleArray(items);
for (let row = 0; row < numberOfRows; row++) {
tbody.innerHTML += `<tr>
<td>${items.shift().capitalize()}</td>
<td>${randomNumber(2, 50)}</td>
</tr>`;
}
}).catch(_ => {
alert('Aplicação não conseguiu se conectar ou encontrar o arquivo de produtos. Tente novamente mais tarde.');
});
}
document.querySelector('.btn-logout').addEventListener('click', _ => {
deleteCookie('canEnter');
window.location.href = 'login.html';
});
});