54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
function list_tasks() {
|
|
fetch(`${config.apiBase}/admin/task/list/${document.getElementById("neptun").value}`,
|
|
{
|
|
method: "GET",
|
|
credentials: "same-origin",
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.status !== 200) {
|
|
alert(data.error);
|
|
console.log(data);
|
|
} else {
|
|
let sum = 0;
|
|
|
|
let table = document.getElementById("list");
|
|
table.innerHTML = "";
|
|
|
|
data.tasks.forEach(task => {
|
|
let row = table.insertRow();
|
|
row.insertCell().innerText = task.description;
|
|
row.insertCell().innerText = task.issuer;
|
|
row.insertCell().innerText = task.points;
|
|
row.insertCell().innerHTML = `<input type="button" value="Remove" onclick="remove(${task.id})">`;
|
|
sum += task.points;
|
|
});
|
|
|
|
document.getElementById("sum").innerText = sum;
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.log(error);
|
|
});
|
|
}
|
|
|
|
function remove(id) {
|
|
fetch(`${config.apiBase}/admin/task/remove/${id}`,
|
|
{
|
|
method: "POST",
|
|
credentials: "same-origin",
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.status !== 200) {
|
|
alert(data.error);
|
|
console.log(data);
|
|
} else {
|
|
alert("removed");
|
|
list_tasks();
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.log(error);
|
|
});
|
|
} |