From a79a8d77ba656b3d775499820e6ae1766e3d2ec7 Mon Sep 17 00:00:00 2001 From: johan Date: Tue, 10 Jan 2023 11:51:10 +0100 Subject: [PATCH] dsd --- static/js/main.js | 90 +++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 43 deletions(-) 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('

Les commandes sont fermés pour le moment mais on revient vite !

'); } @@ -1007,6 +1010,7 @@ $(window).on("load", function() { } updateNextActivity(); + refreshCrepe(); /* load timer */ window.setInterval(function() {