Files
ritzenbergen-frontend/src/assets/bulitipp.js

90 lines
3.0 KiB
JavaScript
Executable File

function ts(user, callback, spieltag) {
$.ajax("punkteRechnen.php", {
method: "GET",
success: callback,
data: { name: user, spieltag: spieltag },
async: true
});
}
$(document).ready(() => {
const table = document.querySelector("#rangliste-sektion table");
var rows = table.querySelectorAll("tr");
rows.forEach((row, i, array) => {
if (i == 0) return;
var user = row
.querySelectorAll("td")[1]
.querySelector(".openBtn").innerHTML;
var callback = (response) => {
row.querySelectorAll("td")[2].innerHTML = response;
document.getElementById("uebersicht-user-" + user).querySelector(".openBtn").innerHTML = response;
sortTable();
table.querySelectorAll("tr").forEach((row, i, array) => {
if (i == 0) return;
row.querySelectorAll("td")[0].innerHTML = i;
});
};
ts(user, callback);
});
function sortTable() {
var switching, i, x, y, shouldSwitch;
switching = true;
/*Make a loop that will continue until
no switching has been done:*/
while (switching) {
//start by saying: no switching is done:
switching = false;
rows = table.rows;
/*Loop through all table rows (except the
first, which contains table headers):*/
for (i = 1; i < rows.length - 1; i++) {
//start by saying there should be no switching:
shouldSwitch = false;
/*Get the two elements you want to compare,
one from current row and one from the next:*/
x = rows[i].getElementsByTagName("TD")[2];
y = rows[i + 1].getElementsByTagName("TD")[2];
//check if the two rows should switch place:
if (parseInt(x.innerHTML) < parseInt(y.innerHTML)) {
//if so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
}
if (shouldSwitch) {
/*If a switch has been marked, make the switch
and mark that a switch has been done:*/
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
switching = true;
}
}
}
});
document.querySelector("#load-table-btn").addEventListener("click",(ev) => {
ev.target.parentElement.style.display="none";
document.querySelector(".buli-table").classList.add("scroll-x");
const table = document.querySelector("#buli-table table");
let tds=[];
var rows = table.querySelectorAll("tr");
rows.forEach((row, i, array) => {
if (i == 0) return;
var spieltag = row.querySelectorAll("td")[0].innerHTML;
if (spieltag == "Summe") spieltag = undefined;
row.querySelectorAll("td").forEach((td, j, array) => {
if (j == 0) return;
var user = rows[0].querySelectorAll("td")[j].innerHTML;
tds.push({"td":td,"user":user,"spieltag":spieltag});
});
});
let callback=(tds,i,limit)=>{
ts(tds[i].user,(response)=>{
tds[i].td.innerHTML=response;
if(i<limit) callback(tds, i+1, limit);
},tds[i].spieltag);
}
callback(tds,0,tds.length-1);
});