+ Demande de vérification par ${treasureData[entry].creator}
+ Activité: ${treasureData[entry].activity.title}
+ Description: ${treasureData[entry].desc}
+
+
+
+ Accepter
+ Refuser
+
+
+ `)
+ }
+ }
break;
case: "activity":
+ $("#admin-content").insertAdjacentHTML("beforeend", `
+
+ Trésor:
+ Description:
+ Lieu:
+ Début:
+ Status: ${activityData[entry].treasureState}
+
+
+ Update
+ Supprimer
+
+
+ `)
+ }
+ }
break;
}
+ refreshListener();
} else {
alert(data.why);
}
@@ -147,77 +234,210 @@ function get_admin(type) {
});
}
-$(".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",
+function refreshListener() {
+ $(".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);
+ 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",
+ $(".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);
+ success: function (data) {
+ if(data.success) {
+ $("#"+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",
+ $(".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);
+ success: function (data) {
+ if(data.success) {
+ $("#"+uid).remove();
+ $("#prankDone").innerHTML = parseInt($("#prankDone").innerHTML) + 1;
+ } else {
+ alert(data.why);
+ }
}
+ });
+ })
+
+ $(".treasure-btn-accept").click((e) => {
+ let uid = e.target.parentNode.parentNode.id
+ $.ajax({
+ type: "POST",
+ url: base_url + "acceptTreasure",
+ data: JSON.stringify({
+ uid: localStorage.getItem('user'),
+ token: localStorage.getItem('token'),
+ treasureUid: uid,
+ }),
+ contentType: "application/json; charset=utf-8",
+ dataType: "json",
+
+ success: function (data) {
+ if(data.success) {
+ $("#"+uid).remove();
+ } else {
+ alert(data.why);
+ }
+ }
+ });
+ })
+
+ $(".treasure-btn-refused").click((e) => {
+ let uid = e.target.parentNode.parentNode.id
+ $.ajax({
+ type: "POST",
+ url: base_url + "refuseTreasure",
+ data: JSON.stringify({
+ uid: localStorage.getItem('user'),
+ token: localStorage.getItem('token'),
+ treasureUid: uid,
+ }),
+ contentType: "application/json; charset=utf-8",
+ dataType: "json",
+
+ success: function (data) {
+ if(data.success) {
+ $("#"+uid).remove();
+ } else {
+ alert(data.why);
+ }
+ }
+ });
+ })
+ $(".activity-btn-update").click((e) => {
+ let uid = e.target.parentNode.parentNode.id;
+ let children = e.target.parentNode.parentNode.children();
+ $.ajax({
+ type: "POST",
+ url: base_url + "refuseTreasure",
+ data: JSON.stringify({
+ uid: localStorage.getItem('user'),
+ token: localStorage.getItem('token'),
+ activityUid: uid,
+ type: (children[0].innerHTML.substring(0, 5) == "Event") ? "event" : "treasure",
+ title: children[0].children()[0].value,
+ desc: children[1].children()[0].value,
+ where: children[2].children()[0].value,
+ start: new Date(children[3].children()[0].value).toString(),
+ end: (children[3].children().length == 0) ? null : new Date(children[4].children()[0].value).toString(),
+ }),
+ contentType: "application/json; charset=utf-8",
+ dataType: "json",
+
+ success: function (data) {
+ if(data.success) {
+ alert("Update réussie")
+ } else {
+ alert(data.why);
+ }
+ }
+ });
+ })
+ $(".activity-btn-delete").click((e) => {
+ let uid = e.target.parentNode.parentNode.id
+ $.ajax({
+ type: "POST",
+ url: base_url + "delActivity",
+ data: JSON.stringify({
+ uid: localStorage.getItem('user'),
+ token: localStorage.getItem('token'),
+ activityUid: uid,
+ }),
+ contentType: "application/json; charset=utf-8",
+ dataType: "json",
+
+ success: function (data) {
+ if(data.success) {
+ $("#"+uid).remove();
+ } else {
+ alert(data.why);
+ }
+ }
+ });
+ })
+ $("activityType").on("change", function() {
+ if (this.value == "treasure") {
+ $("#activity-end-add").style.display = "none";
+ } else if (this.value == "event") {
+ $("#activity-end-add").style.display = "flex";
}
- });
-})
+ })
+ $(".activity-btn-add").click((e) => {
+ let children = e.target.parentNode.parentNode.children();
+ $.ajax({
+ type: "POST",
+ url: base_url + "refuseTreasure",
+ data: JSON.stringify({
+ uid: localStorage.getItem('user'),
+ token: localStorage.getItem('token'),
+ type: $("#activityType").val(),
+ title: children[2].children()[0].value,
+ desc: children[3].children()[0].value,
+ where: children[4].children()[0].value,
+ start: new Date(children[5].children()[0].value).toString(),
+ end: ($("#activityType").val() == "treasure") ? null : new Date(children[6].children()[0].value).toString(),
+ }),
+ contentType: "application/json; charset=utf-8",
+ dataType: "json",
+
+ success: function (data) {
+ if(data.success) {
+ get_admin("activity");
+ } else {
+ alert(data.why);
+ }
+ }
+ });
+ })
+}
$(window).on("load", function() {
@@ -255,3 +475,18 @@ $(window).on("load", function() {
}));
}, 1000);
});
+
+function toIsoString(date) {
+ var tzo = -date.getTimezoneOffset(),
+ dif = tzo >= 0 ? '+' : '-',
+ pad = function(num) {
+ return (num < 10 ? '0' : '') + num;
+ };
+
+ return date.getFullYear() +
+ '-' + pad(date.getMonth() + 1) +
+ '-' + pad(date.getDate()) +
+ 'T' + pad(date.getHours()) +
+ ':' + pad(date.getMinutes()) +
+ ':' + pad(date.getSeconds());
+}