@osimatic/helpers-js 1.0.69 → 1.0.73

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
@@ -285,4 +285,49 @@ class FormHelper {
285
285
 
286
286
  }
287
287
 
288
- module.exports = { FormHelper };
288
+ class EditValue {
289
+ static init(valueDiv, onSubmitCallback, getInputCallback) {
290
+ let link = $('<a href="#" class="text-warning"><i class="fas fa-pencil-alt"></i></a>');
291
+ valueDiv.parent().append('&nbsp;').append(link);
292
+
293
+ function cancelEdit(valueParentDiv) {
294
+ valueParentDiv.find('a, span').removeClass('hide');
295
+ valueParentDiv.find('form').remove();
296
+ }
297
+
298
+ link.click(function (e) {
299
+ e.preventDefault();
300
+
301
+ let parent = $(this).parent();
302
+
303
+ parent.find('a, span').addClass('hide');
304
+
305
+ let form = $('<form class="form-inline"></form>');
306
+
307
+ let value = parent.find('span').data('value') || parent.find('span').text();
308
+ let input = $( typeof getInputCallback == 'function' ? getInputCallback(value) : '<input type="text" />');
309
+ form.append(input);
310
+ form.find('input').addClass('form-control').css('width', 'auto').val(value);
311
+
312
+ 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
+ button.click(function (e) {
314
+ parent.find('button').buttonLoader('loading');
315
+ let newValue = parent.find('input').val();
316
+ onSubmitCallback(newValue, parent,
317
+ (isSuccess, valueFormatCallback) => {
318
+ cancelEdit(parent);
319
+ if (isSuccess) {
320
+ parent.find('span').data('value', newValue).text(typeof valueFormatCallback == 'function' ? valueFormatCallback(newValue) : newValue);
321
+ }
322
+ }
323
+ );
324
+ });
325
+ form.append(button);
326
+
327
+ parent.append(form);
328
+ return false;
329
+ });
330
+ }
331
+ }
332
+
333
+ module.exports = { FormHelper, EditValue };
package/index.js CHANGED
@@ -14,7 +14,7 @@ const { PersonName, Email, TelephoneNumber } = require('./contact_details');
14
14
  const { DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime } = require('./date_time');
15
15
  const { Duration } = require('./duration');
16
16
  const { File, CSV, Img } = require('./file');
17
- const { FormHelper } = require('./form_helper');
17
+ const { FormHelper, EditValue } = require('./form_helper');
18
18
  const { Country, PostalAddress, GeographicCoordinates } = require('./location');
19
19
  const { SocialNetwork } = require('./social_network');
20
20
  const { sleep, refresh } = require('./util');
@@ -47,7 +47,7 @@ const { WebSocket } = require('./web_socket');
47
47
  module.exports = {
48
48
  Array, Object, Number, String,
49
49
  HTTPRequest, Cookie, UrlAndQueryString, IBAN, BankCard, AudioMedia, UserMedia, PersonName, Email, TelephoneNumber, DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, GeographicCoordinates, SocialNetwork,
50
- Browser, DataTable, Pagination, Navigation, DetailsSubArray, SelectAll, MultipleActionInTable, FormDate, InputPeriod, ShoppingCart, FlashMessage, CountDown, ImportFromCsv, JwtToken, JwtSession, ApiTokenSession, ListBox, WebRTC, WebSocket, EventBus,
50
+ Browser, DataTable, Pagination, Navigation, DetailsSubArray, SelectAll, MultipleActionInTable, EditValue, FormDate, InputPeriod, ShoppingCart, FlashMessage, CountDown, ImportFromCsv, JwtToken, JwtSession, ApiTokenSession, ListBox, WebRTC, WebSocket, EventBus,
51
51
  sleep, refresh, chr, ord, trim, empty,
52
52
  GoogleCharts, GoogleRecaptcha, GoogleMap, OpenStreetMap
53
53
  };
