feat(select-entries): save the collections of activities

This commit is contained in:
Florian Schmitt 2025-02-07 16:37:51 +03:00
parent df25bfa9ac
commit 32389d740e

View file

@ -138,10 +138,11 @@ document.addEventListener("DOMContentLoaded", function(event) {
}) })
$('.btn-save-selected').on('click', function(e){ $('.btn-save-selected').on('click', function(e){
e.preventDefault() e.preventDefault()
let content = Array() let bf_activite = Array()
$.each( $('.selected'), function( key, value ) { $.each( $('.selected'), function( key, value ) {
content.push(value.getAttribute('data-tag')) bf_activite[value.getAttribute('data-tag')] = value.getAttribute('data-tag')
}); });
bf_activite = Object.assign({}, bf_activite)
const settings = { const settings = {
async: true, async: true,
crossDomain: true, crossDomain: true,
@ -150,11 +151,27 @@ document.addEventListener("DOMContentLoaded", function(event) {
headers: { headers: {
Authorization: 'Bearer ScTSZnBTCw6SWnpThhAAodKh4brbwrnHwxn5jzIsOLxjk4SotxlFbrqnZnEEvVvb' Authorization: 'Bearer ScTSZnBTCw6SWnpThhAAodKh4brbwrnHwxn5jzIsOLxjk4SotxlFbrqnZnEEvVvb'
}, },
data: JSON.stringify({ bf_titre: $('#title').val(), bf_activite: content, id_typeannonce: 21 }), data: JSON.stringify({ bf_titre: $('#title').val(), bf_activite, id_typeannonce: 21 }),
contentType: 'application/json' contentType: 'application/json'
}; };
$.ajax(settings).done(function (response) { $.ajax(settings).done(function (response) {
console.log(response); toastMessage(
"La sélection est créée, allons la voir!",
2000,
'alert alert-success'
)
setTimeout(function() { window.location.href = response.success }, 2000)
}).fail(function (response) {
const regex = /can not be generated from/gm;
if (response.statusText == "error" && regex.exec(response.responseText)) {
toastMessage(
"Veuillez renseigner un titre pour la sélection",
3000,
'alert alert-danger'
)
}
}); });
return false; return false;
}) })