@osimatic/helpers-js 1.1.0 → 1.1.1

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.
@@ -88,7 +88,7 @@ class TelephoneNumber {
88
88
  const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode);
89
89
  return number != null ? number.formatInternational() : null;
90
90
  } catch (error) {
91
- console.log(error);
91
+ console.error(error);
92
92
  }
93
93
  return '';
94
94
  }
package/data_table.js CHANGED
@@ -158,7 +158,7 @@ class DataTable {
158
158
 
159
159
  }
160
160
 
161
- console.log('defaultFilters', defaultFilters);
161
+ //console.log('defaultFilters', defaultFilters);
162
162
 
163
163
  DataTable.setDefaultFilters(defaultFilters);
164
164
  DataTable.setCallbackOnLoadData(options.on_load_data);
@@ -335,7 +335,7 @@ class DataTable {
335
335
  DataTable.removeLoader(div);
336
336
  }
337
337
  catch (e) {
338
- console.log(e);
338
+ console.error(e);
339
339
  }
340
340
  }
341
341
 
package/google_maps.js CHANGED
@@ -40,7 +40,7 @@ class GoogleMap {
40
40
  }
41
41
 
42
42
  addMarkers(listLocation, icon) {
43
- console.log(listLocation);
43
+ //console.log(listLocation);
44
44
  if (listLocation.length == 0) {
45
45
  return;
46
46
  }
@@ -49,7 +49,7 @@ class GoogleRecaptcha {
49
49
  GoogleRecaptcha.grecaptchaWidgets[id] = grecaptcha.render(id, googleReCaptchaDatas);
50
50
  }
51
51
  catch (e) {
52
- console.log('Exception during grecaptcha.render', e);
52
+ console.error('Exception during grecaptcha.render', e);
53
53
  }
54
54
  }
