76 lines
2.3 KiB
JavaScript
76 lines
2.3 KiB
JavaScript
document.querySelector('.btn-gestion-commandes').addEventListener('click', function(event) {
|
|
event.preventDefault();
|
|
|
|
document.getElementById('container_modal');
|
|
|
|
fetch('/commandes')
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error('Erreur de chargement de la section Promotions');
|
|
}
|
|
return response.text();
|
|
})
|
|
.then(html => {
|
|
// Insérer le HTML dans le conteneur et l'afficher
|
|
container_modal.innerHTML = html;
|
|
container_modal.style.display = 'block';
|
|
})
|
|
.catch(error => {
|
|
console.error('Erreur:', error);
|
|
});
|
|
});
|
|
|
|
function addCommandes (event) {
|
|
document.getElementById('container_modal');
|
|
fetch(`/commandes/new`)
|
|
.then(response => {
|
|
return response.text();
|
|
})
|
|
.then(html => {
|
|
// Insérer le HTML dans le conteneur et l'afficher
|
|
container_modal.innerHTML = html;
|
|
container_modal.style.display = 'block';
|
|
})
|
|
.catch(error => {
|
|
console.error('Erreur:', error);
|
|
});
|
|
}
|
|
|
|
|
|
function updateCommandes (event) {
|
|
document.getElementById('container_modal');
|
|
const commandesIdString = event.getAttribute('data-id');
|
|
let commandesId = parseInt(commandesIdString);
|
|
|
|
fetch(`/commandes/${commandesId}/edit`)
|
|
.then(response => {
|
|
return response.text();
|
|
})
|
|
.then(html => {
|
|
// Insérer le HTML dans le conteneur et l'afficher
|
|
container_modal.innerHTML = html;
|
|
container_modal.style.display = 'block';
|
|
})
|
|
.catch(error => {
|
|
console.error('Erreur:', error);
|
|
});
|
|
}
|
|
|
|
function deleteCommandes (event) {
|
|
document.getElementById('container_modal');
|
|
const commandesIdString = event.getAttribute('data-id');
|
|
let commandesId = parseInt(commandesIdString);
|
|
|
|
fetch(`/commandes/${commandesId}`)
|
|
.then(response => {
|
|
return response.text();
|
|
})
|
|
.then(html => {
|
|
// Insérer le HTML dans le conteneur et l'afficher
|
|
container_modal.innerHTML = html;
|
|
container_modal.style.display = 'block';
|
|
})
|
|
.catch(error => {
|
|
console.error('Erreur:', error);
|
|
});
|
|
} |