Commit 1203b7d5 authored by Mat's avatar Mat
Browse files

nettoyage indentations

parent 0de3b2e6
...@@ -76,75 +76,75 @@ ...@@ -76,75 +76,75 @@
AJAX('GET', ownersURL, function(request) AJAX('GET', ownersURL, function(request)
{ {
// Récupère le json et boucle pour créer le tableau // Récupère le json et boucle pour créer le tableau
let json = JSON.parse(request.responseText); let json = JSON.parse(request.responseText);
for (let i = 0; i < json.length; i++) for (let i = 0; i < json.length; i++)
{ {
let tr = document.createElement('tr'); let tr = document.createElement('tr');
let td0 = document.createElement('td'); let td0 = document.createElement('td');
td0.textContent = json[i].id; td0.textContent = json[i].id;
tr.appendChild(td0); tr.appendChild(td0);
let td1 = document.createElement('td'); let td1 = document.createElement('td');
td1.textContent = json[i].lastname; td1.textContent = json[i].lastname;
tr.appendChild(td1); tr.appendChild(td1);
let td2 = document.createElement('td'); let td2 = document.createElement('td');
td2.textContent = json[i].firstname; td2.textContent = json[i].firstname;
tr.appendChild(td2); tr.appendChild(td2);
let td3 = document.createElement('td'); let td3 = document.createElement('td');
td3.textContent = formatStringDate(json[i].created_at); td3.textContent = formatStringDate(json[i].created_at);
tr.appendChild(td3); tr.appendChild(td3);
let td4 = document.createElement('td'); let td4 = document.createElement('td');
// Boutons edit // Boutons edit
let editBtn = document.createElement('button'); let editBtn = document.createElement('button');
editBtn.dataset.ownerId = json[i].id; editBtn.dataset.ownerId = json[i].id;
editBtn.innerHTML = '<i class="fas fa-edit fa-fw"></i> Editer'; editBtn.innerHTML = '<i class="fas fa-edit fa-fw"></i> Editer';
editBtn.classList.add('btn', 'btn-primary'); editBtn.classList.add('btn', 'btn-primary');
editBtn.addEventListener('click', function() editBtn.addEventListener('click', function()
{ {
let ownerId = this.dataset.ownerId; let ownerId = this.dataset.ownerId;
submitURL = Routing.generate('api_owner_update', {'id': ownerId}); submitURL = Routing.generate('api_owner_update', {'id': ownerId});
AJAX('GET', submitURL, function(request)
{
let json = JSON.parse(request.responseText);
form.querySelector('#owner_firstname').value = json.firstname;
form.querySelector('#owner_lastname').value = json.lastname;
form.parentNode.classList.remove('hidden');
});
}); AJAX('GET', submitURL, function(request)
td4. appendChild(editBtn);
// Boutons delete
let deleteBtn = document.createElement('button');
deleteBtn.dataset.ownerId = json[i].id;
deleteBtn.innerHTML = '<i class="fas fa-trash fa-fw"></i> Supprimer';
deleteBtn.classList.add('btn', 'btn-danger');
deleteBtn.addEventListener('click', function()
{ {
let ownerId = this.dataset.ownerId; let json = JSON.parse(request.responseText);
let r = confirm('Are you sure ?'); form.querySelector('#owner_firstname').value = json.firstname;
if (r === true) { form.querySelector('#owner_lastname').value = json.lastname;
form.parentNode.classList.remove('hidden');
});
submitURL = Routing.generate('api_owner_delete_one', {'id': ownerId}); });
td4. appendChild(editBtn);
AJAX('DELETE', submitURL, function() { // Boutons delete
reloadTableOwner(); let deleteBtn = document.createElement('button');
}); deleteBtn.dataset.ownerId = json[i].id;
} deleteBtn.innerHTML = '<i class="fas fa-trash fa-fw"></i> Supprimer';
}); deleteBtn.classList.add('btn', 'btn-danger');
td4. appendChild(deleteBtn); deleteBtn.addEventListener('click', function()
{
let ownerId = this.dataset.ownerId;
let r = confirm('Are you sure ?');
if (r === true) {
submitURL = Routing.generate('api_owner_delete_one', {'id': ownerId});
tr.appendChild(td4); AJAX('DELETE', submitURL, function() {
tbody.appendChild(tr); reloadTableOwner();
} });
}
});
td4. appendChild(deleteBtn);
tr.appendChild(td4);
tbody.appendChild(tr);
}
}); });
} }
...@@ -181,8 +181,8 @@ ...@@ -181,8 +181,8 @@
AJAX('POST', submitURL, function() AJAX('POST', submitURL, function()
{ {
reloadTableOwner(); reloadTableOwner();
form.parentNode.classList.add('hidden'); form.parentNode.classList.add('hidden');
}, },
form ); form );
......
...@@ -60,13 +60,11 @@ function AJAX(type, url, successCallBack, post = null) ...@@ -60,13 +60,11 @@ function AJAX(type, url, successCallBack, post = null)
xhr.send((post === null)? null : new FormData(post)); xhr.send((post === null)? null : new FormData(post));
} }
// else if (this.status === 500) /*
// { // Faut-il gérer les 500 ou d'autres ???
// console.log(this.status + ' ' + this.statusText); //
// } else if (this.status === 500)
{
// if (post !== null) { console.log(this.status + ' ' + this.statusText);
// xhr.send(new FormData(post)); }
// } else { */
// xhr.send(null);
// }
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