Commit 539f8b6a authored by Mat's avatar Mat

améliorations du javascript, suggérée par phpstorm (warnings)

parent d490a569
......@@ -29,4 +29,6 @@ security:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
\ No newline at end of file
- { path: ^/admin/, role: ROLE_ADMIN }
## TODO Comment je sécurise l'APIBundle ?
......@@ -14,11 +14,11 @@
<span id="t_rows">{{ nbRows }}</span> légumes
<span id="t_pages"></span>
{#
TODO nbRows doit être rafraichis si on crée ou si on efface
TODO nbRows doit être rafraichit si on crée ou si on efface
#}
</div>
<form id="pagination">
<select class="custom-select custom-select-sm">
<select class="custom-select custom-select-sm" title="Pagination">
<option value="-1" selected>Pagination</option>
<option value="5">5</option>
<option value="10">10</option>
......@@ -91,11 +91,15 @@
<script type="text/javascript">
let submitURL = null;
let table = document.querySelector('table#maintab.legumes');
let tbody = table.querySelector('tbody');
let total = parseInt(document.querySelector('#t_rows').textContent);
let tpage = document.querySelector('#t_pages');
let titleForm = document.querySelector('#form-legume');
let paginate = { 'step': 10, 'page': 1, 'column': 'id', 'order': 'ASC' };
/*
......@@ -106,8 +110,8 @@
//console.log(paginate);
tbody.innerHTML = null;
let membreURL = Routing.generate('api_legume_read', paginate);
AJAX('GET', membreURL, function(request)
let legumeURL = Routing.generate('api_legume_read', paginate);
AJAX('GET', legumeURL, function(request)
{
let json = JSON.parse(request.responseText);
//console.log(json);
......@@ -166,7 +170,7 @@
editBtn.innerHTML = '<i class="fas fa-edit fa-fw"></i> Editer';
editBtn.classList.add('btn', 'btn-dark', 'btn-sm', 'mr-1');
editBtn.dataset.legumeId = json[i].id;
editBtn.addEventListener('click', function(e)
editBtn.addEventListener('click', function()
{
let legumeId = this.dataset.legumeId;
submitURL = Routing.generate('api_legume_update', {'id': legumeId});
......@@ -178,7 +182,7 @@
form.querySelector('#legume_nom').value = json.nom;
let legumeFruit = form.querySelector('#legume_fruit');
for(let i, j = 0; i = legumeFruit.options[j]; j++) {
if(i.value == json.fruit) {
if(i.value === json.fruit) {
legumeFruit.selectedIndex = j;
break;
}
......@@ -205,7 +209,7 @@
copyBtn.innerHTML = '<i class="fas fa-clone fa-fw"></i>';
copyBtn.classList.add('btn', 'btn-secondary', 'btn-sm', 'mr-1');
copyBtn.dataset.legumeId = json[i].id;
copyBtn.addEventListener('click', function(e)
copyBtn.addEventListener('click', function()
{
let legumeId = this.dataset.legumeId;
let r = confirm('Dupliquer la rangée n°' + legumeId
......@@ -228,7 +232,7 @@
deleteBtn.innerHTML = '<i class="fas fa-trash fa-fw"></i>';
deleteBtn.classList.add('btn', 'btn-danger', 'btn-sm', 'mr-1');
deleteBtn.dataset.legumeId = json[i].id;
deleteBtn.addEventListener('click', function(e)
deleteBtn.addEventListener('click', function()
{
let legumeId = this.dataset.legumeId;
let r = confirm('Effacer le légume n°' + legumeId
......@@ -250,11 +254,10 @@
* Pagenav, pagination par page
*/
let pageNav = document.querySelector('nav#pagenav ul.pagination');
AJAX('GET', Routing.generate('api_legume_read', paginate), function(request)
AJAX('GET', Routing.generate('api_legume_read', paginate), function()
{
tpage.innerHTML = null;
pageNav.innerHTML = null;
let json = JSON.parse(request.responseText);
let perPage = paginate.step;
if (total > perPage)
{
......@@ -269,7 +272,7 @@
pageItemChild.textContent = i;
if (i !== currentPage)
{
pageItemChild.addEventListener('click', function(e)
pageItemChild.addEventListener('click', function()
{
paginate.page = i;
reloadTableLegume(paginate);
......@@ -294,7 +297,7 @@
*/
let reloadBtns = document.querySelectorAll('.btn-reload');
reloadBtns.forEach(function(reloadBtn) {
reloadBtn.addEventListener('click', function(e)
reloadBtn.addEventListener('click', function()
{
reloadTableLegume(paginate);
});
......@@ -305,7 +308,7 @@
*/
let hideBtns = document.querySelectorAll('.btn-hide');
hideBtns.forEach(function(hideBtn) {
hideBtn.addEventListener('click', function(e)
hideBtn.addEventListener('click', function()
{
form.parentNode.classList.add('hidden');
});
......@@ -316,7 +319,7 @@
*/
let createBtns = document.querySelectorAll('.btn-create');
createBtns.forEach(function(createBtn) {
createBtn.addEventListener('click', function(e)
createBtn.addEventListener('click', function()
{
titleForm.textContent = 'Nouveau légume';
form.querySelector('#legume_nom').value = null;
......@@ -355,9 +358,9 @@
* Définir le pas de la pagination
*/
let stepform = document.querySelector('form#pagination select');
stepform.addEventListener('change', function(e)
stepform.addEventListener('change', function()
{
step = (this.value === '-1') ? 10 : this.value;
let step = (this.value === '-1') ? 10 : this.value;
paginate.step = parseInt(step);
paginate.page = 1;
reloadTableLegume(paginate);
......@@ -370,7 +373,7 @@
columns.forEach(function(column)
{
let col = column.getAttribute('id');
column.addEventListener('click', function(e)
column.addEventListener('click', function()
{
columns.forEach(function(column) {
let oldCaret = column.parentNode.querySelector('i.fas');
......
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