@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.
@@ -1,6 +1,6 @@
1
1
 
2
2
  const libphonenumber = require('libphonenumber-js/max');
3
- const intlTelInput = require('intl-tel-input');
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 intlTelInput(input[0], {
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 intlTelInput.getInstance(input[0]);
185
+ return intlTelInputLib.getInstance(input[0]);
186
186
  }
187
187
 
188
188
  static getEnteredNumberInInternationalFormat(intlTelInput) {
189
- return intlTelInput.getNumber(intlTelInput.utils.numberFormat.E164);
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
- constructor(div, callbackOnRefreshData) {
4
- // console.log('constructor');
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
- this.div = div;
18
- this.callbackOnRefreshData = callbackOnRefreshData;
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
- this.alreadyMakingRequest = false;
21
- this.secondsBefRefresh = 10;
22
- this.refreshIntervalMillis = 60;
23
- this.currentMillis = 0;
24
- this.currentSecond = 0;
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
- this.refreshData();
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
- this.currentMillis += this.refreshIntervalMillis;
60
+ currentMillis += refreshIntervalMillis;
36
61
  }
37
62
  else {
38
- this.currentMillis = 0;
63
+ currentMillis = 0;
39
64
  }
40
65
 
41
- this.currentSecond = parseInt(this.currentMillis / 1000);
66
+ currentSecond = parseInt(currentMillis / 1000);
42
67
 
43
68
  //countDownRefresh();
44
69
  var divCountDownText;
45
70
  var divCountDownCurrentSizePx;
46
71
 
47
- if (this.currentSecond >= this.secondsBefRefresh) {
72
+ if (currentSecond >= secondsBefRefresh) {
48
73
  divCountDownCurrentSizePx = 120;
49
74
  divCountDownText = '0s';
50
75
  }
51
76
  else {
52
- divCountDownCurrentSizePx = Math.round((120/(this.secondsBefRefresh*1000)) * this.currentMillis);
53
- divCountDownText = (this.secondsBefRefresh-this.currentSecond) + 's';
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 (this.currentSecond >= this.secondsBefRefresh) {
64
- this.currentMillis = 0;
88
+ if (currentSecond >= secondsBefRefresh) {
89
+ currentMillis = 0;
65
90
  setTimeout(() => {
66
- this.refreshData();
91
+ refreshData();
67
92
  }, 100);
68
93
  }
69
- }, this.refreshIntervalMillis);
70
-
71
- this.refreshData();
72
- }
94
+ }, refreshIntervalMillis);
73
95
 
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
- }
96
+ refreshData();
99
97
  }
100
98
 
101
99
  }
package/date_time.js CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  require('./string');
3
2
 
4
3
  class DateTimeFormatter {
@@ -1,11 +1,22 @@
1
+ const { HTTPClient } = require('./http_client');
2
+
1
3
  class DetailsSubArray {
2
4
 
3
- static initDetailsLink(table, callbackOnDetailsActionRequestSuccess, callbackOnDetailsActionRequestError, callbackOnDetailsActionRequestBeforeSend) {
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)+'">'+(typeof labelErrorOccured != 'undefined' ? labelErrorOccured : 'Une erreur s’est produite.')+'</td></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 (typeof callbackOnDetailsActionRequestBeforeSend != 'undefined' && callbackOnDetailsActionRequestBeforeSend != null) {
71
- displayDetailsRow(link.closest('tr'), callbackOnDetailsActionRequestBeforeSend(link));
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 (typeof callbackOnDetailsActionRequestError != 'undefined' && callbackOnDetailsActionRequestError != null) {
88
- callbackOnDetailsActionRequestError(link);
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 (typeof callbackOnDetailsActionRequestSuccess != 'undefined' && callbackOnDetailsActionRequestSuccess != null) {
96
- displayDetailsRow(link.closest('tr'), callbackOnDetailsActionRequestSuccess(jsonObj, link));
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 (typeof callbackOnDetailsActionRequestError != 'undefined' && callbackOnDetailsActionRequestError != null) {
103
- callbackOnDetailsActionRequestError(link);
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">'+(typeof labelErrorOccured != 'undefined' ? labelErrorOccured : 'Une erreur s’est produite.')+'</td></tr>'));
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
- $('div.snackbar').remove();
18
- let snackbar = $('<div class="snackbar '+type+'" '+(null !== domId ? 'id="'+domId+'"' : '')+'></div>');
19
- $('html body').append(snackbar);
20
- snackbar.html(message);
21
- snackbar.addClass('show');
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
- $('div.snackbar').remove();
28
+ document.querySelectorAll('div.snackbar').forEach(el => el.remove());
25
29
  if (typeof onMessageHidden == 'function') {
26
30
  onMessageHidden();
27
31
  }