Commit 772e6fa0 authored by Mat's avatar Mat

on va utiliser une variable submitURL commune pour le create et le update du form

parent 64369541
......@@ -53,6 +53,8 @@
{% block customJS %}
<script type="text/javascript">
let submitURL = null;
// L'URL de l'API
let ownersURL = Routing.generate('api_owner_read');
......@@ -103,8 +105,11 @@
editBtn.classList.add('btn', 'btn-primary');
editBtn.addEventListener('click', function() {
let ownerId = this.dataset.ownerId;
console.log(ownerId);
getAJAX(Routing.generate('api_owner_read_one', {'id': ownerId}));
submitURL = Routing.generate('api_owner_update', {'id': ownerId});
getAJAX(submitURL, function()
{
});
});
td4. appendChild(editBtn);
......@@ -133,6 +138,7 @@
createBtns.forEach(function(currentBtn){ // ou for (let currentBtn of createBtns)
currentBtn.addEventListener('click', function(e){ // 'e' veut dire 'event'
form.parentNode.classList.remove('hidden');
submitURL = Routing.generate('api_owner_create');
});
});
......@@ -143,18 +149,18 @@
});
});
form.addEventListener('submit', function(e) {
let createURL = '{{ path('api_owner_create') }}';
// Soumission du formulaire
form.addEventListener('submit', function(e)
{
let form = this;
// Annule l'événement, mais préserve la fonction callback
e.preventDefault();
postAJAX(createURL, function() {
if (this.readyState === 4 && this.status === 200) {
reloadTableOwner();
postAJAX(submitURL, function()
{
}
}, form);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment