@osimatic/helpers-js 1.0.71 → 1.0.74

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/date_time.js CHANGED
@@ -1,18 +1,79 @@
1
1
 
2
- class DateTime {
2
+ class DateTimeFormatter {
3
+ static getDateDigitalFormatter(locale, timeZone) {
4
+ if (this.dateDigitalFormatter == null) {
5
+ this.dateDigitalFormatter = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone });
6
+ }
7
+
8
+ return this.dateDigitalFormatter;
9
+ }
10
+
11
+ static getDateTextFormatter(locale, timeZone) {
12
+ if (this.dateTextFormatter == null) {
13
+ this.dateTextFormatter = new Intl.DateTimeFormat(locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone });
14
+ }
15
+
16
+ return this.dateTextFormatter;
17
+ }
18
+
19
+ static getDateTimeFormatter(locale, timeZone) {
20
+ if (this.dateTimeFormatter == null) {
21
+ this.dateTimeFormatter = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone });
22
+ }
23
+
24
+ return this.dateTimeFormatter;
25
+ }
26
+
27
+ static getDateSqlFormatter(timeZone) {
28
+ if (this.dateSqlFormatter == null) {
29
+ this.dateSqlFormatter = new Intl.DateTimeFormat('fr-CA', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: timeZone });
30
+ }
31
+
32
+ return this.dateSqlFormatter;
33
+ }
3
34
 
35
+ static getTimeSqlFormatter(timeZone) {
36
+ if (this.timeSqlFormatter == null) {
37
+ this.timeSqlFormatter = new Intl.DateTimeFormat('en-GB', { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false, timeZone: timeZone }); //hour12: false = 24h format
38
+ }
39
+
40
+ return this.timeSqlFormatter;
41
+ }
42
+
43
+ static getTimeFormatter(locale, timeZone) {
44
+ if (this.timeFormatter == null) {
45
+ this.timeFormatter = new Intl.DateTimeFormat(locale, { hour: 'numeric', minute: 'numeric', timeZone: timeZone });
46
+ }
47
+
48
+ return this.timeFormatter;
49
+ }
50
+
51
+ static getTimeDigitalFormatter(locale, timeZone) {
52
+ if (this.timeDigitalFormatter == null) {
53
+ this.timeDigitalFormatter = new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone });
54
+ }
55
+
56
+ return this.timeDigitalFormatter;
57
+ }
58
+ }
59
+
60
+ class DateTime {
4
61
  static getSqlDate(jsDate, timeZone="Europe/Paris") {
5
- let pad = function(num) { return ('00'+num).slice(-2) };
62
+ return DateTimeFormatter.getDateSqlFormatter(timeZone).format(jsDate).replace(/\//g,'-').replace(',','');
63
+ /*let pad = function(num) { return ('00'+num).slice(-2) };
6
64
  // return jsDate.getUTCFullYear() + '-' + pad(jsDate.getUTCMonth() + 1) + '-' + pad(jsDate.getUTCDate());
7
65
  //return jsDate.getFullYear() + '-' + pad(jsDate.getMonth() + 1) + '-' + pad(jsDate.getDate());
8
66
  return jsDate.toLocaleDateString('fr-FR', {year: 'numeric', timeZone: timeZone})+'-'+jsDate.toLocaleDateString('fr-FR', {month: '2-digit', timeZone: timeZone})+'-'+jsDate.toLocaleDateString('fr-FR', {day: '2-digit', timeZone: timeZone});
67
+ */
9
68
  }
10
69
 
11
70
  static getSqlTime(jsDate, timeZone="Europe/Paris") {
12
- let pad = function(num) { return ('00'+num).slice(-2) };
71
+ return DateTimeFormatter.getTimeSqlFormatter(timeZone).format(jsDate);
72
+ /*let pad = function(num) { return ('00'+num).slice(-2) };
13
73
  // return pad(jsDate.getUTCHours()) + ':' + pad(jsDate.getUTCMinutes()) + ':' + pad(jsDate.getUTCSeconds());
14
74
  //return pad(jsDate.getHours()) + ':' + pad(jsDate.getMinutes()) + ':' + pad(jsDate.getSeconds());
15
75
  return pad(jsDate.toLocaleTimeString('en-GB', {hour: 'numeric', timeZone: timeZone}))+':'+pad(jsDate.toLocaleTimeString('en-GB', {minute: 'numeric', timeZone: timeZone}))+':'+pad(jsDate.toLocaleTimeString('en-GB', {second: 'numeric', timeZone: timeZone}));
76
+ */
16
77
  }
17
78
 
18
79
  static getSqlDateTime(jsDate) {
@@ -24,18 +85,25 @@ class DateTime {
24
85
  }
25
86
 
26
87
  static getDateDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
27
- return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone});
88
+ return DateTimeFormatter.getDateDigitalFormatter(locale, timeZone).format(jsDate);
89
+ //return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone});
28
90
  }
