let tourId = localStorage.getItem("myElement") async function showTournaments() { let url = 'https://dragonmaster.pl/inz/tournaments'; try { let res = await fetch(url); return await res.json(); } catch (error) { console.log(error); } } function checkId() { if (localStorage.getItem("token") !== null) { fetch('https://dragonmaster.pl/inz/user', { headers: { Authorization: ("Bearer " + localStorage.getItem("token")) } }) .then(res => res.json()) .then(json => { return (json['id']) }) } else { document.getElementById("creator").style.display = "none"; } } function checkOwner() { if (localStorage.getItem("organisatorId") == checkId()) { console.log("dziaua") } } function checkRole() { if (localStorage.getItem("token") !== null) { fetch('https://dragonmaster.pl/inz/user', { headers: { Authorization: ("Bearer " + localStorage.getItem("token")) } }) .then(res => res.json()) .then(json => { if (json['role'] == '1' || json['role'] == '2') { document.getElementById("zapisy").style.display = "none"; document.getElementById("drabinka").style.display = "none"; } else { document.getElementById("zapisy").style.display = ''; document.getElementById("drabinka").style.display = ''; } }) } else { document.getElementById("zapisy").style.display = "none"; document.getElementById("drabinka").style.display = "none"; } } function logout() { localStorage.removeItem('token'); location.reload(); } function logoutVisibility() { if (localStorage.getItem("token") !== null) { document.getElementById("logout").style.display = ""; document.getElementById("saverForTournament").style.display = ""; } else { document.getElementById("logout").style.display = "none"; document.getElementById("saverForTournament").style.display = "none"; } } function loginVisibility() { if (localStorage.getItem("token") !== null) { document.getElementById("login").style.display = "none"; document.getElementById("saverForTournament").style.display = ""; } else { document.getElementById("login").style.display = ""; document.getElementById("saverForTournament").style.display = "none"; } } async function renderTournaments() { let tournaments = await showTournaments(); let html = ''; let htmlDate = ''; tournaments.forEach(tournament => { let rank = 0 if (`${tournament.approved}` == 0) { rank = "Nie" } else if (`${tournament.approved}` == 1) { rank = "Tak, ale niezatwierdzony" } else { rank = "Tak" } if (`${tournament.id}` == localStorage.getItem("tournamentId")) { console.log(`${tournament.rang}`) htmlDate = `

${tournament.name}

Miejsce: ${tournament.place}
${tournament.from} do ${tournament.to}

` let htmlSegment = `

${tournament.name}

Miejsce: ${tournament.place}

Wpisowe:

${tournament.entryFee}

Ranga:

${tournament.rang}

Kategorie:

${tournament.categotry}

Zapisy do:

${tournament.to}

Czy rankingowy:

${rank}

Dyrektor turnieju:

${tournament.director}

Dodatkowe informacje

${tournament.additionalInformations} `; html += htmlSegment; } }); let date = document.querySelector('.tournamentData') date.innerHTML = htmlDate; let container = document.querySelector('.form'); container.innerHTML = html; }