diff --git a/static/js/main.js b/static/js/main.js index 07cade6..34b2717 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -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('