@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
package/count_down.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
class CountDown {
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
static init(div, options = {}) {
|
|
4
|
+
const {
|
|
5
|
+
onRefreshData,
|
|
6
|
+
labelNextUpdate = 'Prochaine mise à jour',
|
|
7
|
+
labelDoUpdate = 'Mettre à jour',
|
|
8
|
+
} = options;
|
|
9
|
+
|
|
5
10
|
if (!div.length) {
|
|
6
11
|
return;
|
|
7
12
|
}
|
|
@@ -14,43 +19,63 @@ class CountDown {
|
|
|
14
19
|
.append('<div class="count_down_link"><a href="#" data-loading-text="<i class=\'fa fa-circle-notch fa-spin\'></i>">'+labelDoUpdate+'</a></div>')
|
|
15
20
|
;
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
let alreadyMakingRequest = false;
|
|
23
|
+
let secondsBefRefresh = 10;
|
|
24
|
+
let refreshIntervalMillis = 60;
|
|
25
|
+
let currentMillis = 0;
|
|
26
|
+
let currentSecond = 0;
|
|
27
|
+
|
|
28
|
+
function refreshData() {
|
|
29
|
+
currentMillis = 0;
|
|
30
|
+
|
|
31
|
+
//Pour ne pas relancer une requête si la précédente n'est pas encore finie
|
|
32
|
+
if (true === alreadyMakingRequest) {
|
|
33
|
+
console.log('Already making request, no new request lauched.');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
19
36
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
37
|
+
if (typeof onRefreshData == 'function') {
|
|
38
|
+
alreadyMakingRequest = true;
|
|
39
|
+
div.find('.count_down_link a').attr('disabled', true).button('loading');
|
|
40
|
+
|
|
41
|
+
onRefreshData(
|
|
42
|
+
// completeCallback
|
|
43
|
+
() => {
|
|
44
|
+
alreadyMakingRequest = false;
|
|
45
|
+
div.find('.count_down_link a').attr('disabled', false).button('reset');
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
25
50
|
|
|
26
51
|
if (div.find('.count_down_link a').length) {
|
|
27
52
|
div.find('.count_down_link a').click(() => {
|
|
28
|
-
|
|
53
|
+
refreshData();
|
|
29
54
|
return false;
|
|
30
55
|
});
|
|
31
56
|
}
|
|
32
57
|
|
|
33
58
|
setInterval(() => {
|
|
34
59
|
if (!div.find('.count_down_link a').length || !div.find('.count_down_link a').prop('disabled')) {
|
|
35
|
-
|
|
60
|
+
currentMillis += refreshIntervalMillis;
|
|
36
61
|
}
|
|
37
62
|
else {
|
|
38
|
-
|
|
63
|
+
currentMillis = 0;
|
|
39
64
|
}
|
|
40
65
|
|
|
41
|
-
|
|
66
|
+
currentSecond = parseInt(currentMillis / 1000);
|
|
42
67
|
|
|
43
68
|
//countDownRefresh();
|
|
44
69
|
var divCountDownText;
|
|
45
70
|
var divCountDownCurrentSizePx;
|
|
46
71
|
|
|
47
|
-
if (
|
|
72
|
+
if (currentSecond >= secondsBefRefresh) {
|
|
48
73
|
divCountDownCurrentSizePx = 120;
|
|
49
74
|
divCountDownText = '0s';
|
|
50
75
|
}
|
|
51
76
|
else {
|
|
52
|
-
divCountDownCurrentSizePx = Math.round((120/(
|
|
53
|
-
divCountDownText = (
|
|
77
|
+
divCountDownCurrentSizePx = Math.round((120/(secondsBefRefresh*1000)) * currentMillis);
|
|
78
|
+
divCountDownText = (secondsBefRefresh-currentSecond) + 's';
|
|
54
79
|
}
|
|
55
80
|
|
|
56
81
|
if (div.find('.count_down_current').length) {
|
|
@@ -60,42 +85,15 @@ class CountDown {
|
|
|
60
85
|
div.find('.count_down_text').html(divCountDownText);
|
|
61
86
|
}
|
|
62
87
|
|
|
63
|
-
if (
|
|
64
|
-
|
|
88
|
+
if (currentSecond >= secondsBefRefresh) {
|
|
89
|
+
currentMillis = 0;
|
|
65
90
|
setTimeout(() => {
|
|
66
|
-
|
|
91
|
+
refreshData();
|
|
67
92
|
}, 100);
|
|
68
93
|
}
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
this.refreshData();
|
|
72
|
-
}
|
|
94
|
+
}, refreshIntervalMillis);
|
|
73
95
|
|
|
74
|
-
|
|
75
|
-
this.callbackOnRefreshData = callback;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
refreshData() {
|
|
79
|
-
this.currentMillis = 0;
|
|
80
|
-
|
|
81
|
-
//Pour ne pas relancer une requête si la précédente n'est pas encore finie
|
|
82
|
-
if (true === this.alreadyMakingRequest) {
|
|
83
|
-
console.log('Already making request, no new request lauched.');
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (typeof this.callbackOnRefreshData == 'function') {
|
|
88
|
-
CountDown.alreadyMakingRequest = true;
|
|
89
|
-
this.div.find('.count_down_link a').attr('disabled', true).button('loading');
|
|
90
|
-
|
|
91
|
-
this.callbackOnRefreshData(
|
|
92
|
-
// completeCallback
|
|
93
|
-
() => {
|
|
94
|
-
this.alreadyMakingRequest = false;
|
|
95
|
-
this.div.find('.count_down_link a').attr('disabled', false).button('reset');
|
|
96
|
-
}
|
|
97
|
-
);
|
|
98
|
-
}
|
|
96
|
+
refreshData();
|
|
99
97
|
}
|
|
100
98
|
|
|
101
99
|
}
|
package/date_time.js
CHANGED
package/details_sub_array.js
CHANGED
|
@@ -1,121 +1,136 @@
|
|
|
1
|
+
const { HTTPClient } = require('./http_client');
|
|
2
|
+
|
|
1
3
|
class DetailsSubArray {
|
|
2
4
|
|
|
3
|
-
static initDetailsLink(table,
|
|
5
|
+
static initDetailsLink(table, options = {}) {
|
|
6
|
+
const {
|
|
7
|
+
onSuccess,
|
|
8
|
+
onError,
|
|
9
|
+
onBeforeSend,
|
|
10
|
+
labelErrorOccurred = 'Une erreur s\'est produite.',
|
|
11
|
+
showDetailsLabel = 'Afficher les détails',
|
|
12
|
+
hideDetailsLabel = 'Masquer les détails',
|
|
13
|
+
} = options;
|
|
14
|
+
|
|
4
15
|
function getNbColumns(tr) {
|
|
5
|
-
return tr.closest('table').
|
|
16
|
+
return tr.closest('table').querySelector('thead tr').children.length;
|
|
6
17
|
}
|
|
7
18
|
function displayErrorRow(tr) {
|
|
8
|
-
tr.
|
|
19
|
+
tr.insertAdjacentHTML('afterend', '<tr class="text-error"><td colspan="'+getNbColumns(tr)+'">'+labelErrorOccurred+'</td></tr>');
|
|
9
20
|
}
|
|
10
21
|
function displayDetailsRow(tr, content) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
const td = document.createElement('td');
|
|
23
|
+
td.setAttribute('colspan', getNbColumns(tr));
|
|
24
|
+
if (content instanceof Node) {
|
|
25
|
+
td.appendChild(content);
|
|
26
|
+
} else {
|
|
27
|
+
td.innerHTML = content || '';
|
|
28
|
+
}
|
|
29
|
+
const trContent = document.createElement('tr');
|
|
30
|
+
trContent.className = 'participants';
|
|
31
|
+
trContent.appendChild(td);
|
|
32
|
+
tr.insertAdjacentElement('afterend', trContent);
|
|
19
33
|
}
|
|
20
34
|
|
|
21
35
|
function hideDetailsRow(link) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
36
|
+
const tr = link.closest('tr');
|
|
37
|
+
tr.classList.add('folded');
|
|
38
|
+
const next = tr.nextElementSibling;
|
|
39
|
+
if (next && next.classList.contains('participants')) {
|
|
40
|
+
next.remove();
|
|
25
41
|
}
|
|
26
42
|
showPlusButton(link);
|
|
27
43
|
}
|
|
28
44
|
|
|
29
45
|
function showPlusButton(link) {
|
|
30
|
-
link.
|
|
46
|
+
link.title = showDetailsLabel;
|
|
47
|
+
link.disabled = false;
|
|
48
|
+
link.innerHTML = '<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>';
|
|
31
49
|
}
|
|
32
50
|
function showMinusButton(link) {
|
|
33
|
-
link.
|
|
51
|
+
link.title = hideDetailsLabel;
|
|
52
|
+
link.disabled = false;
|
|
53
|
+
link.innerHTML = '<span class="glyphicon glyphicon-minus" aria-hidden="true"></span>';
|
|
34
54
|
}
|
|
35
55
|
|
|
36
56
|
function displayLoading(link) {
|
|
37
|
-
link.
|
|
38
|
-
|
|
39
|
-
tr
|
|
57
|
+
link.disabled = true;
|
|
58
|
+
link.innerHTML = '<i class="fa fa-circle-notch fa-spin"></i>';
|
|
59
|
+
const tr = link.closest('tr');
|
|
60
|
+
tr.insertAdjacentHTML('afterend', '<tr class="waiting_icon"><td colspan="'+getNbColumns(tr)+'" class="center"><i class="fa fa-circle-notch fa-spin"></i></td></tr>');
|
|
40
61
|
}
|
|
41
|
-
function hideLoading(
|
|
62
|
+
function hideLoading() {
|
|
42
63
|
// todo : cacher que le loader du lien au lieu de tous les loaders (cas ou l'user clique sur tous les boutons rapidement)
|
|
43
|
-
|
|
44
|
-
$(('tr.waiting_icon')).remove();
|
|
45
|
-
}
|
|
64
|
+
document.querySelectorAll('tr.waiting_icon').forEach(el => el.remove());
|
|
46
65
|
}
|
|
47
66
|
|
|
48
67
|
function setHideDetailsLink(link) {
|
|
49
68
|
showMinusButton(link);
|
|
50
|
-
link.
|
|
51
|
-
|
|
69
|
+
link.onclick = function(e) {
|
|
70
|
+
e.preventDefault();
|
|
52
71
|
hideDetailsRow(link);
|
|
53
72
|
setDisplayDetailsLink(link);
|
|
54
|
-
|
|
55
|
-
});
|
|
73
|
+
};
|
|
56
74
|
}
|
|
57
75
|
|
|
58
76
|
function setDisplayDetailsLink(link) {
|
|
59
|
-
link.
|
|
60
|
-
|
|
77
|
+
link.onclick = function(e) {
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
link.onclick = null;
|
|
61
80
|
hideDetailsRow(link);
|
|
62
81
|
doDetailsActionRequest(link);
|
|
63
|
-
|
|
64
|
-
});
|
|
82
|
+
};
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
function doDetailsActionRequest(link) {
|
|
68
86
|
displayLoading(link);
|
|
69
87
|
|
|
70
|
-
if (
|
|
71
|
-
displayDetailsRow(link.closest('tr'),
|
|
72
|
-
hideLoading(
|
|
88
|
+
if (onBeforeSend != null) {
|
|
89
|
+
displayDetailsRow(link.closest('tr'), onBeforeSend(link));
|
|
90
|
+
hideLoading();
|
|
73
91
|
setHideDetailsLink(link);
|
|
74
92
|
return;
|
|
75
93
|
}
|
|
76
94
|
|
|
77
95
|
function onComplete() {
|
|
78
|
-
hideLoading(
|
|
96
|
+
hideLoading();
|
|
79
97
|
setHideDetailsLink(link);
|
|
80
|
-
//link.attr('disabled', false).button('reset');
|
|
81
98
|
}
|
|
82
99
|
|
|
83
|
-
|
|
84
|
-
HTTPClient.request('GET', link.data('url_details'), null,
|
|
100
|
+
HTTPClient.request('GET', link.dataset.url_details, null,
|
|
85
101
|
(jsonObj) => {
|
|
86
102
|
if (jsonObj == null) {
|
|
87
|
-
if (
|
|
88
|
-
|
|
103
|
+
if (onError != null) {
|
|
104
|
+
onError(link);
|
|
89
105
|
return;
|
|
90
106
|
}
|
|
91
107
|
displayErrorRow(link.closest('tr'));
|
|
92
108
|
return;
|
|
93
109
|
}
|
|
94
110
|
|
|
95
|
-
if (
|
|
96
|
-
displayDetailsRow(link.closest('tr'),
|
|
111
|
+
if (onSuccess != null) {
|
|
112
|
+
displayDetailsRow(link.closest('tr'), onSuccess(jsonObj, link));
|
|
97
113
|
}
|
|
98
114
|
|
|
99
115
|
onComplete();
|
|
100
116
|
},
|
|
101
117
|
() => {
|
|
102
|
-
if (
|
|
103
|
-
|
|
118
|
+
if (onError != null) {
|
|
119
|
+
onError(link);
|
|
104
120
|
return;
|
|
105
121
|
}
|
|
106
122
|
|
|
107
|
-
link.closest('tr').
|
|
123
|
+
link.closest('tr').insertAdjacentHTML('afterend', '<tr class="error"><td colspan="6" class="center">'+(labelErrorOccurred ?? 'Une erreur s\'est produite.')+'</td></tr>');
|
|
108
124
|
|
|
109
125
|
onComplete();
|
|
110
|
-
//window.location.replace(decodeURIComponent(urlRetour));
|
|
111
126
|
}
|
|
112
127
|
);
|
|
113
128
|
}
|
|
114
129
|
|
|
115
|
-
table.
|
|
116
|
-
|
|
117
|
-
setDisplayDetailsLink(
|
|
118
|
-
showPlusButton(
|
|
130
|
+
table.querySelectorAll('a.details_link').forEach((link) => {
|
|
131
|
+
link.classList.remove('hide');
|
|
132
|
+
setDisplayDetailsLink(link);
|
|
133
|
+
showPlusButton(link);
|
|
119
134
|
});
|
|
120
135
|
}
|
|
121
136
|
|
package/flash_message.js
CHANGED
|
@@ -14,14 +14,18 @@ class FlashMessage {
|
|
|
14
14
|
modal.modal('hide');
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
document.querySelectorAll('div.snackbar').forEach(el => el.remove());
|
|
18
|
+
const snackbar = document.createElement('div');
|
|
19
|
+
snackbar.className = 'snackbar ' + type;
|
|
20
|
+
if (null !== domId) {
|
|
21
|
+
snackbar.id = domId;
|
|
22
|
+
}
|
|
23
|
+
snackbar.innerHTML = message;
|
|
24
|
+
snackbar.classList.add('show');
|
|
25
|
+
document.querySelector('body').appendChild(snackbar);
|
|
22
26
|
|
|
23
27
|
setTimeout(function () {
|
|
24
|
-
|
|
28
|
+
document.querySelectorAll('div.snackbar').forEach(el => el.remove());
|
|
25
29
|
if (typeof onMessageHidden == 'function') {
|
|
26
30
|
onMessageHidden();
|
|
27
31
|
}
|