@osimatic/helpers-js 1.5.19 → 1.5.21
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/data_table.js +87 -80
- package/index.js +2 -2
- package/open_street_map.js +354 -183
- package/package.json +6 -2
- package/tests/contact_details.test.js +0 -7
- package/tests/open_street_map.test.js +592 -251
package/data_table.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
2
|
+
const DataTable = require('datatables.net');
|
|
3
|
+
const { FormHelper } = require('./form_helper');
|
|
4
|
+
const { UrlAndQueryString } = require('./network');
|
|
5
|
+
const { InputPeriod } = require('./form_date');
|
|
6
|
+
|
|
7
|
+
class DataTableManager {
|
|
3
8
|
|
|
4
9
|
static setOptions(options) {
|
|
5
|
-
|
|
10
|
+
DataTableManager.dateTableOptions = Object.assign({}, DataTableManager.getOptions(), options);
|
|
6
11
|
}
|
|
7
12
|
static getOptions() {
|
|
8
|
-
return
|
|
13
|
+
return DataTableManager.dateTableOptions || {};
|
|
9
14
|
}
|
|
10
15
|
|
|
11
16
|
static setCallbackOnLoadData(callback) {
|
|
@@ -29,7 +34,7 @@ class DataTable {
|
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
static getFilterParam(key) {
|
|
32
|
-
return this.criteres[key] ||
|
|
37
|
+
return this.criteres[key] || null;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
static getFilters() {
|
|
@@ -41,50 +46,46 @@ class DataTable {
|
|
|
41
46
|
// ------------------------------------------------------------
|
|
42
47
|
|
|
43
48
|
static init(options) {
|
|
44
|
-
let
|
|
45
|
-
|
|
49
|
+
let {
|
|
50
|
+
div,
|
|
51
|
+
default_filters: defaultFilters = {},
|
|
52
|
+
on_show_filter_form: onShowFilterForm,
|
|
53
|
+
export_modal_enabled: exportModalEnabled,
|
|
54
|
+
on_export: onExport,
|
|
55
|
+
set_export_form: setExportForm,
|
|
56
|
+
on_show_export_form: onShowExportForm,
|
|
57
|
+
on_submit_export_modal: onSubmitExportModal,
|
|
58
|
+
on_load_data: onLoadData,
|
|
59
|
+
} = options;
|
|
46
60
|
|
|
47
|
-
//let form = div.find('.filter_popover_content form');
|
|
48
|
-
//if (typeof form != 'undefined') {
|
|
49
61
|
let queryStringFilters = UrlAndQueryString.parseQuery(window.location.search);
|
|
50
62
|
defaultFilters = Object.assign(defaultFilters, queryStringFilters);
|
|
51
|
-
//}
|
|
52
63
|
|
|
53
64
|
// Bouton filtrer
|
|
54
65
|
let filterLink = div.find('a.filter_link');
|
|
55
66
|
if (filterLink.length) {
|
|
56
|
-
filterLink.
|
|
57
|
-
content: div.find('.filter_popover_content').html(),
|
|
58
|
-
template: '<div class="popover filter_popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>',
|
|
59
|
-
container: 'body',
|
|
60
|
-
// trigger: 'manual',
|
|
61
|
-
trigger: 'click',
|
|
62
|
-
html: true,
|
|
63
|
-
animation: false,
|
|
64
|
-
// placement: 'topRight'
|
|
65
|
-
placement: 'leftTop'
|
|
66
|
-
})
|
|
67
|
-
.click(function(e) {
|
|
68
|
-
// $('.popover').not(this).hide(); // optional, hide other popovers
|
|
67
|
+
filterLink.click(function(e) {
|
|
69
68
|
e.preventDefault();
|
|
70
69
|
});
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
let
|
|
71
|
+
$('div#modal_filter').on('show.bs.modal', function (event) {
|
|
72
|
+
let button = $(event.relatedTarget);
|
|
73
|
+
let modal = $(this);
|
|
74
|
+
let form = modal.find('form');
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
DataTableManager.populateFormFromFilters(form);
|
|
76
77
|
|
|
77
78
|
// Lien input period
|
|
78
79
|
InputPeriod.addLinks(form);
|
|
79
80
|
|
|
80
81
|
// Callback custom
|
|
81
|
-
if (typeof
|
|
82
|
-
|
|
82
|
+
if (typeof onShowFilterForm == 'function') {
|
|
83
|
+
onShowFilterForm(modal, button);
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
form.find('button[type="submit"]').off('click').click(function(e) {
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
DataTableManager.updateFiltersAndLoadData(div, form);
|
|
88
89
|
return false;
|
|
89
90
|
});
|
|
90
91
|
});
|
|
@@ -93,13 +94,13 @@ class DataTable {
|
|
|
93
94
|
// Bouton exporter
|
|
94
95
|
let exportLink = div.find('a.export_link');
|
|
95
96
|
if (exportLink.length) {
|
|
96
|
-
if (
|
|
97
|
+
if (!exportModalEnabled) {
|
|
97
98
|
// sans modal
|
|
98
99
|
exportLink.click(function(e) {
|
|
99
100
|
e.preventDefault();
|
|
100
101
|
var button = $(this).attr('disabled', true).button('loading');
|
|
101
|
-
if (typeof
|
|
102
|
-
|
|
102
|
+
if (typeof onExport == 'function') {
|
|
103
|
+
onExport(button.data('format'), {...DataTableManager.getFilters()}, () => {
|
|
103
104
|
button.attr('disabled', false).button('reset');
|
|
104
105
|
});
|
|
105
106
|
}
|
|
@@ -118,13 +119,13 @@ class DataTable {
|
|
|
118
119
|
let form = modal.find('form');
|
|
119
120
|
|
|
120
121
|
// Fonction de callback permettant d'initialiser contenu du modal export, cette fonction doit renvoyer le contenu du modal
|
|
121
|
-
if (typeof
|
|
122
|
-
modal.find('modal-body').html(
|
|
122
|
+
if (typeof setExportForm == 'function') {
|
|
123
|
+
modal.find('.modal-body').html(setExportForm(modal, button));
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
// Fonction de callback permettant d'initialiser le modal export
|
|
126
|
-
if (typeof
|
|
127
|
-
|
|
127
|
+
if (typeof onShowExportForm == 'function') {
|
|
128
|
+
onShowExportForm(modal, button);
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
let btnSubmit = form.find('button[type="submit"]').attr('disabled', false).button('reset');
|
|
@@ -134,8 +135,8 @@ class DataTable {
|
|
|
134
135
|
|
|
135
136
|
// Une fois le formulaire d'export validé, si fonction callback spécifié, on l'appelle, cette fonction doit renvoyer true ou false pour savoir si le form contient des erreurs ou non.
|
|
136
137
|
let hasErrors = false;
|
|
137
|
-
if (typeof
|
|
138
|
-
hasErrors =
|
|
138
|
+
if (typeof onSubmitExportModal == 'function') {
|
|
139
|
+
hasErrors = onSubmitExportModal(modal, button);
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
if (hasErrors) {
|
|
@@ -144,8 +145,8 @@ class DataTable {
|
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
// S'il n'y a pas d'erreur on enclenche l'export
|
|
147
|
-
if (typeof
|
|
148
|
-
|
|
148
|
+
if (typeof onExport == 'function') {
|
|
149
|
+
onExport(button.data('format'), {...DataTableManager.getFilters()}, form, () => {
|
|
149
150
|
// Retrait du modal
|
|
150
151
|
modal.modal('hide');
|
|
151
152
|
});
|
|
@@ -158,31 +159,26 @@ class DataTable {
|
|
|
158
159
|
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
|
|
162
|
+
DataTableManager.setDefaultFilters(defaultFilters);
|
|
163
|
+
DataTableManager.setCallbackOnLoadData(onLoadData);
|
|
162
164
|
|
|
163
|
-
|
|
164
|
-
DataTable.setCallbackOnLoadData(options.on_load_data);
|
|
165
|
-
|
|
166
|
-
DataTable.loadData(div);
|
|
165
|
+
DataTableManager.loadData(div);
|
|
167
166
|
}
|
|
168
167
|
|
|
169
168
|
static updateFiltersAndLoadData(div, form) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
// DataTable.populateFormFromFilters($('.filter_popover form'));
|
|
169
|
+
DataTableManager.setFiltersFromForm(form);
|
|
170
|
+
DataTableManager.addBrowserHistory();
|
|
173
171
|
|
|
174
|
-
$('
|
|
175
|
-
$('.filter_popover').remove();
|
|
172
|
+
$('div#modal_filter').modal('hide');
|
|
176
173
|
|
|
177
|
-
|
|
174
|
+
DataTableManager.loadData(div);
|
|
178
175
|
}
|
|
179
176
|
|
|
180
177
|
static loadData(div) {
|
|
181
|
-
|
|
182
|
-
DataTable.addLoader(div);
|
|
178
|
+
DataTableManager.addLoader(div);
|
|
183
179
|
|
|
184
180
|
if (typeof this.callbackOnLoadData != 'undefined' && this.callbackOnLoadData != null) {
|
|
185
|
-
this.callbackOnLoadData(div,
|
|
181
|
+
this.callbackOnLoadData(div, DataTableManager.getFilters());
|
|
186
182
|
}
|
|
187
183
|
}
|
|
188
184
|
|
|
@@ -199,7 +195,12 @@ class DataTable {
|
|
|
199
195
|
let queryString = UrlAndQueryString.getQueryString(url);
|
|
200
196
|
//console.log('current QueryString', queryString);
|
|
201
197
|
|
|
202
|
-
//
|
|
198
|
+
// Supprimer de l'URL les clés de critères qui ne sont plus dans savedCriterias
|
|
199
|
+
Object.keys(this.criteres).forEach(key => {
|
|
200
|
+
if (!(key in savedCriterias)) {
|
|
201
|
+
queryString = UrlAndQueryString.deleteParam(queryString, key);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
203
204
|
Object.entries(savedCriterias).forEach(([key, value]) => queryString = UrlAndQueryString.setParam(queryString, key, value));
|
|
204
205
|
queryString = queryString.includes('?') ? queryString.substring(1) : queryString;
|
|
205
206
|
//console.log('new queryString', queryString);
|
|
@@ -221,9 +222,10 @@ class DataTable {
|
|
|
221
222
|
table.find('thead,tfoot').removeClass('hide');
|
|
222
223
|
table.find('tbody').children().remove();
|
|
223
224
|
|
|
224
|
-
if (
|
|
225
|
-
table.DataTable()
|
|
226
|
-
|
|
225
|
+
if (DataTable.isDataTable(table)) {
|
|
226
|
+
const dt = table.DataTable();
|
|
227
|
+
dt.clear();
|
|
228
|
+
dt.destroy();
|
|
227
229
|
}
|
|
228
230
|
}
|
|
229
231
|
|
|
@@ -266,7 +268,7 @@ class DataTable {
|
|
|
266
268
|
table.find('tbody').append('<tr class="no_items '+cssClass+'"><td>'+msgHtml+'</td></tr>');
|
|
267
269
|
// table.after(msgHtml);
|
|
268
270
|
// if (removeLoader) {
|
|
269
|
-
|
|
271
|
+
DataTableManager.removeLoader(div);
|
|
270
272
|
// }
|
|
271
273
|
}
|
|
272
274
|
|
|
@@ -305,7 +307,7 @@ class DataTable {
|
|
|
305
307
|
let table = div.find('table').removeClass('hide');
|
|
306
308
|
|
|
307
309
|
try {
|
|
308
|
-
|
|
310
|
+
DataTableManager.resetContent(div);
|
|
309
311
|
let tableBody = table.find('tbody');
|
|
310
312
|
for (let i = 0; i < data.length; i++) {
|
|
311
313
|
tableBody.append(displayLineCallback(data[i]));
|
|
@@ -328,11 +330,11 @@ class DataTable {
|
|
|
328
330
|
}
|
|
329
331
|
}
|
|
330
332
|
|
|
331
|
-
|
|
333
|
+
DataTableManager.initDataContent(div);
|
|
332
334
|
if (typeof completeCallback == 'function') {
|
|
333
335
|
completeCallback();
|
|
334
336
|
}
|
|
335
|
-
|
|
337
|
+
DataTableManager.removeLoader(div);
|
|
336
338
|
}
|
|
337
339
|
catch (e) {
|
|
338
340
|
console.error(e);
|
|
@@ -355,14 +357,15 @@ class DataTable {
|
|
|
355
357
|
//paging(div.find('select.pagination_max_rows'));
|
|
356
358
|
}
|
|
357
359
|
|
|
358
|
-
if (table.length > 0 && !table.is('[data-no_datatables="1"]') &&
|
|
360
|
+
if (table.length > 0 && !table.is('[data-no_datatables="1"]') && !DataTable.isDataTable(table)) {
|
|
361
|
+
const dtOptions = {...DataTableManager.getOptions()};
|
|
359
362
|
if (table.data('page_length') != null) {
|
|
360
|
-
|
|
363
|
+
dtOptions['pageLength'] = table.data('page_length');
|
|
361
364
|
}
|
|
362
|
-
table.DataTable(
|
|
365
|
+
table.DataTable(dtOptions);
|
|
363
366
|
}
|
|
364
367
|
|
|
365
|
-
|
|
368
|
+
DataTableManager.updateDataContent(div);
|
|
366
369
|
}
|
|
367
370
|
|
|
368
371
|
static updateDataContent(div) {
|
|
@@ -387,31 +390,35 @@ class DataTable {
|
|
|
387
390
|
}
|
|
388
391
|
|
|
389
392
|
static filterRows(table, callback) {
|
|
390
|
-
if (
|
|
393
|
+
if (!DataTable.isDataTable(table)) {
|
|
391
394
|
return;
|
|
392
395
|
}
|
|
393
396
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
397
|
+
const dt = table.DataTable();
|
|
398
|
+
|
|
399
|
+
// Retire le filtre précédent enregistré pour cette table
|
|
400
|
+
DataTable.ext.search = DataTable.ext.search.filter(fn => fn._table !== table[0]);
|
|
401
|
+
|
|
402
|
+
// Enregistre un filtre scopé à cette table uniquement
|
|
403
|
+
const filterFn = function(settings, searchData, index) {
|
|
404
|
+
if (settings.nTable !== table[0]) return true;
|
|
405
|
+
return callback($(dt.row(index).node()));
|
|
406
|
+
};
|
|
407
|
+
filterFn._table = table[0];
|
|
408
|
+
DataTable.ext.search.push(filterFn);
|
|
409
|
+
dt.draw();
|
|
403
410
|
}
|
|
404
411
|
|
|
405
412
|
static sort(table, tdSelector) {
|
|
406
|
-
//if (table.find('tbody tr').length > 0 &&
|
|
407
|
-
if (
|
|
413
|
+
//if (table.find('tbody tr').length > 0 && DataTable.isDataTable(table)) {
|
|
414
|
+
if (DataTable.isDataTable(table)) {
|
|
408
415
|
let idx = table.find('thead tr '+tdSelector).index();
|
|
409
416
|
if (idx >= 0) {
|
|
410
|
-
table.DataTable().order([idx, 'asc']);
|
|
417
|
+
table.DataTable().order([[idx, 'asc']]).draw();
|
|
411
418
|
}
|
|
412
419
|
}
|
|
413
420
|
}
|
|
414
421
|
|
|
415
422
|
}
|
|
416
423
|
|
|
417
|
-
module.exports = {
|
|
424
|
+
module.exports = { DataTableManager };
|
package/index.js
CHANGED
|
@@ -26,7 +26,7 @@ const { Password } = require('./user');
|
|
|
26
26
|
|
|
27
27
|
// exports plugins "maison"
|
|
28
28
|
const { Browser, UserAgent } = require('./visitor');
|
|
29
|
-
const {
|
|
29
|
+
const { DataTableManager } = require('./data_table');
|
|
30
30
|
const { Pagination, Navigation } = require('./paging');
|
|
31
31
|
const { DetailsSubArray } = require('./details_sub_array');
|
|
32
32
|
const { SelectAll } = require('./select_all');
|
|
@@ -53,7 +53,7 @@ const { WebSocket } = require('./web_socket');
|
|
|
53
53
|
module.exports = {
|
|
54
54
|
Array, Object, Number, String,
|
|
55
55
|
HTTPClient, Cookie, UrlAndQueryString, IBAN, BankCard, AudioMedia, VideoMedia, UserMedia, PersonName, Email, TelephoneNumber, DateTime, DatePeriod, TimestampUnix, SqlDate, SqlTime, SqlDateTime, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, GeographicCoordinates, Polygon, HexColor, RgbColor, SocialNetwork, NumberFormatter, Rating, Password,
|
|
56
|
-
Browser,
|
|
56
|
+
Browser, DataTableManager, Pagination, Navigation, DetailsSubArray, SelectAll, MultipleActionInTable, MultipleActionInDivList, MultiFilesInput, EditValue, FormDate, InputPeriod, ShoppingCart, FlashMessage, CountDown, ImportFromCsv, JwtToken, JwtSession, ApiTokenSession, ListBox, WebRTC, WebSocket, EventBus,
|
|
57
57
|
sleep, refresh, chr, ord, trim, empty,
|
|
58
58
|
Chartjs, GoogleCharts, GoogleRecaptcha, GoogleMap, OpenStreetMap
|
|
59
59
|
};
|