treasure ok

This commit is contained in:
johan 2023-01-08 20:07:10 +01:00
parent 6e384b472b
commit 625c4a8bb3
3 changed files with 49 additions and 11 deletions

View file

@ -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 {

View file

@ -200,7 +200,10 @@
<p id="treasure-popup-title"></p>
<input type="hidden" id="treasure-popup-uid">
<div class="form-group">
<input type="file" id="treasure-popup-image" >
<input class="form-control" type="file" id="treasure-popup-image" >
</div>
<div class="form-group">
<textarea class="form-control" id="treasure-popup-desc" placeholder="Ajouter une description"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary" id="treasure-popup-button">Envoyer</button>

View file

@ -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(`<div class="treasure-image">Image: <a href="${base_url}images/${td[td_uid].image}.html" target="_blank"> Lien</a></div>`)
$elem.find(".treasure-btn-submit").text('Editer la soumission');
$(`<div class="treasure-image">Image: <a href="${base_url}images/${td[td_uid].image}.html" target="_blank"> Lien</a></div>`).insertAfter($elem.find('.treasure-desc'))
$(`<div class="treasure-user-desc">Votre description :${td[td_uid].desc}</div>`).insertAfter($elem.find('.treasure-desc'))
}
refreshListener();
}
else {
console.alert(data.why);
console.error(data.why);
}
}