From 625c4a8bb3e99fbe7d4e3b1a20237f22b6f6189c Mon Sep 17 00:00:00 2001 From: johan Date: Sun, 8 Jan 2023 20:07:10 +0100 Subject: [PATCH] treasure ok --- static/css/main.css | 4 ++-- static/index.html | 5 ++++- static/js/main.js | 51 ++++++++++++++++++++++++++++++++++++++------- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/static/css/main.css b/static/css/main.css index 8e47deb..36e97e5 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -265,11 +265,11 @@ button[type="submit"]:hover { } .treasure { - padding: 5px; + padding: 0px 20px; } .treasure-submitted { - color: rgba(254, 181, 35, 0.471) + background-color: rgba(255, 196, 0, 0.395); } .treasure-accepted { diff --git a/static/index.html b/static/index.html index e0b5e42..3630c4a 100644 --- a/static/index.html +++ b/static/index.html @@ -200,7 +200,10 @@

- + +
+
+
diff --git a/static/js/main.js b/static/js/main.js index 8131e9f..2c7be44 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -601,6 +601,10 @@ function refreshListener() { $(".treasure-btn-submit").click((e) => { let uid = e.target.parentNode.parentNode.id; + $('#treasure-popup-uid').val(uid); + $('#treasure-popup-title').text($('#' + uid + ' .treasure-title').text()); + $('#treasure-popup-desc').text($('#' + uid + ' .treasure-user-desc').text()); + $('.overlay').css({"opacity": 1, "visibility": "visible"}); }); } @@ -609,6 +613,37 @@ $('.close').click((e) => { $('.overlay').css({"opacity": 0, "visibility": "hidden"}); }); +$('#treasure-popup-button').click((e) => { + var fr = new FileReader(); + + fr.addEventListener('load', () => { + $.ajax({ + type: "POST", + url: base_url + "sendTreasure", + data: JSON.stringify({ + uid: localStorage.getItem('user'), + token: localStorage.getItem('token'), + image: fr.result, + activityUid: $('#treasure-popup-uid').val(), + desc: $('#treasure-popup-desc').text(), + }), + contentType: "application/json; charset=utf-8", + dataType: "json", + + success: function(data) { + if(data.success) { + updateDemandes(); + $('.overlay').css({"opacity": 0, "visibility": "hidden"}); + } else { + console.error(data.why); + } + } + }); + }); + + fr.readAsDataURL($('#treasure-popup-image').prop('files')[0]); +}); + $('#demande-button').click(function () { $.ajax({ type: "POST", @@ -694,10 +729,10 @@ function updateDemandes() { refreshListener(); } else { - if (data.why == "Not authentificated") { + if (data.why == "Not authentificated" || data.why == "Token expired") { show_page('#login-page'); } else { - console.alert(data.why); + console.error(data.why); } } } @@ -741,7 +776,7 @@ function updateDemandes() { refreshListener(); } else { - console.alert(data.why); + console.error(data.why); } } }); @@ -762,16 +797,16 @@ function updateDemandes() { let td = data.treasureData; for(const td_uid in td) { - $elem = $('#' + td_uid); + $elem = $('#' + td[td_uid].activityUid); $elem.addClass('treasure-submitted'); - $elem.children(".treasure-button-submit").text('Editer la soumission'); - $elem.children('.treasure-desc').insertAfter(`
Image: Lien
`) - + $elem.find(".treasure-btn-submit").text('Editer la soumission'); + $(`
Image: Lien
`).insertAfter($elem.find('.treasure-desc')) + $(`
Votre description :${td[td_uid].desc}
`).insertAfter($elem.find('.treasure-desc')) } refreshListener(); } else { - console.alert(data.why); + console.error(data.why); } }