52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
const btnEnregistrerBailleur = document.getElementById('btnEnregistrerBailleur');
|
|
let table;
|
|
|
|
btnEnregistrerBailleur.addEventListener('click', function() {
|
|
const form = document.getElementById('formBailleur');
|
|
const formData = new FormData(form);
|
|
|
|
fetch(form.action, {
|
|
method: 'POST',
|
|
body: formData,
|
|
headers: {
|
|
'X-CSRFToken': formData.get('csrfmiddlewaretoken')
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
alert('Bailleur enregistré avec succès !');
|
|
window.location.reload();
|
|
} else {
|
|
alert('Ce bailleur existe déjà dans la base de données.');
|
|
}
|
|
});
|
|
});
|
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
|
|
table = new Tabulator("#table-bailleurs", {
|
|
ajaxURL: "/gestion-projet/bailleurs/",
|
|
layout: "fitColumns",
|
|
pagination: "local",
|
|
paginationSize: 5,
|
|
|
|
columns: [
|
|
{title: "#", formatter: "rownum", width: 60},
|
|
{title: "Organisme", field: "nom_organisme"},
|
|
{title: "Contact", field: "contact"},
|
|
{title: "Email", field: "email"},
|
|
{title: "Pays", field: "pays"},
|
|
],
|
|
rowDblClick: function(e, row) {
|
|
const data = row.getData();
|
|
|
|
if (confirm(`Voulez-vous vraiment supprimer ${data.nom_organisme} ?`)) {
|
|
supprimerBailleur(data.id);
|
|
}
|
|
}
|
|
});
|
|
|
|
});
|
|
|