@osimatic/helpers-js 1.5.1 → 1.5.3
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/contact_details.js +4 -4
- package/count_down.js +46 -48
- package/date_time.js +0 -1
- package/details_sub_array.js +22 -11
- package/flash_message.js +10 -6
- package/form_date.js +144 -153
- package/import_from_csv.js +34 -5
- package/multi_files_input.js +2 -1
- package/multiple_action_in_table.js +11 -7
- package/package.json +1 -1
- package/tests/contact_details.test.js +31 -0
- package/tests/count_down.test.js +131 -352
- package/tests/details_sub_array.test.js +11 -28
- package/tests/flash_message.test.js +21 -153
- package/tests/form_date.test.js +287 -961
- package/tests/import_from_csv.test.js +53 -11
- package/tests/multi_files_input.test.js +14 -16
- package/tests/multiple_action_in_table.test.js +0 -9
- package/tests/open_street_map.test.js +15 -23
package/contact_details.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
const libphonenumber = require('libphonenumber-js/max');
|
|
3
|
-
const
|
|
3
|
+
const intlTelInputLib = require('intl-tel-input/intlTelInputWithUtils');
|
|
4
4
|
const { Country } = require('./location');
|
|
5
5
|
|
|
6
6
|
class PersonName {
|
|
@@ -174,7 +174,7 @@ class TelephoneNumber {
|
|
|
174
174
|
TelephoneNumber.localCountryCode = typeof TelephoneNumber.localCountryCode != 'undefined' ? TelephoneNumber.localCountryCode : null;
|
|
175
175
|
TelephoneNumber.intlTelInputUtilsPath = typeof TelephoneNumber.intlTelInputUtilsPath != 'undefined' ? TelephoneNumber.intlTelInputUtilsPath : null;
|
|
176
176
|
|
|
177
|
-
return
|
|
177
|
+
return intlTelInputLib(input[0], {
|
|
178
178
|
initialCountry: null != TelephoneNumber.localCountryCode ? TelephoneNumber.localCountryCode.toLowerCase() : null, // depuis version 19.x, le code pays doit être en minuscule
|
|
179
179
|
placeholderNumberType: placeholderNumberType || 'FIXED_LINE_OR_MOBILE',
|
|
180
180
|
utilsScript: TelephoneNumber.intlTelInputUtilsPath
|
|
@@ -182,11 +182,11 @@ class TelephoneNumber {
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
static getIntlTelInputInstance(input) {
|
|
185
|
-
return
|
|
185
|
+
return intlTelInputLib.getInstance(input[0]);
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
static getEnteredNumberInInternationalFormat(intlTelInput) {
|
|
189
|
-
return intlTelInput.getNumber(
|
|
189
|
+
return intlTelInput.getNumber(intlTelInputLib.utils.numberFormat.E164);
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
static formatNumberFromIntlTelInput(intlTelInput) {
|
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,11 +1,22 @@
|
|
|
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
16
|
return tr.closest('table').find('thead tr').children().length;
|
|
6
17
|
}
|
|
7
18
|
function displayErrorRow(tr) {
|
|
8
|
-
tr.after($('<tr class="text-error"><td colspan="'+getNbColumns(tr)+'">'+
|
|
19
|
+
tr.after($('<tr class="text-error"><td colspan="'+getNbColumns(tr)+'">'+labelErrorOccurred+'</td></tr>'));
|
|
9
20
|
}
|
|
10
21
|
function displayDetailsRow(tr, content) {
|
|
11
22
|
var trContent = $(''
|
|
@@ -67,8 +78,8 @@ class DetailsSubArray {
|
|
|
67
78
|
function doDetailsActionRequest(link) {
|
|
68
79
|
displayLoading(link);
|
|
69
80
|
|
|
70
|
-
if (
|
|
71
|
-
displayDetailsRow(link.closest('tr'),
|
|
81
|
+
if (onBeforeSend != null) {
|
|
82
|
+
displayDetailsRow(link.closest('tr'), onBeforeSend(link));
|
|
72
83
|
hideLoading(link);
|
|
73
84
|
setHideDetailsLink(link);
|
|
74
85
|
return;
|
|
@@ -84,27 +95,27 @@ class DetailsSubArray {
|
|
|
84
95
|
HTTPClient.request('GET', link.data('url_details'), null,
|
|
85
96
|
(jsonObj) => {
|
|
86
97
|
if (jsonObj == null) {
|
|
87
|
-
if (
|
|
88
|
-
|
|
98
|
+
if (onError != null) {
|
|
99
|
+
onError(link);
|
|
89
100
|
return;
|
|
90
101
|
}
|
|
91
102
|
displayErrorRow(link.closest('tr'));
|
|
92
103
|
return;
|
|
93
104
|
}
|
|
94
105
|
|
|
95
|
-
if (
|
|
96
|
-
displayDetailsRow(link.closest('tr'),
|
|
106
|
+
if (onSuccess != null) {
|
|
107
|
+
displayDetailsRow(link.closest('tr'), onSuccess(jsonObj, link));
|
|
97
108
|
}
|
|
98
109
|
|
|
99
110
|
onComplete();
|
|
100
111
|
},
|
|
101
112
|
() => {
|
|
102
|
-
if (
|
|
103
|
-
|
|
113
|
+
if (onError != null) {
|
|
114
|
+
onError(link);
|
|
104
115
|
return;
|
|
105
116
|
}
|
|
106
117
|
|
|
107
|
-
link.closest('tr').after($('<tr class="error"><td colspan="6" class="center">'+(
|
|
118
|
+
link.closest('tr').after($('<tr class="error"><td colspan="6" class="center">'+(labelErrorOccurred ??'Une erreur s’est produite.')+'</td></tr>'));
|
|
108
119
|
|
|
109
120
|
onComplete();
|
|
110
121
|
//window.location.replace(decodeURIComponent(urlRetour));
|
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
|
}
|