@osimatic/helpers-js 1.0.30 → 1.0.33

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.txt CHANGED
@@ -37,4 +37,6 @@ let httpHeaders = {...} -> HTTPRequest.setHeader(key, value);
37
37
  remplacer l'utilisation des variables httpHeaders / _httpHeaders par HTTPRequest.getHeaders()
38
38
 
39
39
  FlashMessage.displayRequestFailure(status, exception, modal) -> FlashMessage.displayError(labelErrorOccured, modal)
40
- FormHelper.logRequestFailure(status, exception) -> HTTPRequest.logJqueryRequestFailure(jqxhr, status, exception) (le log de l'erreur est devenu inutile car fait de base dans la classe HTTPRequest)
40
+ FormHelper.logRequestFailure(status, exception) -> HTTPRequest.logJqueryRequestFailure(jqxhr, status, exception) (le log de l'erreur est devenu inutile car fait de base dans la classe HTTPRequest)
41
+
42
+ Location.checkCoordinates(...) -> GeographicCoordinates.check(...) (car Location est déjà défini en javascript natif)
package/data_table.js CHANGED
@@ -284,7 +284,7 @@ class DataTable {
284
284
  }
285
285
 
286
286
  if (error == null) {
287
- return this.displayErrorMessage(div, (typeof defaultMessage != 'undefined' ? defaultMessage : labelErrorOccured));
287
+ return this.displayErrorMessage(div, (typeof defaultMessage != 'undefined' ? defaultMessage : (typeof labelErrorOccured != 'undefined' ? labelErrorOccured : 'Une erreur s’est produite.')));
288
288
  }
289
289
  return this.displayErrorMessage(div, 'Critères sélectionnés incorrect.');
290
290
  }
@@ -5,7 +5,7 @@ class DetailsSubArray {
5
5
  return tr.closest('table').find('thead tr').children().length;
6
6
  }
7
7
  function displayErrorRow(tr) {
8
- tr.after($('<tr class="text-error"><td colspan="'+getNbColumns(tr)+'">'+labelErrorOccured+'</td></tr>'));
8
+ tr.after($('<tr class="text-error"><td colspan="'+getNbColumns(tr)+'">'+(typeof labelErrorOccured != 'undefined' ? labelErrorOccured : 'Une erreur s’est produite.')+'</td></tr>'));
9
9
  }
10
10
  function displayDetailsRow(tr, content) {
11
11
  var trContent = $(''
@@ -74,14 +74,15 @@ class DetailsSubArray {
74
74
  return;
75
75
  }
76
76
 
77
+ function onComplete() {
78
+ hideLoading(link);
79
+ setHideDetailsLink(link);
80
+ //link.attr('disabled', false).button('reset');
81
+ }
82
+
77
83
  //link.attr('disabled', true).button('loading');
78
- $.ajax({
79
- url: link.data("url_details"),
80
- method: 'GET',
81
- headers: HTTPRequest.getHeaders(),
82
- cache: false,
83
- dataType: 'json',
84
- success: function (jsonObj) {
84
+ HTTPRequest.get(link.data('url_details'), {},
85
+ (jsonObj) => {
85
86
  if (jsonObj == null) {
86
87
  if (typeof callbackOnDetailsActionRequestError != 'undefined' && callbackOnDetailsActionRequestError != null) {
87
88
  callbackOnDetailsActionRequestError(link);
@@ -94,24 +95,21 @@ class DetailsSubArray {
94
95
  if (typeof callbackOnDetailsActionRequestSuccess != 'undefined' && callbackOnDetailsActionRequestSuccess != null) {
95
96
  displayDetailsRow(link.closest('tr'), callbackOnDetailsActionRequestSuccess(jsonObj, link));
96
97
  }
97
- },
98
- error: function (jqxhr, status, exception) {
99
- console.log('Detail request failure. Status: '+status+' ; Exception: '+exception);
100
98
 
99
+ onComplete();
100
+ },
101
+ () => {
101
102
  if (typeof callbackOnDetailsActionRequestError != 'undefined' && callbackOnDetailsActionRequestError != null) {
102
103
  callbackOnDetailsActionRequestError(link);
103
104
  return;
104
105
  }
105
106
 
106
- link.closest('tr').after($('<tr class="error"><td colspan="6" class="center">'+labelErrorOccured+'</td></tr>'));
107
+ link.closest('tr').after($('<tr class="error"><td colspan="6" class="center">'+(typeof labelErrorOccured != 'undefined' ? labelErrorOccured : 'Une erreur s’est produite.')+'</td></tr>'));
108
+
109
+ onComplete();
107
110
  //window.location.replace(decodeURIComponent(urlRetour));
108
111
  },
109
- complete: function() {
110
- hideLoading(link);
111
- setHideDetailsLink(link);
112
- //link.attr('disabled', false).button('reset');
113
- }
114
- });
112
+ );
115
113
  }
116
114
 
117
115
  table.find('a.details_link').each(function(idx, link) {
package/file.js CHANGED
@@ -103,7 +103,7 @@ class Img {
103
103
  $.ajax({
104
104
  type: 'GET',
105
105
  url: url,
106
- headers: HTTPRequest.getHeaders(),
106
+ headers: HTTPRequest.getHeaders(true),
107
107
  cache: false,
108
108
  xhrFields: {responseType: 'blob'},
109
109
  success: (data) => {
package/flash_message.js CHANGED
@@ -31,9 +31,8 @@ class FlashMessage {
31
31
  /** @deprecated **/
32
32
  static displayRequestFailure(status, exception, modal) {
33
33
  console.log('request failure. Status: ', status, ' Exception: ', exception);
34
- this.display('danger', typeof labelErrorOccured != 'undefined' ? labelErrorOccured : "Une erreur s'est produite.", false, modal);
34
+ this.display('danger', typeof labelErrorOccured != 'undefined' ? labelErrorOccured : 'Une erreur sest produite.', false, modal);
35
35
  }
36
-
37
36
  }
38
37
 
39
38
  module.exports = { FlashMessage };
package/form_helper.js CHANGED
@@ -255,6 +255,37 @@ class FormHelper {
255
255
  }
256
256
 
257
257
 
258
+ static buttonLoader(button, action) {
259
+ button = $(button);
260
+ if (action === 'start' || action === 'loading') {
261
+ if (button.attr('disabled')) {
262
+ return self;
263
+ }
264
+ button.attr('disabled', true);
265
+ button.attr('data-btn-text', button.html());
266
+ //let text = '<span class="spinner"><i class=\'fa fa-circle-notch fa-spin\'></i></span>Traitement en cours…';
267
+ let text = '<i class=\'fa fa-circle-notch fa-spin\'></i> Traitement en cours…';
268
+ if (button.data('load-text') != undefined && button.data('load-text') != null && button.data('load-text') != '') {
269
+ text = button.data('load-text');
270
+ }
271
+ if (button.data('loading-text') != undefined && button.data('loading-text') != null && button.data('loading-text') != '') {
272
+ text = button.data('loading-text');
273
+ }
274
+ button.html(text);
275
+ button.addClass('disabled');
276
+ }
277
+ if (action === 'stop' || action === 'reset') {
278
+ button.html(button.attr('data-btn-text'));
279
+ button.removeClass('disabled');
280
+ button.attr('disabled', false);
281
+ //button.removeAttr("disabled");
282
+ }
283
+ return button;
284
+ }
285
+
286
+
287
+
288
+
258
289
 
259
290
  /** @deprecated **/
260
291
  static logRequestFailure(status, exception) {
package/index.js CHANGED
@@ -15,7 +15,7 @@ const { DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime } = require('./da
15
15
  const { Duration } = require('./duration');
16
16
  const { File, CSV, Img } = require('./file');
17
17
  const { FormHelper } = require('./form_helper');
18
- const { Country, PostalAddress, Location } = require('./location');
18
+ const { Country, PostalAddress, GeographicCoordinates } = require('./location');
19
19
  const { SocialNetwork } = require('./social_network');
20
20
  const { sleep, refresh } = require('./util');
21
21
  const { chr, ord, trim, empty } = require('./php.min');
@@ -40,11 +40,9 @@ const { GoogleRecaptcha } = require('./google_recaptcha');
40
40
  const { GoogleMap } = require('./google_maps');
41
41
  const { OpenStreetMap } = require('./open_street_map');
42
42
 
43
- // deprecated
44
-
45
43
  module.exports = {
46
44
  Array, Object, Number, String,
47
- HTTPRequest, Cookie, UrlAndQueryString, IBAN, BankCard, AudioMedia, UserMedia, PersonName, Email, TelephoneNumber, DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, Location, SocialNetwork,
45
+ HTTPRequest, Cookie, UrlAndQueryString, IBAN, BankCard, AudioMedia, UserMedia, PersonName, Email, TelephoneNumber, DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, GeographicCoordinates, SocialNetwork,
48
46
  DataTable, Pagination, Navigation, DetailsSubArray, SelectAll, MultipleActionInTable, FormDate, InputPeriod, ShoppingCart, FlashMessage, CountDown, ImportFromCsv, JwtToken, JwtSession, ListBox,
49
47
  sleep, refresh, chr, ord, trim, empty,
50
48
  GoogleCharts, GoogleRecaptcha, GoogleMap, OpenStreetMap
package/location.js CHANGED
@@ -8,19 +8,19 @@ class Country {
8
8
  }
9
9
 
10
10
  static fillCountrySelect(select, defaultValue) {
11
- Object.entries(Country.getCountryList()).forEach(([countryCode, countryName]) => select.append('<option value="'+countryCode+'">'+countryName+'</option>'));
11
+ Object.entries(Country.getCountries()).forEach(([countryCode, countryName]) => select.append('<option value="'+countryCode+'">'+countryName+'</option>'));
12
12
  if (typeof defaultValue != 'undefined') {
13
13
  select.val(defaultValue);
14
14
  }
15
15
  select.selectpicker('refresh');
16
16
  }
17
17
  static getCountryName(countryCode) {
18
- if (Country.getCountryList().hasOwnProperty(countryCode)) {
19
- return Country.getCountryList()[countryCode];
18
+ if (Country.getCountries().hasOwnProperty(countryCode)) {
19
+ return Country.getCountries()[countryCode];
20
20
  }
21
21
  return countryCode;
22
22
  }
23
- static getCountryList() {
23
+ static getCountries() {
24
24
  return {
25
25
  AF:'Afghanistan',
26
26
  AX:'Åland Islands',
@@ -268,6 +268,23 @@ class Country {
268
268
  ZW:'Zimbabwe',
269
269
  };
270
270
  }
271
+
272
+ static getContinents() {
273
+ return {
274
+ 1: "Europe",
275
+ 2: "Moyen-Orient",
276
+ 3: "Afrique",
277
+ 4: "Amérique du Nord",
278
+ 5: "Amérique du Sud",
279
+ 6: "Asie",
280
+ 7: "Océanie",
281
+ };
282
+ }
283
+
284
+ /** @deprecated **/
285
+ static getCountryList() {
286
+ return Country.getCountries();
287
+ }
271
288
  }
272
289
 
273
290
  class PostalAddress {
@@ -377,10 +394,10 @@ class PostalAddress {
377
394
  }
378
395
  }
379
396
 
380
- class Location {
381
- static checkCoordinates(str) {
397
+ class GeographicCoordinates {
398
+ static check(str) {
382
399
  return /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/.test(str);
383
400
  }
384
401
  }
385
402
 
386
- module.exports = { Country, PostalAddress, Location };
403
+ module.exports = { Country, PostalAddress, GeographicCoordinates };
package/media.js CHANGED
@@ -72,6 +72,49 @@ class AudioMedia {
72
72
  }
73
73
  }
74
74
 
75
+ static initAudioVisualization(canvas, audioStream) {
76
+ let canvasCtx = canvas.getContext("2d");
77
+ let canvasWidth = canvas.width;
78
+ let canvasHeight = canvas.height;
79
+ let audioCtx = new (window.AudioContext || window.webkitAudioContext)();
80
+ let analyser = audioCtx.createAnalyser();
81
+
82
+ let distortion = audioCtx.createWaveShaper();
83
+ let source = audioCtx.createMediaStreamSource(audioStream);
84
+ source.connect(analyser);
85
+ analyser.connect(distortion);
86
+ distortion.connect(audioCtx.destination);
87
+
88
+ analyser.fftSize = 256;
89
+ let bufferLength = analyser.frequencyBinCount;
90
+ console.log(bufferLength);
91
+ let dataArray = new Uint8Array(bufferLength);
92
+
93
+ canvasCtx.clearRect(0, 0, canvasWidth, canvasHeight);
94
+
95
+ function draw() {
96
+ let drawVisual = requestAnimationFrame(draw);
97
+
98
+ analyser.getByteFrequencyData(dataArray);
99
+
100
+ canvasCtx.fillStyle = 'rgb(0, 0, 0)';
101
+ canvasCtx.fillRect(0, 0, canvasWidth, canvasHeight);
102
+
103
+ let barWidth = (canvasWidth / bufferLength) * 2.5;
104
+ let barHeight;
105
+ let x = 0;
106
+ for (let i = 0; i < bufferLength; i++) {
107
+ barHeight = dataArray[i] / 2;
108
+
109
+ canvasCtx.fillStyle = 'rgb(' + (barHeight + 100) + ',50,50)';
110
+ canvasCtx.fillRect(x, canvasHeight - barHeight / 2, barWidth, barHeight);
111
+
112
+ x += barWidth + 1;
113
+ }
114
+ }
115
+
116
+ draw();
117
+ }
75
118
  }
76
119
 
77
120
  //Source : https://www.npmjs.com/package/mic-check
package/network.js CHANGED
@@ -14,7 +14,7 @@ class HTTPRequest {
14
14
  this.headers[key] = value;
15
15
  }
16
16
 
17
- static getHeaders() {
17
+ static getHeaders(asObject) {
18
18
  //if (typeof httpHeaders != 'undefined') {
19
19
  // return httpHeaders;
20
20
  //}
@@ -23,6 +23,10 @@ class HTTPRequest {
23
23
  this.headers = {};
24
24
  }
25
25
 
26
+ if (typeof asObject != 'undefined' && asObject) {
27
+ return this.headers;
28
+ }
29
+
26
30
  let httpHeaders = new Headers();
27
31
  Object.entries(this.headers).forEach(([key, value]) => {
28
32
  httpHeaders.append(key, value);
@@ -108,7 +112,7 @@ class HTTPRequest {
108
112
  $.ajax({
109
113
  type: 'GET',
110
114
  url: url,
111
- headers: HTTPRequest.getHeaders(),
115
+ headers: HTTPRequest.getHeaders(true),
112
116
  dataType: 'json',
113
117
  cache: false,
114
118
  success: (data) => successCallback(data),
@@ -187,7 +191,7 @@ class HTTPRequest {
187
191
  let ajaxOptions = {
188
192
  type: 'GET',
189
193
  url: url,
190
- headers: HTTPRequest.getHeaders(),
194
+ headers: HTTPRequest.getHeaders(true),
191
195
  cache: false,
192
196
  xhrFields: {
193
197
  responseType: 'blob'
@@ -238,7 +242,7 @@ class HTTPRequest {
238
242
  jsonData = await response.json();
239
243
  //console.log(url, jsonData);
240
244
 
241
- if (response.status == 401 && (response.statusText === "Expired JWT Token" || (typeof jsonData['error'] != 'undefined' && jsonData['error'] === 'expired_token'))) {
245
+ if (response.status == 401 && url !== HTTPRequest.refreshTokenUrl && (response.statusText === "Expired JWT Token" || (typeof jsonData['error'] != 'undefined' && jsonData['error'] === 'expired_token'))) {
242
246
  HTTPRequest.refreshToken(() => HTTPRequest.post(url, formData, successCallback, errorCallback, formErrorCallback));
243
247
  return;
244
248
  }
@@ -275,7 +279,7 @@ class HTTPRequest {
275
279
  $.ajax({
276
280
  type: 'POST',
277
281
  url: url,
278
- headers: HTTPRequest.getHeaders(),
282
+ headers: HTTPRequest.getHeaders(true),
279
283
  dataType: 'json', // 22/09/2020 : à voir si cette ligne pose pb (utilisé pour requete import et peut être d'autres
280
284
  data: formData,
281
285
  cache: false,
@@ -287,7 +291,7 @@ class HTTPRequest {
287
291
  }
288
292
  },
289
293
  error: (jqxhr, status, errorThrown) => {
290
- if (typeof jqxhr.responseJSON != 'undefined' && jqxhr.responseJSON.code == 401 && (jqxhr.responseJSON.message === "Expired JWT Token" || (typeof jqxhr.responseJSON['error'] != 'undefined' && jqxhr.responseJSON['error'] === 'expired_token' ))) {
294
+ if (typeof jqxhr.responseJSON != 'undefined' && jqxhr.responseJSON.code == 401 && url !== HTTPRequest.refreshTokenUrl && (jqxhr.responseJSON.message === "Expired JWT Token" || (typeof jqxhr.responseJSON['error'] != 'undefined' && jqxhr.responseJSON['error'] === 'expired_token' ))) {
291
295
  HTTPRequest.refreshToken(() => HTTPRequest.post(url, formData, successCallback, errorCallback, formErrorCallback));
292
296
  return;
293
297
  }
@@ -324,8 +328,7 @@ class HTTPRequest {
324
328
  JwtSession.setRefreshToken(data.refresh_token);
325
329
  onCompleteCallback();
326
330
  },
327
- (jqxhr, status, exception) => {
328
- console.log(exception);
331
+ () => {
329
332
  JwtSession.logout();
330
333
  }
331
334
  );
@@ -351,11 +354,12 @@ class HTTPRequest {
351
354
 
352
355
  xhr.onreadystatechange = function () {
353
356
  if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
357
+ let data;
354
358
  if (formatRetour == 'xml') {
355
- var data = xhr.responseXML;
359
+ data = xhr.responseXML;
356
360
  }
357
361
  else {
358
- var data = eval('(' + xhr.responseText + ')');
362
+ data = eval('(' + xhr.responseText + ')');
359
363
  }
360
364
  callback(data);
361
365
  }
@@ -597,6 +601,7 @@ class UrlAndQueryString {
597
601
 
598
602
  // deprecated
599
603
 
604
+ /** @deprecated **/
600
605
  static parseQueryString(string) {
601
606
  if (string === "" || string == null) return {};
602
607
  if (string.charAt(0) === "?") string = string.slice(1);
@@ -636,6 +641,7 @@ class UrlAndQueryString {
636
641
  return data0;
637
642
  }
638
643
 
644
+ /** @deprecated **/
639
645
  static getQuery(url) {
640
646
  var str = url;
641
647
  var strpos = str.indexOf('?');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.0.30",
3
+ "version": "1.0.33",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1,50 +0,0 @@
1
-
2
- // Loading button plugin (removed from BS4)
3
- (function($) {
4
- "use strict";
5
-
6
- $.fn.extend({
7
- /*
8
- button: function (action) {
9
- console.log(action);
10
- if (action === 'loading' && this.data('loading-text')) {
11
- console.log('loading');
12
- this.data('original-text', this.html()).html(this.data('loading-text')).prop('disabled', true);
13
- }
14
- if (action === 'reset' && this.data('original-text')) {
15
- console.log('reset');
16
- this.html(this.data('original-text')).prop('disabled', false);
17
- }
18
- },
19
- */
20
-
21
- buttonLoader: function (action) {
22
- //console.log(action);
23
- var self = $(this);
24
- if (action === 'start' || action === 'loading') {
25
- if ($(self).attr('disabled')) {
26
- return self;
27
- }
28
- $(self).attr('disabled', true);
29
- $(self).attr('data-btn-text', $(self).html());
30
- //let text = '<span class="spinner"><i class=\'fa fa-circle-notch fa-spin\'></i></span>Traitement en cours…';
31
- let text = '<i class=\'fa fa-circle-notch fa-spin\'></i> Traitement en cours…';
32
- if ($(self).data('load-text') != undefined && $(self).data('load-text') != null && $(self).data('load-text') != '') {
33
- text = $(self).data('load-text');
34
- }
35
- if ($(self).data('loading-text') != undefined && $(self).data('loading-text') != null && $(self).data('loading-text') != '') {
36
- text = $(self).data('loading-text');
37
- }
38
- $(self).html(text);
39
- $(self).addClass('disabled');
40
- }
41
- if (action === 'stop' || action === 'reset') {
42
- $(self).html($(self).attr('data-btn-text'));
43
- $(self).removeClass('disabled');
44
- $(self).attr('disabled', false);
45
- //$(self).removeAttr("disabled");
46
- }
47
- return self;
48
- }
49
- });
50
- }(jQuery));