@osimatic/helpers-js 1.0.60 → 1.0.63

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/CHANGELOG CHANGED
@@ -45,4 +45,7 @@ FormHelper.getFormErrorTextBis(...) -> FormHelper.getFormErrorText(...)
45
45
  FormHelper.displayFormErrorsFromXhr(form, btnSubmit, xhr) -> FormHelper.displayFormErrors(form, btnSubmit, xhr.responseJSON)
46
46
 
47
47
  1.0.35 :
48
- ajout méthode HTTPRequest.init() (charge le polyfill de fetch)
48
+ ajout méthode HTTPRequest.init() (charge le polyfill de fetch)
49
+
50
+ 1.0.61
51
+ DataTable.displayErrorFromXhr -> DataTable.displayError
package/data_table.js CHANGED
@@ -268,10 +268,6 @@ class DataTable {
268
268
  // }
269
269
  }
270
270
 
271
- static displayErrorFromXhr(div, jqxhr, defaultMessage) {
272
- this.displayError(div, JSON.parse(jqxhr.responseJSON), defaultMessage);
273
- }
274
-
275
271
  static displayError(div, data, defaultMessage) {
276
272
  var error = null;
277
273
  if (data != null) {
package/file.js CHANGED
@@ -111,7 +111,7 @@ class Img {
111
111
  // $(img).attr('src', urlCreator.createObjectURL(data));
112
112
  Img.setBlobToImg($(img), data);
113
113
  },
114
- error: (jqxhr, status, exception) => console.log('request failure. Status: '+status+'Exception: '+exception),
114
+ error: (jqxhr, status, errorThrown) => HTTPRequest.logJqueryRequestFailure(jqxhr, status, errorThrown),
115
115
  });
116
116
  }
117
117
 
