2022-06-10 00:56:06 +02:00
|
|
|
// document.getElementById("tournamentSubmit").addEventListener("click", function () {
|
|
|
|
// var xhttp = new XMLHttpRequest();
|
|
|
|
// xhttp.onreadystatechange = function () {
|
|
|
|
// if (this.readyState == 4 && this.status == 200) {
|
|
|
|
// alert("Dodano turniej");
|
|
|
|
// } else if (this.readyState == 4) {
|
|
|
|
// alert("something not work :( " + this.status);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// xhttp.open("PUT", "dragonmaster.pl/inz/tournament");
|
|
|
|
// xhttp.setRequestHeader("Authorization", "Bearer " + token);
|
|
|
|
// xhttp.send('{"name":"' + document.getElementById("tournamentName").value +
|
|
|
|
// '","typeOfLadder":"' + document.getElementById("ladderType").value +
|
|
|
|
// '","pointsForTournament":"' + document.getElementById("tournamentPoints").value +
|
|
|
|
// '","places":"' + document.getElementById("tournamentPlace").value +
|
|
|
|
// '","roles":"' + document.getElementById("tournamentRole").value +
|
|
|
|
// '","ranked":"' + document.getElementById("isRanked").value +
|
|
|
|
// '","place":"' + document.getElementById("tournamentPlace").value +
|
|
|
|
// '","from":"' + document.getElementById("tournamentFrom").value +
|
|
|
|
// '","to":"' + document.getElementById("tournamentTo").value +
|
|
|
|
// '","rang":"' + document.getElementById("tournamentRang").value +
|
|
|
|
// '","entyFee":"' + document.getElementById("tournamentEntyFee").value +
|
|
|
|
// '","director":"' + document.getElementById("tournamentDirector").value +
|
|
|
|
// '","phone":"' + document.getElementById("directorphone").value +
|
|
|
|
// '","entriesTo":"' + document.getElementById("tournamentEntriesTo").value +
|
|
|
|
// '","additionalInformations":"' + document.getElementById("tournamentAddInfo").value +
|
|
|
|
// '","category":"' + "cat1" +
|
|
|
|
// '","}');
|
|
|
|
// });
|
2022-06-19 09:34:23 +02:00
|
|
|
function checkCheckBox() {
|
|
|
|
let checkBox = document.getElementById("checkBox");
|
|
|
|
|
|
|
|
if (checkBox.checked == true) {
|
|
|
|
return ("TRUE")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ("FALSE")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkRankingBox() {
|
|
|
|
let checkBox = document.getElementById("checkBoxRanking");
|
|
|
|
|
|
|
|
if (checkBox.checked == true) {
|
|
|
|
return ("1")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ("0")
|
|
|
|
}
|
|
|
|
}
|
2022-06-10 00:56:06 +02:00
|
|
|
|
|
|
|
function createTournament() {
|
2022-06-19 09:34:23 +02:00
|
|
|
let rankingChecker = checkRankingBox();
|
|
|
|
console.log(rankingChecker)
|
|
|
|
let checker = checkCheckBox();
|
|
|
|
console.log(checker)
|
2022-06-10 00:56:06 +02:00
|
|
|
fetch('https://dragonmaster.pl/inz/tournament', {
|
2022-06-18 14:35:43 +02:00
|
|
|
method: "POST",
|
2022-06-10 00:56:06 +02:00
|
|
|
headers: {
|
|
|
|
'Content-type': 'application/json',
|
|
|
|
Authorization: ("Bearer " + localStorage.getItem("token"))
|
|
|
|
},
|
|
|
|
body: JSON.stringify(
|
|
|
|
{
|
2022-06-18 14:35:43 +02:00
|
|
|
"id": localStorage.getItem('tournamentId'),
|
2022-06-10 00:56:06 +02:00
|
|
|
"name": document.getElementById("name").value,
|
2022-06-10 12:23:44 +02:00
|
|
|
"typeOfLadder": "string",
|
|
|
|
"pointsForTournament": "1",
|
2022-06-19 13:14:20 +02:00
|
|
|
"place": document.getElementById("place").value,
|
2022-06-10 00:56:06 +02:00
|
|
|
"roles": document.getElementById("category").value,
|
2022-06-18 14:35:43 +02:00
|
|
|
"from": document.getElementById("term_from").value,
|
|
|
|
"to": document.getElementById("term_to").value,
|
|
|
|
"rang": document.getElementById("rank").value,
|
2022-06-10 00:56:06 +02:00
|
|
|
"entryFee": document.getElementById("entry-fee").value,
|
2022-06-10 12:23:44 +02:00
|
|
|
"director": document.getElementById("director").value,
|
|
|
|
"phone": document.getElementById("phone").value,
|
2022-06-18 14:35:43 +02:00
|
|
|
"entriesTo": document.getElementById("entries").value,
|
2022-06-10 12:23:44 +02:00
|
|
|
"additionalInformations": document.getElementById("add-info").value,
|
2022-06-18 14:35:43 +02:00
|
|
|
"categotry": document.getElementById("category").value,
|
2022-06-19 09:34:23 +02:00
|
|
|
"visibility": checker
|
2022-06-10 00:56:06 +02:00
|
|
|
}
|
|
|
|
)
|
2022-06-01 22:23:12 +02:00
|
|
|
}
|
2022-06-10 00:56:06 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(data => console.log(data))
|
|
|
|
.catch(error => console.log(error))
|
|
|
|
}
|
2022-06-10 12:23:44 +02:00
|
|
|
|
2022-06-18 14:35:43 +02:00
|
|
|
|
2022-06-10 12:23:44 +02:00
|
|
|
function logout() {
|
|
|
|
localStorage.clear();
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
function logoutVisibility() {
|
|
|
|
if (localStorage.getItem("token") !== null) {
|
|
|
|
document.getElementById("logout").style.display = "";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("logout").style.display = "none";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function loginVisibility() {
|
|
|
|
if (localStorage.getItem("token") !== null) {
|
|
|
|
document.getElementById("login").style.display = "none";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById("login").style.display = "";
|
|
|
|
|
|
|
|
}
|
2022-06-10 15:33:05 +02:00
|
|
|
}
|
2022-06-19 13:14:20 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function renderTournaments() {
|
|
|
|
let tournaments = await showTournaments();
|
|
|
|
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}`)
|
|
|
|
document.getElementById("name").placeholder = `${tournament.name}`
|
|
|
|
document.getElementById("term_from").placeholder = `${tournament.from}`
|
|
|
|
document.getElementById("term_to").placeholder = `${tournament.to}`
|
|
|
|
document.getElementById("place").placeholder = `${tournament.place}`
|
|
|
|
document.getElementById("category").placeholder = `${tournament.roles}`
|
|
|
|
document.getElementById("rank").placeholder = `${tournament.rang}`
|
|
|
|
document.getElementById("entry-fee").placeholder = `${tournament.entryFee}`
|
|
|
|
document.getElementById("director").placeholder = `${tournament.director}`
|
|
|
|
document.getElementById("phone").placeholder = `${tournament.phone}`
|
|
|
|
document.getElementById("entries").placeholder = `${tournament.entriesTo}`
|
|
|
|
document.getElementById("add-info").placeholder = `${tournament.additionalInformations}`
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|