91
+
29
92
  static getDateTextDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
30
- return jsDate.toLocaleDateString(locale, {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone});
93
+ return DateTimeFormatter.getDateTextFormatter(locale, timeZone).format(jsDate);
94
+ //return jsDate.toLocaleDateString(locale, {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone});
31
95
  }
32
96
 
33
97
  static getTimeDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
34
- return jsDate.toLocaleTimeString(locale, {hour: 'numeric', minute: 'numeric', timeZone: timeZone});
98
+ return DateTimeFormatter.getTimeFormatter(locale, timeZone).format(jsDate);
99
+ //return jsDate.toLocaleTimeString(locale, {hour: 'numeric', minute: 'numeric', timeZone: timeZone});
35
100
  }
101
+
36
102
  static getTimeDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
37
- return jsDate.toLocaleTimeString(locale, {hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone});
103
+ return DateTimeFormatter.getTimeDigitalFormatter(locale, timeZone).format(jsDate);
104
+ //return jsDate.toLocaleTimeString(locale, {hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone});
38
105
  }
106
+
39
107
  static getTimeDisplayWithNbDays(jsDate, jsPreviousDate, locale="fr-FR", timeZone="Europe/Paris") {
40
108
  let str = this.getTimeDisplay(jsDate, locale, timeZone);
41
109
  if (jsPreviousDate != 0 && jsPreviousDate != null) {
@@ -48,7 +116,8 @@ class DateTime {
48
116
  }
49
117
 
50
118
  static getDateTimeDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
51
- return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone});
119
+ return DateTimeFormatter.getDateTimeFormatter(locale, timeZone).format(jsDate);
120
+ //return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone});
52
121
  }
53
122
 
