Skip to content

Commit f207a46

Browse files
committed
Prefer const over let
1 parent 15b6d5e commit f207a46

23 files changed

+474
-482
lines changed

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default [
88
rules: {
99
'no-var': 'error',
1010
'no-unexpected-multiline': 'off', // Prettier disagrees
11+
'prefer-const': 'error',
1112
},
1213
},
1314
];

htdocs/cahier/cahier.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function loadActualBookings(_actualBookings) {
2121
$('divTabCahierTableActualBookings').previousElementSibling.title =
2222
bookableNbr + ' embarcations, ' + participantNbr + ' personnes';
2323

24-
let children = $('divTabCahierTables').children;
24+
const children = $('divTabCahierTables').children;
2525
for (let j = 0; j < children.length; j++) {
2626
if (
2727
children[j].id != 'divTabCahierTableActualBookings' &&
@@ -52,7 +52,7 @@ function coloring(booking) {
5252
}
5353

5454
function actualizeActualBookings(_actualBookings) {
55-
let all = $('divTabCahierTableActualBookings').getElementsByClassName('TableEntries');
55+
const all = $('divTabCahierTableActualBookings').getElementsByClassName('TableEntries');
5656
for (let i = 0; i < all.length; i++) {
5757
if (all[i].id != 'divTabCahierTableActualBookingsTopBar') {
5858
all[i].parentNode.removeChild(all[i]);
@@ -61,14 +61,14 @@ function actualizeActualBookings(_actualBookings) {
6161
}
6262

6363
if (_actualBookings.length == 0) {
64-
let entry = div($('divTabCahierTableActualBookings'));
64+
const entry = div($('divTabCahierTableActualBookings'));
6565
entry.classList.add('TableEntries');
6666
entry.classList.add('TableEntriesHover');
6767
div(entry);
6868
}
6969

7070
for (let j = 0; j < _actualBookings.length; j++) {
71-
let container = div($('divTabCahierTableActualBookings'));
71+
const container = div($('divTabCahierTableActualBookings'));
7272
container.id = j;
7373
container.classList.add('TableEntries');
7474
container.classList.add('TableEntriesHover');
@@ -96,11 +96,11 @@ function actualizeActualBookings(_actualBookings) {
9696
}
9797
});
9898

99-
let divDate = div(container);
99+
const divDate = div(container);
100100

101-
let maxHours = 24;
101+
const maxHours = 24;
102102
if (Date.now() - new Date(_actualBookings[j].startDate).getTime() > (maxHours / 6) * 60 * 60 * 1000) {
103-
let d = div(divDate);
103+
const d = div(divDate);
104104
d.classList.add('TableEntriesAlert');
105105
d.style.filter = 'grayscale(1) invert(1)';
106106
d.title = '+ de 4 heures';
@@ -123,7 +123,7 @@ function actualizeActualBookings(_actualBookings) {
123123
divDate.id = 'SORTING' + new Date(_actualBookings[j].startDate).toISOString(); // for the sorting
124124
divDate.innerHTML += new Date(_actualBookings[j].startDate).getNiceTime(':', true);
125125

126-
let participantCount = div(container);
126+
const participantCount = div(container);
127127
participantCount.innerHTML = _actualBookings[j].participantCount;
128128
participantCount.title = Cahier.getSingularOrPlural(_actualBookings[j].participantCount);
129129

@@ -132,7 +132,7 @@ function actualizeActualBookings(_actualBookings) {
132132
if (_actualBookings[j].bookables.length == 0) {
133133
createBookingBookableBox(div(container));
134134
} else {
135-
let c = div(container);
135+
const c = div(container);
136136
for (let k = 0; k < _actualBookings[j].bookables.length; k++) {
137137
createBookingBookableBox(c, _actualBookings[j].bookables[k]);
138138
}
@@ -142,9 +142,9 @@ function actualizeActualBookings(_actualBookings) {
142142

143143
div(container).innerHTML = getStartCommentFromBooking(_actualBookings[j]).shorten(200, 16);
144144

145-
let d = div(container);
145+
const d = div(container);
146146
d.title = 'Terminer ou modifier cette sortie';
147-
let btn = div(d);
147+
const btn = div(d);
148148
btn.classList.add('Buttons');
149149
}
150150
sortTable($('divTabCahierTableActualBookings'));
@@ -153,11 +153,11 @@ function actualizeActualBookings(_actualBookings) {
153153
// new search system
154154
export function bookingTableSearch(_table) {
155155
let bookings;
156-
let txts = _table.previousElementSibling.previousElementSibling.value.split(' ');
156+
const txts = _table.previousElementSibling.previousElementSibling.value.split(' ');
157157
// means finishedBookings
158158
if (_table != $('divTabCahierTableActualBookings')) {
159159
let i;
160-
let all = document.getElementsByClassName('BookingsTable');
160+
const all = document.getElementsByClassName('BookingsTable');
161161
for (i = 1; i < all.length; i++) {
162162
if (all[i] == _table) {
163163
break;
@@ -168,7 +168,7 @@ export function bookingTableSearch(_table) {
168168
// means actualBookings
169169
bookings = Cahier.actualBookings;
170170
}
171-
let result = [];
171+
const result = [];
172172

173173
for (let t = 0; t < txts.length; t++) {
174174
result[t] = [];
@@ -208,7 +208,7 @@ export function bookingTableSearch(_table) {
208208
}
209209

210210
// merge but only take the bookings which are in every search result !
211-
let send = result.mergeAND();
211+
const send = result.mergeAND();
212212
if (_table == $('divTabCahierTableActualBookings')) {
213213
actualizeActualBookings(send);
214214
} else {
@@ -217,15 +217,15 @@ export function bookingTableSearch(_table) {
217217
}
218218

219219
function createBookingBookableBox(elem, bookable = {code: 'ZZZ'}) {
220-
let d = div(elem);
220+
const d = div(elem);
221221
if (bookable.code != null) {
222222
d.id = bookable.code;
223223
} else {
224224
d.id = '999';
225225
}
226226

227-
let img = div(d);
228-
let code = div(d);
227+
const img = div(d);
228+
const code = div(d);
229229

230230
if (bookable == Cahier.personalBookable) {
231231
img.style.backgroundImage = 'url(img/icons/own-sail.png)';
@@ -245,7 +245,7 @@ function createBookingBookableBox(elem, bookable = {code: 'ZZZ'}) {
245245

246246
if (bookable.code != null) {
247247
code.innerHTML = bookable.code;
248-
let codeLength = bookable.code.pixelLength(20);
248+
const codeLength = bookable.code.pixelLength(20);
249249
div(d).innerHTML = bookable.name.shorten(170 - codeLength, 18);
250250
} else {
251251
code.innerHTML = '';
@@ -257,8 +257,8 @@ function createBookingBookableBox(elem, bookable = {code: 'ZZZ'}) {
257257

258258
export function loadTableTopBars(allTables = document.getElementsByClassName('BookingsTable')) {
259259
for (let u = 0; u < allTables.length; u++) {
260-
let table = allTables[u];
261-
let top = table.getElementsByClassName('TableTopBar')[0];
260+
const table = allTables[u];
261+
const top = table.getElementsByClassName('TableTopBar')[0];
262262
const all = top.getElementsByTagName('div');
263263

264264
for (let i = 0; i < all.length; i = i + 2) {
@@ -277,7 +277,7 @@ export function loadTableTopBars(allTables = document.getElementsByClassName('Bo
277277
this.getElementsByTagName('div')[0].style.backgroundImage = 'url(img/icons/sort-desc.png)';
278278
}
279279

280-
let allButtons = this.parentElement.getElementsByTagName('div');
280+
const allButtons = this.parentElement.getElementsByTagName('div');
281281
for (let k = 0; k < all.length; k = k + 2) {
282282
if (allButtons[k] != this) {
283283
allButtons[k].classList.remove('BookingsTopBarSorted');
@@ -295,8 +295,8 @@ export function loadTableTopBars(allTables = document.getElementsByClassName('Bo
295295
}
296296

297297
function sortTable(table) {
298-
let field = parseInt(table.getElementsByClassName('BookingsTopBarSorted')[0].id);
299-
let order = function () {
298+
const field = parseInt(table.getElementsByClassName('BookingsTopBarSorted')[0].id);
299+
const order = function () {
300300
if (
301301
table.getElementsByClassName('BookingsTopBarSorted')[0].getElementsByTagName('div')[0].style
302302
.backgroundImage == 'url("img/icons/sort-desc.png")'
@@ -307,7 +307,7 @@ function sortTable(table) {
307307
}
308308
};
309309

310-
let all = table.getElementsByClassName('TableEntries');
310+
const all = table.getElementsByClassName('TableEntries');
311311
let switching = true;
312312
while (switching) {
313313
switching = false;
@@ -343,32 +343,32 @@ export function newBookingTable(date, title = '?') {
343343
}
344344

345345
export function createBookingsTable(date, title) {
346-
let input = document.createElement('input');
346+
const input = document.createElement('input');
347347
input.type = 'text';
348348
input.value = '';
349349
input.spellcheck = false;
350350
input.placeholder = 'Rechercher';
351351
$('divTabCahierTables').appendChild(input);
352352

353-
let t = div($('divTabCahierTables'));
353+
const t = div($('divTabCahierTables'));
354354
t.classList.add('BookingsTableText');
355355
if (title == '?') {
356356
title = date.getNiceDate();
357357
}
358358
t.innerHTML = title;
359359

360-
let table = div($('divTabCahierTables'));
360+
const table = div($('divTabCahierTables'));
361361
input.onkeyup = function () {
362362
bookingTableSearch(table);
363363
};
364364
table.id = date.toISOString();
365365
table.classList.add('BookingsTable');
366366

367-
let topBar = div(table);
367+
const topBar = div(table);
368368
topBar.classList.add('TableEntries');
369369
topBar.classList.add('TableTopBar');
370370

371-
let fields = [
371+
const fields = [
372372
'',
373373
'',
374374
'',
@@ -378,7 +378,7 @@ export function createBookingsTable(date, title) {
378378
'Commentaire de départ',
379379
"Commentaire d'arrivée",
380380
];
381-
let images = [
381+
const images = [
382382
'icons/start',
383383
'icons/end',
384384
'icons/participant-count',
@@ -390,10 +390,10 @@ export function createBookingsTable(date, title) {
390390
];
391391

392392
for (let i = 0; i < fields.length; i++) {
393-
let d = div(topBar);
393+
const d = div(topBar);
394394
d.id = i;
395395
div(d);
396-
let img = document.createElement('img');
396+
const img = document.createElement('img');
397397
img.src = 'img/' + images[i] + '.png';
398398
img.alt = '?';
399399
d.appendChild(img);
@@ -402,7 +402,7 @@ export function createBookingsTable(date, title) {
402402

403403
topBar.getElementsByTagName('div')[0].classList.add('BookingsTopBarSorted');
404404

405-
let b = div(table);
405+
const b = div(table);
406406
b.style.position = 'absolute';
407407
b.style.width = '100%';
408408
b.style.height = '2px';
@@ -415,13 +415,13 @@ export function createBookingsTable(date, title) {
415415
}
416416

417417
export function createNoBookingMessage(date) {
418-
let t = div($('divTabCahierTables'));
418+
const t = div($('divTabCahierTables'));
419419
t.classList.add('BookingsTableTextNoBooking');
420420
t.innerHTML = 'Aucune sortie le ' + date.getNiceDate();
421421
}
422422

423423
export function actualizeFinishedBookingListForDay(bookings, table) {
424-
let all = table.getElementsByClassName('TableEntries');
424+
const all = table.getElementsByClassName('TableEntries');
425425
for (let i = 0; i < all.length; i++) {
426426
if (all[i].classList.contains('TableTopBar') === false) {
427427
all[i].parentNode.removeChild(all[i]);
@@ -438,13 +438,13 @@ export function actualizeFinishedBookingListForDay(bookings, table) {
438438
table.previousElementSibling.title = bookableNbr + ' embarcations, ' + participantNbr + ' personnes';
439439

440440
if (bookings.length === 0) {
441-
let ent = div(table);
441+
const ent = div(table);
442442
ent.classList.add('TableEntries');
443443
ent.classList.add('TableEntriesHover');
444444
div(ent);
445445
} else {
446446
for (let i = 0; i < bookings.length; i++) {
447-
let entry = div(table);
447+
const entry = div(table);
448448
entry.id = i;
449449
entry.classList.add('TableEntries');
450450
entry.classList.add('TableEntriesHover');
@@ -471,7 +471,7 @@ export function actualizeFinishedBookingListForDay(bookings, table) {
471471
if (bookings[i].bookables.length === 0) {
472472
createBookingBookableBox(div(entry));
473473
} else {
474-
let c = div(entry);
474+
const c = div(entry);
475475
for (let k = 0; k < bookings[i].bookables.length; k++) {
476476
createBookingBookableBox(c, bookings[i].bookables[k]);
477477
}

0 commit comments

Comments
 (0)