@@ -95,13 +95,13 @@ class ImportFromCsv {
95
95
 
96
96
  requestImportData(dataToImport,
97
97
  // fonction callback en cas d'erreur de formulaire
98
- function (jqxhr) {
99
- console.log(jqxhr.responseJSON);
100
- if (typeof jqxhr.responseJSON['import_list'] !== 'undefined') {
101
- formMatching.find('div.errors').html(jqxhr.responseJSON['import_list']).removeClass('hide');
98
+ (json) => {
99
+ console.log(json);
100
+ if (typeof json['import_list'] !== 'undefined') {
101
+ formMatching.find('div.errors').html(json['import_list']).removeClass('hide');
102
102
  }
103
103
  else {
104
- formMatching.find('div.errors').html(ImportFromCsv.getErrorsHtmlOfImportData(jqxhr.responseJSON, divResult)).removeClass('hide');
104
+ formMatching.find('div.errors').html(ImportFromCsv.getErrorsHtmlOfImportData(json, divResult)).removeClass('hide');
105
105
  }
106
106
  formMatching.find('button[type="submit"]').buttonLoader('reset');
107
107
  }
package/network.js CHANGED
@@ -1,3 +1,4 @@
1
+ const { JwtSession } = require('@osimatic/helpers-js/jwt');
1
2
 
2
3
  class HTTPRequest {
3
4
  static init() {
@@ -138,10 +139,8 @@ class HTTPRequest {
138
139
  let jsonData = {};
139
140
  try {
140
141
  jsonData = await response.json();
141
- //console.log(url, jsonData);
142
- //console.log(response.status, response.statusText, jsonData['error']);
143
142
 
144
- if (response.status === 401 && (response.statusText === 'Expired JWT Token' || typeof jsonData['error'] != 'undefined' && jsonData['error'] === 'expired_token')) {
143
+ if (response.status === 401 && (response.statusText === 'Expired JWT Token' || (typeof jsonData['message'] != 'undefined' && jsonData['message'] === 'Expired JWT Token') || (typeof jsonData['error'] != 'undefined' && jsonData['error'] === 'expired_token'))) {
145
144
  HTTPRequest.refreshToken(() => HTTPRequest.get(url, data, successCallback, errorCallback));
146
145
  return;
147
146
  }
@@ -303,7 +302,7 @@ class HTTPRequest {
303
302
  }
304
303
  //console.log(url, jsonData);
305
304
 
306
- if (response.status === 401 && url !== HTTPRequest.refreshTokenUrl && (response.statusText === 'Expired JWT Token' || (typeof jsonData['error'] != 'undefined' && jsonData['error'] === 'expired_token'))) {
305
+ if (response.status === 401 && url !== HTTPRequest.refreshTokenUrl && (response.statusText === 'Expired JWT Token' || (typeof jqxhr.responseJSON['message'] != 'undefined' && jqxhr.responseJSON['message'] === 'Expired JWT Token') || (typeof jsonData['error'] != 'undefined' && jsonData['error'] === 'expired_token'))) {
307
306
  HTTPRequest.refreshToken(() => HTTPRequest.post(url, formData, successCallback, errorCallback, formErrorCallback));
308
307
  return;
309
308
  }
@@ -386,6 +385,9 @@ class HTTPRequest {
386
385
  (data) => {
387
386
  JwtSession.setToken(data.token);
388
387
  JwtSession.setRefreshToken(data.refresh_token);
388
+
389
+ HTTPRequest.setAuthorizationHeader(JwtSession.getToken());
390
+
389
391
  onCompleteCallback();
390
392
  },
391
393
  () => {
package/number.js CHANGED
@@ -1,10 +1,6 @@
1
1
 
2
2
  Number.prototype.format = Number.prototype.format || function(nbDecimal, locale) {
3
- nbDecimal = (typeof nbDecimal != 'undefined'?nbDecimal:2);
4
- return new Intl.NumberFormat(locale, {
5
- minimumFractionDigits: nbDecimal,
6
- maximumFractionDigits: nbDecimal
7
- }).format(this);
3
+ return Number.format(this, nbDecimal, locale);
8
4
  }
9
5
 
10
6
  if (!Number.format) {
@@ -32,32 +28,44 @@ Number.prototype.formatForDisplay = Number.prototype.formatForDisplay || functio
32
28
  };
33
29
 
34
30
  Number.prototype.formatCurrency = Number.prototype.formatCurrency || function(currency, nbDecimal, locale) {
31
+ return Number.formatCurrency(this, currency, nbDecimal, locale);
32
+ }
33
+ Number.formatCurrency = Number.formatCurrency || function(number, currency, nbDecimal, locale) {
35
34
  nbDecimal = (typeof nbDecimal != 'undefined'?nbDecimal:2);
36
35
  return new Intl.NumberFormat(locale, {
37
36
  style: 'currency',
38
37
  currency: currency,
39
38
  minimumFractionDigits: nbDecimal,
40
39
  maximumFractionDigits: nbDecimal
41
- }).format(this);
40
+ }).format(number);
42
41
  }
43
42
 
44
43
  Number.prototype.formatPercent = Number.prototype.formatPercent || function(nbDecimal, locale) {
44
+ return Number.formatPercent(this, nbDecimal, locale);
45
+ }
46
+ Number.formatPercent = Number.formatPercent || function(number, nbDecimal, locale) {
45
47
  nbDecimal = (typeof nbDecimal != 'undefined'?nbDecimal:2);
46
48
  return new Intl.NumberFormat(locale, {
47
49
  style: 'percent',
48
50
  minimumFractionDigits: nbDecimal,
49
51
  maximumFractionDigits: nbDecimal
50
- }).format(this);
52
+ }).format(number);
51
53
  }
52
54
 
53
- Number.prototype.padLeft2 = Number.prototype.padLeft2 || function(n) {
54
- return this > 9 ? "" + this : "0" + this;
55
+ Number.prototype.padLeft2 = Number.prototype.padLeft2 || function() {
56
+ return Number.padLeft2(this);
57
+ }
58
+ Number.padLeft2 = Number.padLeft2 || function(n) {
59
+ return n > 9 ? "" + n : "0" + n;
55
60
  }
56
61
 
57
62
  Number.prototype.roundDecimal = Number.prototype.roundDecimal || function(precision) {
63
+ return Number.roundDecimal(this, precision);
64
+ }
65
+ Number.roundDecimal = Number.roundDecimal || function(number, precision) {
58
66
  precision = precision || 2;
59
- var tmp = Math.pow(10, precision);
60
- return Math.round(this*tmp) / tmp;
67
+ let tmp = Math.pow(10, precision);
68
+ return Math.round(number*tmp) / tmp;
61
69
  }
62
70
 
63
71
  if (!Number.random) {
@@ -65,24 +73,3 @@ if (!Number.random) {
65
73
  return Math.floor(Math.random() * (max - min + 1)) + min;
66
74
  };
67
75
  }
68
-
69
- /** @deprecated */
70
- Number.prototype.formatAsString = function(locale, minimumFractionDigits) {
71
- minimumFractionDigits = (typeof minimumFractionDigits != 'undefined'?minimumFractionDigits:0);
72
- return new Intl.NumberFormat(locale, {minimumFractionDigits: minimumFractionDigits}).format(this);
73
- };
74
- /** @deprecated */
75
- Number.prototype.formatAsCurrency = function(locale, currency, nbFractionDigits) {
76
- nbFractionDigits = (typeof nbFractionDigits != 'undefined'?nbFractionDigits:2);
77
- return new Intl.NumberFormat(locale, {
78
- style: 'currency',
79
- currency: 'EUR',
80
- minimumFractionDigits: nbFractionDigits,
81
- maximumFractionDigits: nbFractionDigits
82
- }).format(this);
83
- };
84
- /** @deprecated */
85
- Number.prototype.formatAsPercent = function(locale, minimumFractionDigits) {
86
- minimumFractionDigits = (typeof minimumFractionDigits != 'undefined'?minimumFractionDigits:0);
87
- return new Intl.NumberFormat(locale, {style: 'percent', minimumFractionDigits:minimumFractionDigits}).format(this);
88
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.0.60",
3
+ "version": "1.0.63",
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>