54
123
  static getYear(jsDate) {
package/form_helper.js CHANGED
@@ -200,11 +200,12 @@ class FormHelper {
200
200
  static displayFormErrors(form, btnSubmit, errors, errorWrapperDiv) {
201
201
  this.displayFormErrorsFromText(form, this.getFormErrorText(errors), errorWrapperDiv);
202
202
  if (btnSubmit != null) {
203
- if (btnSubmit.buttonLoader != null) {
204
- btnSubmit.buttonLoader('reset');
205
- } else {
206
- btnSubmit.attr('disabled', false).button('reset');
207
- }
203
+ FormHelper.buttonLoader(btnSubmit, 'reset');
204
+ //if (btnSubmit.buttonLoader != null) {
205
+ // btnSubmit.buttonLoader('reset');
206
+ //} else {
207
+ // btnSubmit.attr('disabled', false).button('reset');
208
+ //}
208
209
  }
209
210
  }
210
211
 
@@ -311,7 +312,7 @@ class EditValue {
311
312
 
312
313
  let button = $('<button type="submit" class="btn btn-success ms-2" data-loading-text="<i class=\'fa fa-circle-notch fa-spin\'></i>" style="vertical-align: baseline;"><i class="fas fa-check"></i></button>');
313
314
  button.click(function (e) {
314
- parent.find('button').buttonLoader('loading');
315
+ FormHelper.buttonLoader(parent.find('button'), 'loading');
315
316
  let newValue = parent.find('input').val();
316
317
  onSubmitCallback(newValue, parent,
317
318
  (isSuccess, valueFormatCallback) => {
@@ -24,7 +24,7 @@ class ImportFromCsv {
24
24
 
25
25
  formUpload.find('button[type="submit"]').click(function(event) {
26
26
  event.preventDefault();
27
- $(this).buttonLoader('loading');
27
+ FormHelper.buttonLoader($(this), 'loading');
28
28
  formUpload.find('div.errors').addClass('hide');
29
29
 
30
30
  let isFileParsed = false;
@@ -69,7 +69,7 @@ class ImportFromCsv {
69
69
  if (!isFileParsed) {
70
70
  formUpload.find('div.errors').html(errorMessageFileEmpty).removeClass('hide');
71
71
  }
72
- formUpload.find('button[type="submit"]').buttonLoader('reset');
72
+ FormHelper.buttonLoader(formUpload.find('button[type="submit"]'), 'reset');
73
73
  }
74
74
  });
75
75
  event.preventDefault();
@@ -77,7 +77,7 @@ class ImportFromCsv {
77
77
 
78
78
  formMatching.find('button[type="submit"]').click(function (event) {
79
79
  event.preventDefault();
80
- $(this).buttonLoader('loading');
80
+ FormHelper.buttonLoader($(this), 'loading');
81
81
  formMatching.find('div.errors').addClass('hide').empty();
82
82
  divResult.find('table tr').removeClass('danger');
83
83
 
@@ -86,7 +86,7 @@ class ImportFromCsv {
86
86
 
87
87
  if ($.isEmptyObject(tabLink)) {
88
88
  formMatching.find('div.errors').html(errorMessageImportSelectColumns).removeClass('hide');
89
- $(this).buttonLoader('reset');
89
+ FormHelper.buttonLoader($(this), 'reset');
90
90
  return false;
91
91
  }
92
92
 
@@ -103,7 +103,7 @@ class ImportFromCsv {
103
103
  else {
104
104
  formMatching.find('div.errors').html(ImportFromCsv.getErrorsHtmlOfImportData(json, divResult)).removeClass('hide');
105
105
  }
106
- formMatching.find('button[type="submit"]').buttonLoader('reset');
106
+ FormHelper.buttonLoader(formMatching.find('button[type="submit"]'), 'reset');
107
107
  }
108
108
  );
109
109
  });
package/media.js CHANGED
@@ -15,14 +15,13 @@ class AudioMedia {
15
15
  });
16
16
 
17
17
  div.find('.play_asynchronously_link').off('click').click(function () {
18
- if ($(this).buttonLoader('loading') != null) {
19
- let button = $(this).buttonLoader('loading');
20
- AudioMedia.playAudioUrl($(this).data('url'), () => button.buttonLoader('reset'));
21
- } else {
22
- let button = $(this).attr('disabled', true).button('loading');
23
- AudioMedia.playAudioUrl($(this).data('url'), () => button.attr('disabled', false).button('reset'));
24
- }
25
-
18
+ //if (FormHelper.buttonLoader($(this), 'loading') != null) {
19
+ let button = FormHelper.buttonLoader($(this), 'loading');
20
+ AudioMedia.playAudioUrl($(this).data('url'), () => FormHelper.buttonLoader(button, 'reset'));
21
+ //} else {
22
+ // let button = $(this).attr('disabled', true).button('loading');
23
+ // AudioMedia.playAudioUrl($(this).data('url'), () => button.attr('disabled', false).button('reset'));
24
+ //}
26
25
  return false;
27
26
  });
28
27
 
package/network.js CHANGED
@@ -227,16 +227,13 @@ class HTTPRequest {
227
227
 
228
228
  const response = await fetch(url, requestInit);
229
229
  try {
230
- const blobData = await response.blob();
231
- /*console.log(url);
232
- console.log(blobData);*/
233
-
234
230
  if (response.status === 401 && response.statusText === 'Expired JWT Token') {
235
231
  HTTPRequest.refreshToken(() => HTTPRequest.download(url, data, errorCallback, completeCallback, method), errorCallback);
236
232
  return;
237
233
  }
238
234
 
239
235
  if (response.ok) {
236
+ const blobData = await response.blob();
240
237
  File.download(blobData, response.headers.get('content-type'), response.headers.get('content-disposition'));
241
238
  }
242
239
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.0.71",
3
+ "version": "1.0.74",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"