admin prank management html and js done

This commit is contained in:
asyncnomi 2023-01-02 21:38:58 +01:00
parent 9bd674db95
commit e8cca14021

View file

@ -40,7 +40,7 @@ $("#login-button").click(function (e) {
localStorage.setItem("isAdmin", data.isAdmin);
show_page('#demande-page');
} else {
alert(data.why);
}
}
@ -114,9 +114,9 @@ function get_admin(type) {
<div class="prank-date">UID: ${prankData[entry].date}</div>
</span>
<span class="prank-btn">
<div class="prank-btn-accept">${(prankData[entry].state == "pending") ? "Accepter" : "Récupérer (accepté par: "+prankData[entry].manageBy+")"}</div>
<div class="prank-btn-accept" style="display: ${(prankData[entry].state == "accepted" && prankData[entry].manageBy == localStorage.getItem("user")) ? "none" : "flex"};">${(prankData[entry].state == "pending") ? "Accepter" : "Récupérer (accepté par: "+prankData[entry].manageBy+")"}</div>
<div class="prank-btn-refused">Refuser</div>
<div class="prank-btn-done" style="display: ${(prankData[entry].state == "accepted" && (prankData[entry].manageBy) == localStorage.getItem("user") ? "flex" : "none"};">Done</div>
<div class="prank-btn-done" style="display: ${(prankData[entry].state == "accepted" && prankData[entry].manageBy == localStorage.getItem("user")) ? "flex" : "none"};">Done</div>
</span>
</span>
`)
@ -125,10 +125,15 @@ function get_admin(type) {
}
break;
case: "kidnap":
// On garde ou pas ?
// Not Handle
break;
}
}
$("#admin-content").insertAdjacentHTML("beforeend", `
<span class="prank">
<div id=prankDone>Nombre totale de mission achevées: ${doneCnt}</div>
</span>
`);
break;
case: "treasure":
break;
@ -138,11 +143,82 @@ function get_admin(type) {
} else {
alert(data.why);
}
}
});
}
$(".prank-btn-accept").click((e) => {
let uid = e.target.parentNode.parentNode.id
$.ajax({
type: "POST",
url: base_url + "acceptPrank",
data: JSON.stringify({
uid: localStorage.getItem('user'),
token: localStorage.getItem('token'),
prankUid: uid,
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if(data.success) {
let btnElems = $("#"+uid).children()[6];
btnElems.children()[0].style.display = "none";
btnElems.children()[2].style.display = "flex";
} else {
alert(data.why);
}
}
});
})
$(".prank-btn-refused").click((e) => {
let uid = e.target.parentNode.parentNode.id
$.ajax({
type: "POST",
url: base_url + "refusePrank",
data: JSON.stringify({
uid: localStorage.getItem('user'),
token: localStorage.getItem('token'),
prankUid: uid,
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if(data.success) {
let btnElems = $("#"+uid).remove();
} else {
alert(data.why);
}
}
});
})
$(".prank-btn-done").click((e) => {
let uid = e.target.parentNode.parentNode.id
$.ajax({
type: "POST",
url: base_url + "donePrank",
data: JSON.stringify({
uid: localStorage.getItem('user'),
token: localStorage.getItem('token'),
prankUid: uid,
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if(data.success) {
let btnElems = $("#"+uid).remove();
$("#prankDone").innerHTML = parseInt($("#prankDone").innerHTML) + 1;
} else {
alert(data.why);
}
}
});
})
$(window).on("load", function() {
/* Register the Service Worker */