@osimatic/helpers-js 1.5.2 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/count_down.js +46 -48
- package/date_time.js +0 -1
- package/details_sub_array.js +65 -50
- package/flash_message.js +10 -6
- package/form_date.js +144 -153
- package/form_helper.js +283 -232
- package/google_charts.js +154 -144
- package/google_maps.js +1 -1
- package/import_from_csv.js +198 -160
- package/multi_files_input.js +44 -35
- package/multiple_action_in_table.js +123 -109
- package/package.json +1 -1
- package/paging.js +103 -84
- package/select_all.js +65 -70
- package/sortable_list.js +12 -13
- package/tests/count_down.test.js +131 -352
- package/tests/details_sub_array.test.js +213 -258
- package/tests/flash_message.test.js +21 -153
- package/tests/form_date.test.js +287 -961
- package/tests/form_helper.test.js +553 -673
- package/tests/google_charts.test.js +338 -339
- package/tests/google_maps.test.js +3 -15
- package/tests/import_from_csv.test.js +421 -640
- package/tests/multi_files_input.test.js +305 -737
- package/tests/multiple_action_in_table.test.js +442 -429
- package/tests/open_street_map.test.js +15 -23
- package/tests/paging.test.js +344 -475
- package/tests/select_all.test.js +232 -318
- package/tests/sortable_list.test.js +176 -500
- package/tests/user.test.js +163 -54
- package/user.js +35 -38
|
@@ -4,28 +4,30 @@ class MultipleActionInTable {
|
|
|
4
4
|
// Ajoute les colonnes select (thead th + tbody td) dans le DOM.
|
|
5
5
|
// Idempotent : sans effet si les colonnes existent déjà.
|
|
6
6
|
// Doit être appelé AVANT l'initialisation DataTable.
|
|
7
|
-
static initCols(table,
|
|
8
|
-
if (!table.
|
|
7
|
+
static initCols(table, cellSelector = 'select') {
|
|
8
|
+
if (!table.classList.contains('table-action_multiple')) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
11
|
if (MultipleActionInTable.getDivBtn(table) == null) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
if (table.
|
|
16
|
-
table.
|
|
15
|
+
if (!table.querySelector('thead tr th[data-key="select"]')) {
|
|
16
|
+
table.querySelector('thead tr').insertAdjacentHTML('afterbegin', '<th class="' + cellSelector + '" data-key="select"></th>');
|
|
17
17
|
}
|
|
18
|
-
table.
|
|
19
|
-
if (
|
|
20
|
-
|
|
18
|
+
table.querySelectorAll('tbody tr:not(.no_items)').forEach(tr => {
|
|
19
|
+
if (!tr.querySelector('td.select')) {
|
|
20
|
+
tr.insertAdjacentHTML('afterbegin', '<td class="select"><input type="checkbox" class="action_multiple_checkbox" name="' + tr.dataset.action_multiple_input_name + '" value="' + tr.dataset.action_multiple_item_id + '"></td>');
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// Initialise les colonnes (via initCols) puis branche les event handlers.
|
|
26
26
|
// Peut être appelé après l'initialisation DataTable.
|
|
27
|
-
static init(table,
|
|
28
|
-
|
|
27
|
+
static init(table, options = {}) {
|
|
28
|
+
const { cellSelector = 'select', imgArrow = '' } = options;
|
|
29
|
+
|
|
30
|
+
if (!table.classList.contains('table-action_multiple')) {
|
|
29
31
|
return;
|
|
30
32
|
}
|
|
31
33
|
|
|
@@ -34,35 +36,38 @@ class MultipleActionInTable {
|
|
|
34
36
|
return;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
MultipleActionInTable.initCols(table,
|
|
39
|
+
MultipleActionInTable.initCols(table, cellSelector);
|
|
38
40
|
|
|
39
|
-
if (!divBtn.
|
|
40
|
-
divBtn.
|
|
41
|
-
divBtn.
|
|
42
|
-
divBtn.
|
|
41
|
+
if (!divBtn.classList.contains('action_multiple_buttons_initialized')) {
|
|
42
|
+
divBtn.insertAdjacentHTML('afterbegin', '<img src="'+imgArrow+'" alt="" /> ');
|
|
43
|
+
divBtn.insertAdjacentHTML('beforeend', '<br/><br/>');
|
|
44
|
+
divBtn.classList.add('action_multiple_buttons_initialized');
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
if (firstTh.
|
|
47
|
-
firstTh.
|
|
47
|
+
const firstTh = table.querySelector('thead tr th');
|
|
48
|
+
if (firstTh && !firstTh.querySelector('input')) {
|
|
49
|
+
firstTh.innerHTML = '<input type="checkbox" class="action_multiple_check_all" />';
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
table.
|
|
51
|
-
|
|
52
|
+
table.querySelectorAll('input.action_multiple_checkbox').forEach(cb => {
|
|
53
|
+
cb.addEventListener('change', () => {
|
|
54
|
+
MultipleActionInTable.updateCheckbox(table);
|
|
55
|
+
});
|
|
52
56
|
});
|
|
53
57
|
|
|
54
|
-
table.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
const checkAll = table.querySelector('input.action_multiple_check_all');
|
|
59
|
+
if (checkAll) {
|
|
60
|
+
const checkAllClone = checkAll.cloneNode(true);
|
|
61
|
+
checkAll.parentElement.replaceChild(checkAllClone, checkAll);
|
|
62
|
+
checkAllClone.addEventListener('click', function() {
|
|
63
|
+
const t = this.closest('table');
|
|
64
|
+
const checkboxes = t.querySelectorAll('input.action_multiple_checkbox');
|
|
65
|
+
const checked = t.querySelectorAll('input.action_multiple_checkbox:checked');
|
|
66
|
+
const newState = checkboxes.length !== checked.length;
|
|
67
|
+
checkboxes.forEach(cb => { cb.checked = newState; });
|
|
68
|
+
MultipleActionInTable.updateCheckbox(t);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
66
71
|
|
|
67
72
|
MultipleActionInTable.updateCheckbox(table);
|
|
68
73
|
}
|
|
@@ -70,60 +75,62 @@ class MultipleActionInTable {
|
|
|
70
75
|
static updateCheckbox(table) {
|
|
71
76
|
MultipleActionInTable.showButtonsAction(table);
|
|
72
77
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
const allCheckbox = table.querySelectorAll('input.action_multiple_checkbox');
|
|
79
|
+
const allCheckboxChecked = table.querySelectorAll('input.action_multiple_checkbox:checked');
|
|
80
|
+
const checkboxSelectAll = table.querySelector('thead tr th input.action_multiple_check_all');
|
|
76
81
|
|
|
77
|
-
if (
|
|
78
|
-
checkboxSelectAll.addClass('hide');
|
|
82
|
+
if (!checkboxSelectAll) {
|
|
79
83
|
return;
|
|
80
84
|
}
|
|
81
85
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
checkboxSelectAll.prop('checked', false);
|
|
86
|
+
if (allCheckbox.length === 0) {
|
|
87
|
+
checkboxSelectAll.classList.add('hide');
|
|
88
|
+
return;
|
|
88
89
|
}
|
|
90
|
+
|
|
91
|
+
checkboxSelectAll.classList.remove('hide');
|
|
92
|
+
checkboxSelectAll.checked = allCheckbox.length === allCheckboxChecked.length;
|
|
89
93
|
}
|
|
90
94
|
|
|
91
95
|
static getDivBtn(table) {
|
|
92
|
-
|
|
93
|
-
let divBtn = divTableResponsive.
|
|
94
|
-
if (divBtn.
|
|
96
|
+
const divTableResponsive = table.parentElement;
|
|
97
|
+
let divBtn = divTableResponsive.nextElementSibling;
|
|
98
|
+
if (divBtn && divBtn.classList.contains('action_multiple_buttons')) {
|
|
95
99
|
return divBtn;
|
|
96
100
|
}
|
|
97
|
-
divBtn = divTableResponsive.
|
|
98
|
-
if (divBtn.
|
|
101
|
+
divBtn = divTableResponsive.parentElement?.parentElement?.parentElement?.nextElementSibling;
|
|
102
|
+
if (divBtn && divBtn.classList.contains('action_multiple_buttons')) {
|
|
99
103
|
return divBtn;
|
|
100
104
|
}
|
|
101
105
|
return null;
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
static showButtonsAction(table) {
|
|
105
|
-
|
|
109
|
+
const divBtn = MultipleActionInTable.getDivBtn(table);
|
|
106
110
|
if (divBtn == null) {
|
|
107
111
|
return;
|
|
108
112
|
}
|
|
109
113
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
const nbItems = table.querySelectorAll('input.action_multiple_checkbox:checked').length;
|
|
115
|
+
const isHidden = divBtn.classList.contains('hide');
|
|
116
|
+
const isVisible = !isHidden;
|
|
113
117
|
|
|
114
|
-
if (nbItems > 0 &&
|
|
115
|
-
divBtn.
|
|
118
|
+
if (nbItems > 0 && isHidden) {
|
|
119
|
+
divBtn.classList.remove('hide');
|
|
116
120
|
}
|
|
117
121
|
// 13/04/2021 : si le tableau est caché cela veut dire qu'il est en train de s'initialiser (après avoir chargé les données) et donc s'il n'y a pas de ligne sélectionnées, on cache la div buttons
|
|
118
|
-
else if ((nbItems === 0 &&
|
|
119
|
-
divBtn.
|
|
122
|
+
else if ((nbItems === 0 && isVisible) || (nbItems === 0 && table.classList.contains('hide'))) {
|
|
123
|
+
divBtn.classList.add('hide');
|
|
120
124
|
}
|
|
121
125
|
|
|
122
126
|
// affichage aucune action possible si aucun bouton n'est visible
|
|
123
|
-
if (divBtn.
|
|
124
|
-
divBtn.
|
|
125
|
-
if (divBtn.
|
|
126
|
-
divBtn.
|
|
127
|
+
if (!divBtn.classList.contains('hide')) {
|
|
128
|
+
divBtn.querySelectorAll('span.no_button').forEach(el => el.remove());
|
|
129
|
+
if (divBtn.querySelectorAll('button:not(.hide), a:not(.hide)').length === 0) {
|
|
130
|
+
const img = divBtn.querySelector('img');
|
|
131
|
+
if (img) {
|
|
132
|
+
img.insertAdjacentHTML('afterend', '<span class="no_button"><em>aucune action possible</em></span>');
|
|
133
|
+
}
|
|
127
134
|
}
|
|
128
135
|
}
|
|
129
136
|
}
|
|
@@ -132,52 +139,57 @@ class MultipleActionInTable {
|
|
|
132
139
|
|
|
133
140
|
class MultipleActionInDivList {
|
|
134
141
|
// init checkbox
|
|
135
|
-
static init(contentDiv) {
|
|
142
|
+
static init(contentDiv, options = {}) {
|
|
143
|
+
const { imgArrow = '' } = options;
|
|
144
|
+
|
|
136
145
|
let buttonsDiv = MultipleActionInDivList.getButtonsDiv(contentDiv);
|
|
137
146
|
if (buttonsDiv == null) {
|
|
138
147
|
return;
|
|
139
148
|
}
|
|
140
149
|
|
|
141
|
-
buttonsDiv.
|
|
150
|
+
buttonsDiv.classList.add('hide');
|
|
142
151
|
|
|
143
152
|
// Si aucune div sélectionnable, on n'applique pas le plugin
|
|
144
|
-
if (!contentDiv.
|
|
153
|
+
if (!contentDiv.querySelectorAll('.multiple_action').length) {
|
|
145
154
|
return;
|
|
146
155
|
}
|
|
147
156
|
|
|
148
|
-
if (!buttonsDiv.
|
|
149
|
-
buttonsDiv.
|
|
150
|
-
buttonsDiv.
|
|
151
|
-
buttonsDiv.
|
|
157
|
+
if (!buttonsDiv.dataset.action_multiple_buttons_initialized) {
|
|
158
|
+
buttonsDiv.insertAdjacentHTML('afterbegin', '<img src="'+imgArrow+'" alt="" /> ');
|
|
159
|
+
buttonsDiv.insertAdjacentHTML('beforeend', '<br/><br/>');
|
|
160
|
+
buttonsDiv.dataset.action_multiple_buttons_initialized = '1';
|
|
152
161
|
}
|
|
153
162
|
|
|
154
163
|
// Ajout checkbox pour chaque div sélectionnable
|
|
155
|
-
contentDiv.
|
|
156
|
-
if (
|
|
157
|
-
|
|
164
|
+
contentDiv.querySelectorAll('.multiple_action').forEach(div => {
|
|
165
|
+
if (!div.querySelector('div.multi_select')) {
|
|
166
|
+
div.insertAdjacentHTML('afterbegin', '<div class="multi_select float-start me-2"><input type="checkbox" class="action_multiple_checkbox" name="'+div.dataset.action_multiple_input_name+'" value="'+div.dataset.action_multiple_item_id+'"></div>');
|
|
158
167
|
}
|
|
159
168
|
});
|
|
160
169
|
|
|
161
170
|
// Ajout checkbox select all
|
|
162
|
-
if (contentDiv.
|
|
163
|
-
contentDiv.
|
|
171
|
+
if (!contentDiv.querySelector('input.action_multiple_check_all')) {
|
|
172
|
+
contentDiv.insertAdjacentHTML('afterbegin', '<p class="mb-2"><input type="checkbox" class="action_multiple_check_all" /> Tout sélectionner</p>');
|
|
164
173
|
}
|
|
165
174
|
|
|
166
|
-
contentDiv.
|
|
167
|
-
|
|
175
|
+
contentDiv.querySelectorAll('input.action_multiple_checkbox').forEach(cb => {
|
|
176
|
+
cb.addEventListener('change', () => {
|
|
177
|
+
MultipleActionInDivList.updateCheckbox(contentDiv);
|
|
178
|
+
});
|
|
168
179
|
});
|
|
169
180
|
|
|
170
|
-
contentDiv.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
const checkAll = contentDiv.querySelector('input.action_multiple_check_all');
|
|
182
|
+
if (checkAll) {
|
|
183
|
+
const checkAllClone = checkAll.cloneNode(true);
|
|
184
|
+
checkAll.parentElement.replaceChild(checkAllClone, checkAll);
|
|
185
|
+
checkAllClone.addEventListener('click', function() {
|
|
186
|
+
const checkboxes = contentDiv.querySelectorAll('input.action_multiple_checkbox');
|
|
187
|
+
const checked = contentDiv.querySelectorAll('input.action_multiple_checkbox:checked');
|
|
188
|
+
const newState = checkboxes.length !== checked.length;
|
|
189
|
+
checkboxes.forEach(cb => { cb.checked = newState; });
|
|
190
|
+
MultipleActionInDivList.updateCheckbox(contentDiv);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
181
193
|
|
|
182
194
|
MultipleActionInDivList.updateCheckbox(contentDiv);
|
|
183
195
|
}
|
|
@@ -185,55 +197,57 @@ class MultipleActionInDivList {
|
|
|
185
197
|
static updateCheckbox(contentDiv) {
|
|
186
198
|
MultipleActionInDivList.showButtonsAction(contentDiv);
|
|
187
199
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
200
|
+
const allCheckbox = contentDiv.querySelectorAll('input.action_multiple_checkbox');
|
|
201
|
+
const allCheckboxChecked = contentDiv.querySelectorAll('input.action_multiple_checkbox:checked');
|
|
202
|
+
const checkboxSelectAll = contentDiv.querySelector('input.action_multiple_check_all');
|
|
191
203
|
|
|
192
|
-
if (
|
|
193
|
-
checkboxSelectAll.addClass('hide');
|
|
204
|
+
if (!checkboxSelectAll) {
|
|
194
205
|
return;
|
|
195
206
|
}
|
|
196
207
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
checkboxSelectAll.prop('checked', false);
|
|
208
|
+
if (allCheckbox.length === 0) {
|
|
209
|
+
checkboxSelectAll.classList.add('hide');
|
|
210
|
+
return;
|
|
203
211
|
}
|
|
212
|
+
|
|
213
|
+
checkboxSelectAll.classList.remove('hide');
|
|
214
|
+
checkboxSelectAll.checked = allCheckbox.length === allCheckboxChecked.length;
|
|
204
215
|
}
|
|
205
216
|
|
|
206
217
|
static getButtonsDiv(contentDiv) {
|
|
207
|
-
|
|
208
|
-
if (buttonsDiv.
|
|
218
|
+
const buttonsDiv = contentDiv.nextElementSibling;
|
|
219
|
+
if (buttonsDiv && buttonsDiv.classList.contains('action_multiple_buttons')) {
|
|
209
220
|
return buttonsDiv;
|
|
210
221
|
}
|
|
211
222
|
return null;
|
|
212
223
|
}
|
|
213
224
|
|
|
214
225
|
static showButtonsAction(contentDiv) {
|
|
215
|
-
|
|
226
|
+
const buttonsDiv = MultipleActionInDivList.getButtonsDiv(contentDiv);
|
|
216
227
|
if (buttonsDiv == null) {
|
|
217
228
|
return;
|
|
218
229
|
}
|
|
219
230
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
231
|
+
const nbItems = contentDiv.querySelectorAll('input.action_multiple_checkbox:checked').length;
|
|
232
|
+
const isHidden = buttonsDiv.classList.contains('hide');
|
|
233
|
+
const isVisible = !isHidden;
|
|
223
234
|
|
|
224
|
-
if (nbItems > 0 &&
|
|
225
|
-
buttonsDiv.
|
|
235
|
+
if (nbItems > 0 && isHidden) {
|
|
236
|
+
buttonsDiv.classList.remove('hide');
|
|
226
237
|
}
|
|
227
238
|
// 13/04/2021 : si le tableau est caché cela veut dire qu'il est en train de s'initialiser (après avoir chargé les données) et donc s'il n'y a pas de ligne sélectionnées, on cache la div buttons
|
|
228
|
-
else if ((nbItems === 0 &&
|
|
229
|
-
buttonsDiv.
|
|
239
|
+
else if ((nbItems === 0 && isVisible) || (nbItems === 0 && contentDiv.classList.contains('hide'))) {
|
|
240
|
+
buttonsDiv.classList.add('hide');
|
|
230
241
|
}
|
|
231
242
|
|
|
232
243
|
// affichage aucune action possible si aucun bouton n'est visible
|
|
233
|
-
if (buttonsDiv.
|
|
234
|
-
buttonsDiv.
|
|
235
|
-
if (buttonsDiv.
|
|
236
|
-
buttonsDiv.
|
|
244
|
+
if (!buttonsDiv.classList.contains('hide')) {
|
|
245
|
+
buttonsDiv.querySelectorAll('span.no_button').forEach(el => el.remove());
|
|
246
|
+
if (buttonsDiv.querySelectorAll('button:not(.hide), a:not(.hide)').length === 0) {
|
|
247
|
+
const img = buttonsDiv.querySelector('img');
|
|
248
|
+
if (img) {
|
|
249
|
+
img.insertAdjacentHTML('afterend', '<span class="no_button"><em>aucune action possible</em></span>');
|
|
250
|
+
}
|
|
237
251
|
}
|
|
238
252
|
}
|
|
239
253
|
}
|
package/package.json
CHANGED
package/paging.js
CHANGED
|
@@ -1,146 +1,165 @@
|
|
|
1
1
|
// Fonction commune de pagination
|
|
2
2
|
//Bootstrap class pagination https://getbootstrap.com/docs/3.3/components/#pagination
|
|
3
3
|
|
|
4
|
+
const { UrlAndQueryString } = require('./network');
|
|
5
|
+
|
|
4
6
|
class Pagination {
|
|
5
|
-
static paginateCards(div, nbItemsPerPage
|
|
6
|
-
Pagination.paginate(div, div.
|
|
7
|
+
static paginateCards(div, nbItemsPerPage) {
|
|
8
|
+
Pagination.paginate(div, div.querySelectorAll('.pagination_item'), nbItemsPerPage, null);
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
static paginateTable(table, select
|
|
10
|
-
Pagination.paginate(table, table.
|
|
11
|
+
static paginateTable(table, select=null) {
|
|
12
|
+
Pagination.paginate(table, table.querySelectorAll('tbody tr:not(.hide)'), parseInt(table.dataset.max_rows), select);
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
static paginate(div, items, nbItemsPerPage, select,
|
|
15
|
+
static paginate(div, items, nbItemsPerPage, select=null, labelDisplayAll=null) {
|
|
14
16
|
let maxItems = nbItemsPerPage;
|
|
15
17
|
|
|
16
|
-
if (
|
|
18
|
+
if (!div) {
|
|
17
19
|
return;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
if (
|
|
21
|
-
if (!select.children
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
if (select != null) {
|
|
23
|
+
if (!select.children.length) {
|
|
24
|
+
const opt0 = document.createElement('option');
|
|
25
|
+
opt0.value = '0';
|
|
26
|
+
opt0.textContent = labelDisplayAll ?? 'Afficher tout';
|
|
27
|
+
select.appendChild(opt0);
|
|
28
|
+
|
|
29
|
+
const nbRowsList = select.dataset.nb_rows_list ? select.dataset.nb_rows_list.split(',') : [5, 10, 25, 50];
|
|
30
|
+
nbRowsList.forEach(nbRows => {
|
|
31
|
+
const opt = document.createElement('option');
|
|
32
|
+
opt.value = nbRows;
|
|
33
|
+
opt.textContent = nbRows;
|
|
34
|
+
select.appendChild(opt);
|
|
26
35
|
});
|
|
27
36
|
|
|
28
|
-
if (select.
|
|
29
|
-
select.
|
|
37
|
+
if (select.dataset.default_nb_rows) {
|
|
38
|
+
select.value = select.dataset.default_nb_rows;
|
|
30
39
|
}
|
|
31
40
|
}
|
|
32
41
|
|
|
33
|
-
maxItems = parseInt(select.
|
|
42
|
+
maxItems = parseInt(select.value);
|
|
34
43
|
|
|
35
|
-
select.change(
|
|
44
|
+
select.addEventListener('change', () => Pagination.paginate(div, items, nbItemsPerPage, select));
|
|
36
45
|
}
|
|
37
46
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Pagination.initPaginationDiv(div, ulPagination, true, true); //top
|
|
42
|
-
Pagination.initPaginationDiv(div, ulPagination, false, true); //bottom
|
|
43
|
-
} else {
|
|
44
|
-
Pagination.initPaginationDiv(div, ulPagination, false, false); //bottom
|
|
45
|
-
}
|
|
47
|
+
document.querySelectorAll('ul.pagination').forEach(ul => ul.remove());
|
|
48
|
+
Pagination.initPaginationDiv(div, true); // top
|
|
49
|
+
Pagination.initPaginationDiv(div, false); // bottom
|
|
46
50
|
|
|
47
|
-
Pagination.initPaginationItems(items, maxItems
|
|
51
|
+
Pagination.initPaginationItems(items, maxItems);
|
|
48
52
|
}
|
|
49
53
|
|
|
50
|
-
static initPaginationDiv(div,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
static initPaginationDiv(div, onTop) {
|
|
55
|
+
const ul = document.createElement('ul');
|
|
56
|
+
ul.className = 'pagination';
|
|
57
|
+
|
|
58
|
+
const paginationLinks = div.querySelector('.pagination_links');
|
|
59
|
+
if (paginationLinks) {
|
|
60
|
+
if (onTop) {
|
|
61
|
+
paginationLinks.prepend(ul);
|
|
62
|
+
} else {
|
|
63
|
+
paginationLinks.appendChild(ul);
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
if (onTop) {
|
|
67
|
+
div.before(ul);
|
|
55
68
|
} else {
|
|
56
|
-
|
|
69
|
+
div.after(ul);
|
|
57
70
|
}
|
|
58
71
|
}
|
|
59
72
|
}
|
|
60
73
|
|
|
61
|
-
static initPaginationItems(items, maxItems
|
|
62
|
-
const
|
|
74
|
+
static initPaginationItems(items, maxItems) {
|
|
75
|
+
const paginationUls = [...document.querySelectorAll('ul.pagination')];
|
|
63
76
|
|
|
64
|
-
|
|
77
|
+
const totalItems = items.length;
|
|
65
78
|
|
|
66
79
|
let lineNum = 0;
|
|
67
|
-
items.
|
|
80
|
+
items.forEach(item => {
|
|
68
81
|
lineNum++;
|
|
69
82
|
if (0 === maxItems || lineNum <= maxItems) {
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
$(this).hide();
|
|
83
|
+
item.style.display = '';
|
|
84
|
+
} else {
|
|
85
|
+
item.style.display = 'none';
|
|
74
86
|
}
|
|
75
87
|
});
|
|
76
88
|
|
|
77
|
-
|
|
89
|
+
paginationUls.forEach(ul => ul.querySelectorAll('li').forEach(li => li.remove()));
|
|
78
90
|
|
|
79
91
|
if (0 === maxItems || totalItems < maxItems) {
|
|
80
|
-
|
|
92
|
+
paginationUls.forEach(ul => ul.classList.add('hide'));
|
|
81
93
|
return;
|
|
82
94
|
}
|
|
83
95
|
|
|
84
|
-
|
|
85
|
-
for (let i=1; i <= nbPages; i++) {
|
|
86
|
-
|
|
96
|
+
const nbPages = Math.ceil(totalItems / maxItems);
|
|
97
|
+
for (let i = 1; i <= nbPages; i++) {
|
|
98
|
+
paginationUls.forEach(ul => {
|
|
99
|
+
ul.insertAdjacentHTML('beforeend', '<li class="page-item" data-page="' + i + '"><a href="#" class="page-link">' + i + '<span class="sr-only">(current)</span></a></li>');
|
|
100
|
+
});
|
|
87
101
|
}
|
|
88
102
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
103
|
+
paginationUls.forEach(ul => ul.classList.remove('hide'));
|
|
104
|
+
paginationUls.forEach(ul => {
|
|
105
|
+
const firstLi = ul.querySelector('li:first-child');
|
|
106
|
+
if (firstLi) firstLi.classList.add('active');
|
|
107
|
+
});
|
|
108
|
+
paginationUls.forEach(ul => {
|
|
109
|
+
ul.querySelectorAll('li').forEach(li => {
|
|
110
|
+
li.addEventListener('click', function(e) {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
paginationUls.forEach(ul2 => ul2.querySelectorAll('li').forEach(l => l.classList.remove('active')));
|
|
113
|
+
|
|
114
|
+
const pageNum = parseInt(this.dataset.page);
|
|
115
|
+
let trIndex = 0;
|
|
116
|
+
|
|
117
|
+
document.querySelectorAll('li[data-page="' + pageNum + '"]').forEach(l => l.classList.add('active'));
|
|
118
|
+
|
|
119
|
+
items.forEach(item => {
|
|
120
|
+
trIndex++;
|
|
121
|
+
if (trIndex > (maxItems * pageNum) || trIndex <= ((maxItems * pageNum) - maxItems)) {
|
|
122
|
+
item.style.display = 'none';
|
|
123
|
+
} else {
|
|
124
|
+
item.style.display = '';
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
111
128
|
});
|
|
112
|
-
|
|
113
|
-
return false;
|
|
114
|
-
}));
|
|
129
|
+
});
|
|
115
130
|
}
|
|
116
131
|
}
|
|
117
132
|
|
|
118
133
|
class Navigation {
|
|
119
134
|
static activateTab(a) {
|
|
120
|
-
//console.log(a);
|
|
121
|
-
//a.click();
|
|
122
135
|
let ulNav = a.closest('.nav');
|
|
123
|
-
let tabContent = ulNav.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
136
|
+
let tabContent = ulNav.parentElement.querySelector('.tab-content');
|
|
137
|
+
|
|
138
|
+
ulNav.querySelectorAll('a.nav-link').forEach(navLink => {
|
|
139
|
+
navLink.classList.remove('active');
|
|
140
|
+
const id = navLink.getAttribute('href');
|
|
141
|
+
if (id && id.charAt(0) === '#') {
|
|
142
|
+
const pane = tabContent.querySelector(id);
|
|
143
|
+
if (pane) {
|
|
144
|
+
pane.classList.remove('active');
|
|
145
|
+
pane.classList.remove('show');
|
|
146
|
+
}
|
|
131
147
|
}
|
|
132
148
|
});
|
|
133
149
|
|
|
134
|
-
|
|
135
|
-
a.
|
|
136
|
-
|
|
150
|
+
a.classList.add('active');
|
|
151
|
+
const targetPane = tabContent.querySelector(a.getAttribute('href'));
|
|
152
|
+
if (targetPane) {
|
|
153
|
+
targetPane.classList.add('active');
|
|
154
|
+
targetPane.classList.add('show');
|
|
155
|
+
}
|
|
137
156
|
}
|
|
138
157
|
|
|
139
158
|
static showTab(a) {
|
|
140
159
|
if (typeof bootstrap == 'undefined') {
|
|
141
160
|
return;
|
|
142
161
|
}
|
|
143
|
-
let tab = new bootstrap.Tab(a
|
|
162
|
+
let tab = new bootstrap.Tab(a);
|
|
144
163
|
tab.show();
|
|
145
164
|
}
|
|
146
165
|
|
|
@@ -180,7 +199,7 @@ function paginationAsList(nbResultatsTotal, nbResultatsParPage, urlPage, nomPara
|
|
|
180
199
|
|
|
181
200
|
// Initialisation du numéro de la page courante
|
|
182
201
|
//var query = window.location.search.substring(1).query.split("&");
|
|
183
|
-
|
|
202
|
+
|
|
184
203
|
var url = new URL(currentUrl);
|
|
185
204
|
var params = url.searchParams;
|
|
186
205
|
|