Padel-Tournaments-System/frontend/panel_organizatora/dodawanie turnieju/app.js

137 lines
5.3 KiB
JavaScript
Raw Permalink Normal View History

// 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")
}
}
function createTournament() {
2022-06-19 09:34:23 +02:00
let rankingChecker = checkRankingBox();
console.log(rankingChecker)
let checker = checkCheckBox();
let name = document.getElementById("name").value
let place = document.getElementById("place").value
let from = document.getElementById("term_from").value
let to = document.getElementById("term_to").value
let rang = document.getElementById("rank").value
let entryFee = document.getElementById("entry-fee").value
let director = document.getElementById("director").value
let phone = document.getElementById("phone").value
let entriesTo = document.getElementById("entries").value
let additionalInformations = document.getElementById("add-info").value
let category = document.getElementById("category").value
2022-06-19 09:34:23 +02:00
console.log(checker)
if (name == null || name == "", place == null || place == "", from == null || from == "", to == null || to == "", rang == null || rang == "", entryFee == null || entryFee == "", director == null || director == "", phone == null || phone == "", entriesTo == null || entriesTo == "", additionalInformations == null || additionalInformations == "", category == null || category == "") {
alert("Nie można utworzyć turnieju! Proszę wypełnić wszystkie pola!")
}
else {
fetch('https://dragonmaster.pl/inz/tournament', {
method: "PUT",
headers: {
'Content-type': 'application/json',
Authorization: ("Bearer " + localStorage.getItem("token"))
},
body: JSON.stringify(
{
"name": name,
"typeOfLadder": "string",
"pointsForTournament": "1",
"places": "12",
"roles": "role",
"ranked": rankingChecker,
"place": place,
"from": from,
"to": to,
"rang": rang,
"entryFee": entryFee,
"director": director,
"phone": phone,
"entriesTo": entriesTo,
"additionalInformations": additionalInformations,
"categotry": category,
"visibility": checker
}
)
}
)
.then(res => res.json())
.then(data => {
console.log(data)
window.location.href = '../../normal_user/index.html'
})
.catch(error => console.log(error))
}
}
function logout() {
localStorage.removeItem('token');
window.location.href = '../../normal_user/index.html'
}
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
}