This commit is contained in:
johan 2023-01-10 11:51:10 +01:00
parent 5f95e0a4cd
commit a79a8d77ba

View file

@ -721,51 +721,53 @@ $('#treasure-popup-button').click((e) => {
fr.readAsDataURL(f);
});
$('#demande-button').click(function () {
amount = $('#demande-amount').val();
if (amount > 9) {
t = new TypeIt('#error-message-demande', {
speed: 100,
lifeLike: true
})
.type("Trop de crêpes, maximum c'est 9")
.go();
return;
}
$.ajax({
type: "POST",
url: base_url + "addPrank",
data: JSON.stringify({
uid: localStorage.getItem('user'),
token: localStorage.getItem('token'),
type: "crêpe",
amount: amount,
where: $('#demande-where').val(),
supplement: $('#demande-supp').val(),
note: $('#demande-notes').val(),
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
if(data.success) {
$('#demande-form input').val("");
alert("C'est envoyé, gros gourmand ^^")
updateDemandes();
} else {
$('#error-message-demande').empty();
t = new TypeIt('#error-message-demande', {
speed: 100,
lifeLike: true
})
.type(data.why)
.go();
if(data.why.startsWith('Token expired') || data.why.startsWith('Not authen'))
show_page("#login-page");
}
function refreshCrepe() {
$('#demande-button').click(function () {
amount = $('#demande-amount').val();
if (amount > 9) {
t = new TypeIt('#error-message-demande', {
speed: 100,
lifeLike: true
})
.type("Trop de crêpes, maximum c'est 9")
.go();
return;
}
$.ajax({
type: "POST",
url: base_url + "addPrank",
data: JSON.stringify({
uid: localStorage.getItem('user'),
token: localStorage.getItem('token'),
type: "crêpe",
amount: amount,
where: $('#demande-where').val(),
supplement: $('#demande-supp').val(),
note: $('#demande-notes').val(),
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
if(data.success) {
$('#demande-form input').val("");
alert("C'est envoyé, gros gourmand ^^")
updateDemandes();
} else {
$('#error-message-demande').empty();
t = new TypeIt('#error-message-demande', {
speed: 100,
lifeLike: true
})
.type(data.why)
.go();
if(data.why.startsWith('Token expired') || data.why.startsWith('Not authen'))
show_page("#login-page");
}
}
});
});
});
}
var saved_form = $('#demande-form').html();
@ -791,6 +793,7 @@ function updateDemandes() {
if(data.success) {
if(data.state == "open") {
$('#demande-form').html(saved_form);
refreshCrepe();
} else {
$('#demande-form').html('<h2>Les commandes sont fermés pour le moment mais on revient vite !</h2>');
}
@ -1007,6 +1010,7 @@ $(window).on("load", function() {
}
updateNextActivity();
refreshCrepe();
/* load timer */
window.setInterval(function() {