@osimatic/helpers-js 1.1.77 → 1.2.0

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.
@@ -1,195 +1,199 @@
1
-
2
- class PersonName {
3
-
4
- static format(firstName, lastName) {
5
- let str = '';
6
- if (firstName != null && firstName !== '') {
7
- str += ' '+firstName;
8
- }
9
- if (lastName != null && lastName !== '') {
10
- str += ' '+lastName;
11
- }
12
- return str.trim();
13
- }
14
-
15
- static checkFirstName(firstName) {
16
- if (firstName.length < 2 || firstName.length > 64) {
17
- return false;
18
- }
19
-
20
- let regEx = /^([a-zA-Z'àâäéèêëìîïòôöùûüçÀÂÄÉÈÊËÌÎÏÒÔÖÙÛÜÇ\s-]+)$/;
21
- return regEx.exec(firstName) != null;
22
- }
23
-
24
- static checkLastName(lastName) {
25
- if (lastName.length < 2 || lastName.length > 64) {
26
- return false;
27
- }
28
-
29
- let regEx = /^([a-zA-Z'àâäéèêëìîïòôöùûüçÀÂÄÉÈÊËÌÎÏÒÔÖÙÛÜÇ\s-]+)$/;
30
- return regEx.exec(lastName) != null;
31
- }
32
- }
33
-
34
- class Email {
35
- static validateEmail(email) {
36
- let re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
37
- return re.test(email);
38
- }
39
-
40
- static checkEmail(email) {
41
- let regExEmail = /^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$/;
42
- return regExEmail.exec(email) != null;
43
- }
44
-
45
- static getMailToLink(email) {
46
- return '<a href="mailto:'+email+'">'+email+'</a>';
47
- }
48
- }
49
-
50
- class TelephoneNumber {
51
- //this class works with libphonenumber-max.min.js
52
-
53
- static setLocalCountryCode(countryCode) {
54
- TelephoneNumber.localCountryCode = countryCode;
55
- }
56
-
57
- static setIntlTelInputUtilsPath(path) {
58
- TelephoneNumber.intlTelInputUtilsPath = path;
59
- }
60
-
61
- static getCountryIsoCode(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
62
- try {
63
- const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
64
- return number != null ? number.country : null;
65
- } catch (error) {
66
- console.error(error);
67
- }
68
- return null;
69
- //return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase()).country || '';
70
- }
71
- static getCountryName(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
72
- return Country.getCountryName(this.getCountryIsoCode(phoneNumber, localCountryIsoCode));
73
- }
74
- static getFlagImg(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
75
- return Country.getFlagImg(this.getCountryIsoCode(phoneNumber, localCountryIsoCode));
76
- }
77
- static formatNational(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
78
- try {
79
- const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
80
- return number != null ? number.formatNational() : '';
81
- } catch (error) {
82
- console.error(error);
83
- }
84
- return '';
85
- //return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase()).formatNational();
86
- }
87
- static formatInternational(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
88
- try {
89
- const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
90
- return number != null ? number.formatInternational() : '';
91
- } catch (error) {
92
- console.error(error);
93
- }
94
- return '';
95
- //return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode).formatInternational();
96
- }
97
- static formatInternationalWithTelLink(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
98
- return '<a href="tel:'+phoneNumber+'">'+TelephoneNumber.formatInternational(phoneNumber, localCountryIsoCode)+'</a>';
99
- }
100
- static formatNationalWithFlagImg(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
101
- return TelephoneNumber.getFlagImg(phoneNumber, localCountryIsoCode)+'&nbsp;'+TelephoneNumber.formatNational(phoneNumber, localCountryIsoCode);
102
- }
103
- static formatNationalWithFlagImgAndTelLink(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
104
- return TelephoneNumber.getFlagImg(phoneNumber, localCountryIsoCode)+'&nbsp;<a href="tel:'+phoneNumber+'">'+TelephoneNumber.formatNational(phoneNumber, localCountryIsoCode)+'</a>';
105
- }
106
-
107
- static parse(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
108
- try {
109
- const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
110
- return number != null ? number.formatInternational() : null;
111
- } catch (error) {
112
- console.error(error);
113
- }
114
- return null;
115
- }
116
-
117
- static check(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
118
- try {
119
- const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
120
- return number != null ? number.isValid() : false;
121
- } catch (error) { }
122
- return false;
123
- //var numberObject = libphonenumber.parse(phoneNumber, localCountryIsoCode.toUpperCase());
124
- //return (typeof numberObject.country !== 'undefined');
125
- }
126
-
127
- static checkSyntaxe(phoneNumber) {
128
- let verifPhoneFr = /^(0)[1-9]{1}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}$/;
129
- let verifPhoneInt = /^((\+)|(00))[1-9]{1}[0-9]{0,3}([ \.\-\/]?[0-9]{1}){4,20}$/;
130
- if (verifPhoneFr.exec(phoneNumber) != null) {
131
- return true;
132
- }
133
- return verifPhoneInt.exec(phoneNumber) != null;
134
- }
135
-
136
- static getType(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
137
- if (phoneNumber == null || phoneNumber.length === 0) {
138
- return 'MASKED';
139
- }
140
-
141
- try {
142
- const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
143
- return number != null ? number.getType() : null;
144
- } catch (error) {
145
- console.error(error);
146
- }
147
- return null;
148
- }
149
-
150
- static getTypeLabelList() {
151
- return {
152
- FIXED_LINE: 'Fixe',
153
- MOBILE: 'Mobile',
154
- FIXED_LINE_OR_MOBILE: 'Fixe ou Mobile',
155
- TOLL_FREE: 'Vert',
156
- PREMIUM_RATE: 'Surtaxé',
157
- SHARED_COST: 'Coût partagé',
158
- VOIP: 'VOIP',
159
- PERSONAL_NUMBER: 'Personnel',
160
- PAGER: 'Pager',
161
- UAN: 'UAN',
162
- UNKNOWN: 'Inconnu',
163
- MASKED: 'Masqué',
164
- };
165
- }
166
-
167
- static getTypeLabel(phoneNumberType) {
168
- return TelephoneNumber.getTypeLabelList()[phoneNumberType] || 'Inconnu';
169
- }
170
-
171
- static setIntlTelInput(input, placeholderNumberType) {
172
- TelephoneNumber.localCountryCode = typeof TelephoneNumber.localCountryCode != 'undefined' ? TelephoneNumber.localCountryCode : null;
173
- TelephoneNumber.intlTelInputUtilsPath = typeof TelephoneNumber.intlTelInputUtilsPath != 'undefined' ? TelephoneNumber.intlTelInputUtilsPath : null;
174
-
175
- return window.intlTelInput(input[0], {
176
- initialCountry: null != TelephoneNumber.localCountryCode ? TelephoneNumber.localCountryCode.toLowerCase() : null, // depuis version 19.x, le code pays doit être en minuscule
177
- placeholderNumberType: placeholderNumberType || 'FIXED_LINE_OR_MOBILE',
178
- utilsScript: TelephoneNumber.intlTelInputUtilsPath
179
- });
180
- }
181
-
182
- static getEnteredNumberInInternationalFormat(intlTelInput) {
183
- return intlTelInput.getNumber(window.intlTelInput.utils.numberFormat.E164);
184
- }
185
-
186
- static formatNumberFromIntlTelInput(intlTelInput) {
187
- let number = intlTelInput.getNumber();
188
- if (number != '' && number.substr(0, 1) !== '+') {
189
- number = '+' + intlTelInput.getSelectedCountryData().dialCode + number;
190
- }
191
- return number;
192
- }
193
- }
194
-
1
+
2
+ class PersonName {
3
+
4
+ static format(firstName, lastName) {
5
+ let str = '';
6
+ if (firstName != null && firstName !== '') {
7
+ str += ' '+firstName;
8
+ }
9
+ if (lastName != null && lastName !== '') {
10
+ str += ' '+lastName;
11
+ }
12
+ return str.trim();
13
+ }
14
+
15
+ static checkFirstName(firstName) {
16
+ if (firstName.length < 2 || firstName.length > 64) {
17
+ return false;
18
+ }
19
+
20
+ let regEx = /^([a-zA-Z'àâäéèêëìîïòôöùûüçÀÂÄÉÈÊËÌÎÏÒÔÖÙÛÜÇ\s-]+)$/;
21
+ return regEx.exec(firstName) != null;
22
+ }
23
+
24
+ static checkLastName(lastName) {
25
+ if (lastName.length < 2 || lastName.length > 64) {
26
+ return false;
27
+ }
28
+
29
+ let regEx = /^([a-zA-Z'àâäéèêëìîïòôöùûüçÀÂÄÉÈÊËÌÎÏÒÔÖÙÛÜÇ\s-]+)$/;
30
+ return regEx.exec(lastName) != null;
31
+ }
32
+ }
33
+
34
+ class Email {
35
+ static validateEmail(email) {
36
+ let re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
37
+ return re.test(email);
38
+ }
39
+
40
+ static checkEmail(email) {
41
+ let regExEmail = /^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$/;
42
+ return regExEmail.exec(email) != null;
43
+ }
44
+
45
+ static getMailToLink(email) {
46
+ return '<a href="mailto:'+email+'">'+email+'</a>';
47
+ }
48
+ }
49
+
50
+ class TelephoneNumber {
51
+ //this class works with libphonenumber-max.min.js
52
+
53
+ static setLocalCountryCode(countryCode) {
54
+ TelephoneNumber.localCountryCode = countryCode;
55
+ }
56
+
57
+ static setIntlTelInputUtilsPath(path) {
58
+ TelephoneNumber.intlTelInputUtilsPath = path;
59
+ }
60
+
61
+ static getCountryIsoCode(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
62
+ try {
63
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
64
+ return number != null ? number.country : null;
65
+ } catch (error) {
66
+ console.error(error);
67
+ }
68
+ return null;
69
+ //return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase()).country || '';
70
+ }
71
+ static getCountryName(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
72
+ return Country.getCountryName(this.getCountryIsoCode(phoneNumber, localCountryIsoCode));
73
+ }
74
+ static getFlagImg(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
75
+ return Country.getFlagImg(this.getCountryIsoCode(phoneNumber, localCountryIsoCode));
76
+ }
77
+ static formatNational(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
78
+ try {
79
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
80
+ return number != null ? number.formatNational() : '';
81
+ } catch (error) {
82
+ console.error(error);
83
+ }
84
+ return '';
85
+ //return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase()).formatNational();
86
+ }
87
+ static formatInternational(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
88
+ try {
89
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
90
+ return number != null ? number.formatInternational() : '';
91
+ } catch (error) {
92
+ console.error(error);
93
+ }
94
+ return '';
95
+ //return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode).formatInternational();
96
+ }
97
+ static formatInternationalWithTelLink(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
98
+ return '<a href="tel:'+phoneNumber+'">'+TelephoneNumber.formatInternational(phoneNumber, localCountryIsoCode)+'</a>';
99
+ }
100
+ static formatNationalWithFlagImg(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
101
+ return TelephoneNumber.getFlagImg(phoneNumber, localCountryIsoCode)+'&nbsp;'+TelephoneNumber.formatNational(phoneNumber, localCountryIsoCode);
102
+ }
103
+ static formatNationalWithFlagImgAndTelLink(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
104
+ return TelephoneNumber.getFlagImg(phoneNumber, localCountryIsoCode)+'&nbsp;<a href="tel:'+phoneNumber+'">'+TelephoneNumber.formatNational(phoneNumber, localCountryIsoCode)+'</a>';
105
+ }
106
+
107
+ static parse(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
108
+ try {
109
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
110
+ return number != null ? number.formatInternational() : null;
111
+ } catch (error) {
112
+ console.error(error);
113
+ }
114
+ return null;
115
+ }
116
+
117
+ static check(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
118
+ try {
119
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
120
+ return number != null ? number.isValid() : false;
121
+ } catch (error) { }
122
+ return false;
123
+ //var numberObject = libphonenumber.parse(phoneNumber, localCountryIsoCode.toUpperCase());
124
+ //return (typeof numberObject.country !== 'undefined');
125
+ }
126
+
127
+ static checkSyntaxe(phoneNumber) {
128
+ let verifPhoneFr = /^(0)[1-9]{1}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}$/;
129
+ let verifPhoneInt = /^((\+)|(00))[1-9]{1}[0-9]{0,3}([ \.\-\/]?[0-9]{1}){4,20}$/;
130
+ if (verifPhoneFr.exec(phoneNumber) != null) {
131
+ return true;
132
+ }
133
+ return verifPhoneInt.exec(phoneNumber) != null;
134
+ }
135
+
136
+ static getType(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
137
+ if (phoneNumber == null || phoneNumber.length === 0) {
138
+ return 'MASKED';
139
+ }
140
+
141
+ try {
142
+ const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
143
+ return number != null ? number.getType() : null;
144
+ } catch (error) {
145
+ console.error(error);
146
+ }
147
+ return null;
148
+ }
149
+
150
+ static getTypeLabelList() {
151
+ return {
152
+ FIXED_LINE: 'Fixe',
153
+ MOBILE: 'Mobile',
154
+ FIXED_LINE_OR_MOBILE: 'Fixe ou Mobile',
155
+ TOLL_FREE: 'Vert',
156
+ PREMIUM_RATE: 'Surtaxé',
157
+ SHARED_COST: 'Coût partagé',
158
+ VOIP: 'VOIP',
159
+ PERSONAL_NUMBER: 'Personnel',
160
+ PAGER: 'Pager',
161
+ UAN: 'UAN',
162
+ UNKNOWN: 'Inconnu',
163
+ MASKED: 'Masqué',
164
+ };
165
+ }
166
+
167
+ static getTypeLabel(phoneNumberType) {
168
+ return TelephoneNumber.getTypeLabelList()[phoneNumberType] || 'Inconnu';
169
+ }
170
+
171
+ static setIntlTelInput(input, placeholderNumberType) {
172
+ TelephoneNumber.localCountryCode = typeof TelephoneNumber.localCountryCode != 'undefined' ? TelephoneNumber.localCountryCode : null;
173
+ TelephoneNumber.intlTelInputUtilsPath = typeof TelephoneNumber.intlTelInputUtilsPath != 'undefined' ? TelephoneNumber.intlTelInputUtilsPath : null;
174
+
175
+ return window.intlTelInput(input[0], {
176
+ initialCountry: null != TelephoneNumber.localCountryCode ? TelephoneNumber.localCountryCode.toLowerCase() : null, // depuis version 19.x, le code pays doit être en minuscule
177
+ placeholderNumberType: placeholderNumberType || 'FIXED_LINE_OR_MOBILE',
178
+ utilsScript: TelephoneNumber.intlTelInputUtilsPath
179
+ });
180
+ }
181
+
182
+ static getIntlTelInputInstance(input) {
183
+ return window.intlTelInput.getInstance(input[0]);
184
+ }
185
+
186
+ static getEnteredNumberInInternationalFormat(intlTelInput) {
187
+ return intlTelInput.getNumber(window.intlTelInput.utils.numberFormat.E164);
188
+ }
189
+
190
+ static formatNumberFromIntlTelInput(intlTelInput) {
191
+ let number = intlTelInput.getNumber();
192
+ if (number != '' && number.substr(0, 1) !== '+') {
193
+ number = '+' + intlTelInput.getSelectedCountryData().dialCode + number;
194
+ }
195
+ return number;
196
+ }
197
+ }
198
+
195
199
  module.exports = { PersonName, Email, TelephoneNumber };
package/count_down.js CHANGED
@@ -1,103 +1,103 @@
1
- class CountDown {
2
-
3
- constructor(div, callbackOnRefreshData) {
4
- // console.log('constructor');
5
- if (!div.length) {
6
- return;
7
- }
8
-
9
- div
10
- .append('<div class="count_down_title">'+labelNextUpdate+'</div>')
11
- .append('<div class="count_down_progress"><div class="count_down_current"></div></div>')
12
- .append('<div class="count_down_text"></div>')
13
- //.append('<div class="cl"></div>')
14
- .append('<div class="count_down_link"><a href="#" data-loading-text="<i class=\'fa fa-circle-notch fa-spin\'></i>">'+labelDoUpdate+'</a></div>')
15
- ;
16
-
17
- this.div = div;
18
- this.callbackOnRefreshData = callbackOnRefreshData;
19
-
20
- this.alreadyMakingRequest = false;
21
- this.secondsBefRefresh = 10;
22
- this.refreshIntervalMillis = 60;
23
- this.currentMillis = 0;
24
- this.currentSecond = 0;
25
-
26
- if (div.find('.count_down_link a').length) {
27
- div.find('.count_down_link a').click(() => {
28
- this.refreshData();
29
- return false;
30
- });
31
- }
32
-
33
- setInterval(() => {
34
- if (!div.find('.count_down_link a').length || !div.find('.count_down_link a').prop('disabled')) {
35
- this.currentMillis += this.refreshIntervalMillis;
36
- }
37
- else {
38
- this.currentMillis = 0;
39
- }
40
-
41
- this.currentSecond = parseInt(this.currentMillis / 1000);
42
-
43
- //countDownRefresh();
44
- var divCountDownText;
45
- var divCountDownCurrentSizePx;
46
-
47
- if (this.currentSecond >= this.secondsBefRefresh) {
48
- divCountDownCurrentSizePx = 120;
49
- divCountDownText = '0s';
50
- }
51
- else {
52
- divCountDownCurrentSizePx = Math.round((120/(this.secondsBefRefresh*1000)) * this.currentMillis);
53
- divCountDownText = (this.secondsBefRefresh-this.currentSecond) + 's';
54
- }
55
-
56
- if (div.find('.count_down_current').length) {
57
- div.find('.count_down_current').width(divCountDownCurrentSizePx);
58
- }
59
- if (div.find('.count_down_text').length) {
60
- div.find('.count_down_text').html(divCountDownText);
61
- }
62
-
63
- if (this.currentSecond >= this.secondsBefRefresh) {
64
- this.currentMillis = 0;
65
- setTimeout(() => {
66
- this.refreshData();
67
- }, 100);
68
- }
69
- }, this.refreshIntervalMillis);
70
-
71
- this.refreshData();
72
- }
73
-
74
- setCallbackOnRefreshData(callback) {
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
- }
99
- }
100
-
101
- }
102
-
1
+ class CountDown {
2
+
3
+ constructor(div, callbackOnRefreshData) {
4
+ // console.log('constructor');
5
+ if (!div.length) {
6
+ return;
7
+ }
8
+
9
+ div
10
+ .append('<div class="count_down_title">'+labelNextUpdate+'</div>')
11
+ .append('<div class="count_down_progress"><div class="count_down_current"></div></div>')
12
+ .append('<div class="count_down_text"></div>')
13
+ //.append('<div class="cl"></div>')
14
+ .append('<div class="count_down_link"><a href="#" data-loading-text="<i class=\'fa fa-circle-notch fa-spin\'></i>">'+labelDoUpdate+'</a></div>')
15
+ ;
16
+
17
+ this.div = div;
18
+ this.callbackOnRefreshData = callbackOnRefreshData;
19
+
20
+ this.alreadyMakingRequest = false;
21
+ this.secondsBefRefresh = 10;
22
+ this.refreshIntervalMillis = 60;
23
+ this.currentMillis = 0;
24
+ this.currentSecond = 0;
25
+
26
+ if (div.find('.count_down_link a').length) {
27
+ div.find('.count_down_link a').click(() => {
28
+ this.refreshData();
29
+ return false;
30
+ });
31
+ }
32
+
33
+ setInterval(() => {
34
+ if (!div.find('.count_down_link a').length || !div.find('.count_down_link a').prop('disabled')) {
35
+ this.currentMillis += this.refreshIntervalMillis;
36
+ }
37
+ else {
38
+ this.currentMillis = 0;
39
+ }
40
+
41
+ this.currentSecond = parseInt(this.currentMillis / 1000);
42
+
43
+ //countDownRefresh();
44
+ var divCountDownText;
45
+ var divCountDownCurrentSizePx;
46
+
47
+ if (this.currentSecond >= this.secondsBefRefresh) {
48
+ divCountDownCurrentSizePx = 120;
49
+ divCountDownText = '0s';
50
+ }
51
+ else {
52
+ divCountDownCurrentSizePx = Math.round((120/(this.secondsBefRefresh*1000)) * this.currentMillis);
53
+ divCountDownText = (this.secondsBefRefresh-this.currentSecond) + 's';
54
+ }
55
+
56
+ if (div.find('.count_down_current').length) {
57
+ div.find('.count_down_current').width(divCountDownCurrentSizePx);
58
+ }
59
+ if (div.find('.count_down_text').length) {
60
+ div.find('.count_down_text').html(divCountDownText);
61
+ }
62
+
63
+ if (this.currentSecond >= this.secondsBefRefresh) {
64
+ this.currentMillis = 0;
65
+ setTimeout(() => {
66
+ this.refreshData();
67
+ }, 100);
68
+ }
69
+ }, this.refreshIntervalMillis);
70
+
71
+ this.refreshData();
72
+ }
73
+
74
+ setCallbackOnRefreshData(callback) {
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
+ }
99
+ }
100
+
101
+ }
102
+
103
103
  module.exports = { CountDown };