@osimatic/helpers-js 1.0.68 → 1.0.72
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 +79 -8
- package/form_helper.js +46 -1
- package/index.js +2 -2
- package/media.js +1 -1
- package/network.js +9 -11
- package/package.json +1 -1
- package/.idea/helpers-js.iml +0 -8
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
package/date_time.js
CHANGED
|
@@ -1,18 +1,81 @@
|
|
|
1
1
|
|
|
2
|
-
class
|
|
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
|
+
}
|
|
3
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-FR', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: timeZone });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return this.dateSqlFormatter;
|
|
33
|
+
}
|
|
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
|
-
|
|
62
|
+
return DateTimeFormatter.getDateSqlFormatter(timeZone).format(jsDate).replace(/\//g,'-').replace(',','');
|
|
63
|
+
|
|
64
|
+
//24/08/22 bad perfs
|
|
65
|
+
/*let pad = function(num) { return ('00'+num).slice(-2) };
|
|
6
66
|
// return jsDate.getUTCFullYear() + '-' + pad(jsDate.getUTCMonth() + 1) + '-' + pad(jsDate.getUTCDate());
|
|
7
67
|
//return jsDate.getFullYear() + '-' + pad(jsDate.getMonth() + 1) + '-' + pad(jsDate.getDate());
|
|
8
68
|
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});
|
|
69
|
+
*/
|
|
9
70
|
}
|
|
10
71
|
|
|
11
72
|
static getSqlTime(jsDate, timeZone="Europe/Paris") {
|
|
12
|
-
|
|
73
|
+
return DateTimeFormatter.getTimeSqlFormatter(timeZone).format(jsDate);
|
|
74
|
+
/*let pad = function(num) { return ('00'+num).slice(-2) };
|
|
13
75
|
// return pad(jsDate.getUTCHours()) + ':' + pad(jsDate.getUTCMinutes()) + ':' + pad(jsDate.getUTCSeconds());
|
|
14
76
|
//return pad(jsDate.getHours()) + ':' + pad(jsDate.getMinutes()) + ':' + pad(jsDate.getSeconds());
|
|
15
77
|
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}));
|
|
78
|
+
*/
|
|
16
79
|
}
|
|
17
80
|
|
|
18
81
|
static getSqlDateTime(jsDate) {
|
|
@@ -24,18 +87,25 @@ class DateTime {
|
|
|
24
87
|
}
|
|
25
88
|
|
|
26
89
|
static getDateDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
27
|
-
return
|
|
90
|
+
return DateTimeFormatter.getDateDigitalFormatter(locale, timeZone).format(jsDate);
|
|
91
|
+
//return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone}); //24/08/22 bad perfs
|
|
28
92
|
}
|
|
93
|
+
|
|
29
94
|
static getDateTextDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
30
|
-
return
|
|
95
|
+
return DateTimeFormatter.getDateTextFormatter(locale, timeZone).format(jsDate);
|
|
96
|
+
//return jsDate.toLocaleDateString(locale, {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone}); //24/08/22 bad perfs
|
|
31
97
|
}
|
|
32
98
|
|
|
33
99
|
static getTimeDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
34
|
-
return
|
|
100
|
+
return DateTimeFormatter.getTimeFormatter(locale, timeZone).format(jsDate);
|
|
101
|
+
//return jsDate.toLocaleTimeString(locale, {hour: 'numeric', minute: 'numeric', timeZone: timeZone}); //24/08/22 bad perfs
|
|
35
102
|
}
|
|
103
|
+
|
|
36
104
|
static getTimeDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
37
|
-
return
|
|
105
|
+
return DateTimeFormatter.getTimeDigitalFormatter(locale, timeZone).format(jsDate);
|
|
106
|
+
//return jsDate.toLocaleTimeString(locale, {hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone}); //24/08/22 bad perfs
|
|
38
107
|
}
|
|
108
|
+
|
|
39
109
|
static getTimeDisplayWithNbDays(jsDate, jsPreviousDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
40
110
|
let str = this.getTimeDisplay(jsDate, locale, timeZone);
|
|
41
111
|
if (jsPreviousDate != 0 && jsPreviousDate != null) {
|
|
@@ -48,7 +118,8 @@ class DateTime {
|
|
|
48
118
|
}
|
|
49
119
|
|
|
50
120
|
static getDateTimeDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
51
|
-
return
|
|
121
|
+
return DateTimeFormatter.getDateTimeFormatter(locale, timeZone).format(jsDate);
|
|
122
|
+
//return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone}); //24/08/22 bad perfs
|
|
52
123
|
}
|
|
53
124
|
|
|
54
125
|
static getYear(jsDate) {
|
package/form_helper.js
CHANGED
|
@@ -285,4 +285,49 @@ class FormHelper {
|
|
|
285
285
|
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
-
|
|
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(' ').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/media.js
CHANGED
|
@@ -46,7 +46,7 @@ class AudioMedia {
|
|
|
46
46
|
let context = new (window.AudioContext || window.webkitAudioContext)();
|
|
47
47
|
let request = new XMLHttpRequest();
|
|
48
48
|
request.open("GET", url, true);
|
|
49
|
-
Object.entries(HTTPRequest.getHeaders()).forEach(([key, value]) => request.setRequestHeader(key, value));
|
|
49
|
+
Object.entries(HTTPRequest.getHeaders(true)).forEach(([key, value]) => request.setRequestHeader(key, value));
|
|
50
50
|
request.responseType = "arraybuffer";
|
|
51
51
|
|
|
52
52
|
request.onload = function () {
|
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
package/.idea/helpers-js.iml
DELETED
|
@@ -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>
|