55
55
  else {
package/http_client.js CHANGED
@@ -177,8 +177,6 @@ class HTTPClient {
177
177
  }
178
178
 
179
179
  static async request(method, url, data, successCallback, errorCallback, formErrorCallback) {
180
- method = method.toUpperCase();
181
-
182
180
  if (!window.fetch) {
183
181
  return;
184
182
  }
@@ -186,19 +184,17 @@ class HTTPClient {
186
184
  let body = null;
187
185
  method = method.toUpperCase();
188
186
 
189
- if ('POST' !== method && 'PATCH' !== method) {
190
- url += (!url.includes('?') ? '?' : '') + HTTPClient.formatQueryString(data);
191
- data = null;
192
- }
193
-
194
- if (method === 'PATCH') {
187
+ if ('PATCH' === method) {
195
188
  HTTPClient.setHeader('Content-Type', 'application/x-www-form-urlencoded');
196
189
  body = new URLSearchParams(HTTPClient.formatFormData(data)).toString();
197
190
  }
198
-
199
- if ('POST' === method) {
191
+ else if ('POST' === method) {
200
192
  body = HTTPClient.formatFormData(data);
201
193
  }
194
+ else {
195
+ url += (!url.includes('?') ? '?' : '') + HTTPClient.formatQueryString(data);
196
+ data = null;
197
+ }
202
198
 
203
199
  const requestOptions = {
204
200
  headers: HTTPClient.getHeaders(),
@@ -252,33 +248,46 @@ class HTTPClient {
252
248
  }
253
249
  }
254
250
 
255
- static async download(method, url, data, errorCallback, completeCallback) {
256
- method = typeof method == 'undefined' || null == method ? 'GET' : method;
257
-
258
- if ('GET' === method) {
259
- url += (!url.includes('?') ? '?' : '') + HTTPClient.formatQueryString(data);
260
- data = null;
261
- }
251
+ static download(method, url, data, errorCallback, completeCallback) {
252
+ HTTPClient.requestBlob(method, url, data,
253
+ (blobData, response) => File.download(blobData, response.headers.get('content-type'), response.headers.get('content-disposition')),
254
+ errorCallback,
255
+ completeCallback
256
+ );
257
+ }
262
258
 
259
+ static async requestBlob(method, url, data, successCallback, errorCallback, completeCallback) {
263
260
  if (!window.fetch) {
264
261
  return;
265
262
  }
266
263
 
267
- let requestOptions = {
264
+ let body = null;
265
+ method = method.toUpperCase();
266
+
267
+ if ('PATCH' === method) {
268
+ HTTPClient.setHeader('Content-Type', 'application/x-www-form-urlencoded');
269
+ body = new URLSearchParams(HTTPClient.formatFormData(data)).toString();
270
+ }
271
+ else if ('POST' === method) {
272
+ body = HTTPClient.formatFormData(data);
273
+ }
274
+ else {
275
+ url += (!url.includes('?') ? '?' : '') + HTTPClient.formatQueryString(data);
276
+ data = null;
277
+ }
278
+
279
+ const requestOptions = {
268
280
  method: method,
269
281
  headers: HTTPClient.getHeaders(),
282
+ body: body,
270
283
  mode: 'cors',
271
284
  cache: 'no-cache'
272
285
  }
273
286
 
274
- if ('GET' !== method) {
275
- requestOptions['body'] = HTTPClient.formatFormData(data);
276
- }
277
-
278
287
  const response = await fetch(url, requestOptions);
279
288
  try {
280
289
  if (response.status === 401 && response.statusText === 'Expired JWT Token') {
281
- HTTPClient.refreshToken(() => HTTPClient.download(method, url, data, errorCallback, completeCallback), errorCallback);
290
+ HTTPClient.refreshToken(() => HTTPClient.requestBlob(method, url, data, successCallback, errorCallback, completeCallback), errorCallback);
282
291
  return;
283
292
  }
284
293
 
@@ -289,7 +298,9 @@ class HTTPClient {
289
298
 
290
299
  if (response.ok) {
291
300
  const blobData = await response.blob();
292
- File.download(blobData, response.headers.get('content-type'), response.headers.get('content-disposition'));
301
+ if (typeof successCallback != 'undefined' && successCallback != null) {
302
+ successCallback(blobData, response);
303
+ }
293
304
  }
294
305
  else {
295
306
  HTTPClient.logRequestFailure(response, null);
@@ -42,7 +42,7 @@ class ImportFromCsv {
42
42
  },
43
43
  complete: function(results, file) {
44
44
  isFileParsed = true;
45
- console.log(file, results);
45
+ //console.log(file, results);
46
46
 
47
47
  if (false === CSV.checkFile(file.name, file.type)) {
48
48
  $('#form_import_upload div.errors').html(errorMessageFileNotValid).removeClass('hide');
@@ -63,7 +63,7 @@ class ImportFromCsv {
63
63
  error: function(err, file, inputElem, reason) {
64
64
  isFileParsed = true;
65
65
  formUpload.find('div.errors').html(errorMessageFileNotValid).removeClass('hide');
66
- console.log(err, file, reason);
66
+ console.error(err, file, reason);
67
67
  },
68
68
  complete: function() {
69
69
  if (!isFileParsed) {
@@ -82,7 +82,7 @@ class ImportFromCsv {
82
82
  divResult.find('table tr').removeClass('danger');
83
83
 
84
84
  let tabLink = ImportFromCsv.getTabLink(formMatching);
85
- console.log('tabLink', tabLink);
85
+ //console.log('tabLink', tabLink);
86
86
 
87
87
  if ($.isEmptyObject(tabLink)) {
88
88
  formMatching.find('div.errors').html(errorMessageImportSelectColumns).removeClass('hide');
@@ -91,12 +91,12 @@ class ImportFromCsv {
91
91
  }
92
92
 
93
93
  let dataToImport = ImportFromCsv.getDataToImport(divResult, tabLink);
94
- console.log('dataToImport', dataToImport);
94
+ //console.log('dataToImport', dataToImport);
95
95
 
96
96
  requestImportData(dataToImport,
97
97
  // fonction callback en cas d'erreur de formulaire
98
98
  (json) => {
99
- console.log(json);
99
+ //console.log(json);
100
100
  if (typeof json['import_list'] !== 'undefined') {
101
101
  formMatching.find('div.errors').html(json['import_list']).removeClass('hide');
102
102
  }
@@ -133,7 +133,7 @@ class ImportFromCsv {
133
133
  }
134
134
  }
135
135
  });
136
- console.log('lineData', lineData);
136
+ //console.log('lineData', lineData);
137
137
  importListWithFieldNames.push(lineData);
138
138
  });
139
139
  return importListWithFieldNames;
@@ -222,7 +222,7 @@ class ImportFromCsv {
222
222
  let resultError = errorMessageImportFailed;
223
223
  resultError += '<ul>';
224
224
  $.each(json, function(idx, errorData) {
225
- console.log(errorData);
225
+ console.error(errorData);
226
226
  divResult.find('table tr[data-line="'+errorData.line+'"]').addClass('danger');
227
227
 
228
228
  resultError += '<li>'+lineLabel.format(errorData.line)+'<ul>';
package/media.js CHANGED
@@ -66,8 +66,7 @@ class AudioMedia {
66
66
  request.send();
67
67
  }
68
68
  catch (e) {
69
- console.log(e);
70
- console.log('web audio api not supported');
69
+ console.error('web audio api not supported', e);
71
70
  }
72
71
  }
73
72
 
@@ -86,7 +85,7 @@ class AudioMedia {
86
85
 
87
86
  analyser.fftSize = 256;
88
87
  let bufferLength = analyser.frequencyBinCount;
89
- console.log(bufferLength);
88
+ //console.log(bufferLength);
90
89
  let dataArray = new Uint8Array(bufferLength);
91
90
 
92
91
  canvasCtx.clearRect(0, 0, canvasWidth, canvasHeight);
@@ -81,7 +81,7 @@ class OpenStreetMap {
81
81
 
82
82
  //marker.on('click', () => {
83
83
  marker.on('popupopen', () => {
84
- console.log('popupopen');
84
+ //console.log('popupopen');
85
85
  if (typeof options['on_click'] == 'function') {
86
86
  options['on_click']();
87
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"