Padel-Tournaments-System/frontend/panel_organizatora/edycja turnieju/app.js
2022-06-19 09:34:23 +02:00

117 lines
4.2 KiB
JavaScript

// 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" +
// '","}');
// });
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")
}
}
function createTournament() {
let rankingChecker = checkRankingBox();
console.log(rankingChecker)
let checker = checkCheckBox();
console.log(checker)
fetch('https://dragonmaster.pl/inz/tournament', {
method: "POST",
headers: {
'Content-type': 'application/json',
Authorization: ("Bearer " + localStorage.getItem("token"))
},
body: JSON.stringify(
{
"id": localStorage.getItem('tournamentId'),
"name": document.getElementById("name").value,
"typeOfLadder": "string",
"pointsForTournament": "1",
"places": document.getElementById("place").value,
"roles": document.getElementById("category").value,
"from": document.getElementById("term_from").value,
"to": document.getElementById("term_to").value,
"rang": document.getElementById("rank").value,
"entryFee": document.getElementById("entry-fee").value,
"director": document.getElementById("director").value,
"phone": document.getElementById("phone").value,
"entriesTo": document.getElementById("entries").value,
"additionalInformations": document.getElementById("add-info").value,
"categotry": document.getElementById("category").value,
"visibility": checker
}
)
}
)
.then(res => res.json())
.then(data => console.log(data))
.catch(error => console.log(error))
}
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 = "";
}
}