package/network.js CHANGED
@@ -154,7 +154,7 @@ class HTTPRequest {
154
154
  jsonData = await response.json();
155
155
 
156
156
  if (HTTPRequest.isExpiredToken(response, jsonData)) {
157
- HTTPRequest.refreshToken(() => HTTPRequest.get(url, data, successCallback, errorCallback));
157
+ HTTPRequest.refreshToken(() => HTTPRequest.get(url, data, successCallback, errorCallback), errorCallback);
158
158
  return;
159
159
  }
160
160
 
@@ -192,7 +192,7 @@ class HTTPRequest {
192
192
  },
193
193
  error: (jqxhr, status, errorThrown) => {
194
194
  if (HTTPRequest.isExpiredToken(jqxhr, jqxhr.responseJSON)) {
195
- HTTPRequest.refreshToken(() => HTTPRequest.get(url, data, successCallback, errorCallback));
195
+ HTTPRequest.refreshToken(() => HTTPRequest.get(url, data, successCallback, errorCallback), errorCallback);
196
196
  return;
197
197
  }
198
198
 
@@ -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
- HTTPRequest.refreshToken(() => HTTPRequest.download(url, data, errorCallback, completeCallback, method));
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 {
@@ -279,7 +276,7 @@ class HTTPRequest {
279
276
  success: (data, status, jqxhr) => File.download(data, jqxhr.getResponseHeader('Content-Type'), jqxhr.getResponseHeader('Content-Disposition')),
280
277
  error: (jqxhr, status, errorThrown) => {
281
278
  if (HTTPRequest.isExpiredToken(jqxhr, jqxhr.responseJSON)) {
282
- HTTPRequest.refreshToken(() => HTTPRequest.download(url, data, errorCallback, completeCallback, method));
279
+ HTTPRequest.refreshToken(() => HTTPRequest.download(url, data, errorCallback, completeCallback, method), errorCallback);
283
280
  return;
284
281
  }
285
282
 
@@ -316,7 +313,7 @@ class HTTPRequest {
316
313
  //console.log(url, jsonData);
317
314
 
318
315
  if (url !== HTTPRequest.refreshTokenUrl && HTTPRequest.isExpiredToken(response, jsonData)) {
319
- HTTPRequest.refreshToken(() => HTTPRequest.post(url, formData, successCallback, errorCallback, formErrorCallback));
316
+ HTTPRequest.refreshToken(() => HTTPRequest.post(url, formData, successCallback, errorCallback, formErrorCallback), errorCallback);
320
317
  return;
321
318
  }
322
319
 
@@ -364,7 +361,7 @@ class HTTPRequest {
364
361
  },
365
362
  error: (jqxhr, status, errorThrown) => {
366
363
  if (url !== HTTPRequest.refreshTokenUrl && HTTPRequest.isExpiredToken(jqxhr, jqxhr.responseJSON)) {
367
- HTTPRequest.refreshToken(() => HTTPRequest.post(url, formData, successCallback, errorCallback, formErrorCallback));
364
+ HTTPRequest.refreshToken(() => HTTPRequest.post(url, formData, successCallback, errorCallback, formErrorCallback), errorCallback);
368
365
  return;
369
366
  }
370
367
  if (jqxhr.status === 400 && typeof formErrorCallback != 'undefined' && formErrorCallback != null) {
@@ -380,7 +377,7 @@ class HTTPRequest {
380
377
  });
381
378
  }
382
379
 
383
- static refreshToken(onCompleteCallback) {
380
+ static refreshToken(onCompleteCallback, errorCallback) {
384
381
  if (typeof this.refreshTokenCallback == 'function') {
385
382
  this.refreshTokenCallback(onCompleteCallback);
386
383
  return;
@@ -405,6 +402,7 @@ class HTTPRequest {
405
402
  },
406
403
  () => {
407
404
  JwtSession.logout();
405
+ errorCallback();
408
406
  }
409
407
  );
410
408
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.0.69",
3
+ "version": "1.0.73",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$" />
5
- <orderEntry type="inheritedJdk" />
6
- <orderEntry type="sourceFolder" forTests="false" />
7
- </component>
8
- </module>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/helpers-js.iml" filepath="$PROJECT_DIR$/.idea/helpers-js.iml" />
6
- </modules>
7
- </component>
8
- </project>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>