@osimatic/helpers-js 1.0.710 → 1.1.0

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
@@ -48,4 +48,15 @@ FormHelper.displayFormErrorsFromXhr(form, btnSubmit, xhr) -> FormHelper.displayF
48
48
  ajout méthode HTTPRequest.init() (charge le polyfill de fetch)
49
49
 
50
50
  1.0.61
51
- DataTable.displayErrorFromXhr -> DataTable.displayError
51
+ DataTable.displayErrorFromXhr -> DataTable.displayError
52
+
53
+ 1.0.96
54
+ var intlTelInputUtilsPath = 'xxx'; -> TelephoneNumber.setIntlTelInputUtilsPath('xxx');
55
+
56
+ 1.0.99
57
+ JwtSession.isSimulationConnexion() -> JwtSession.simulateLogin() (fonctionnement différent)
58
+ JwtSession.cancelSimulationConnexion() -> JwtSession.cancelSimulatedLogin() (fonctionnement différent)
59
+ HTTPRequest -> HTTPClient
60
+
61
+ 1.0.106
62
+ UrlAndQueryString.getPath() -> UrlAndQueryString.getHostAndPath()
@@ -2,7 +2,7 @@
2
2
  class PersonName {
3
3
 
4
4
  static format(firstName, lastName) {
5
- var str = '';
5
+ let str = '';
6
6
  if (firstName != null && firstName != '') {
7
7
  str += ' '+firstName;
8
8
  }
@@ -17,12 +17,8 @@ class PersonName {
17
17
  return false;
18
18
  }
19
19
 
20
- var regEx = /^([a-zA-Z'àâäéèêëìîïòôöùûüçÀÂÄÉÈÊËÌÎÏÒÔÖÙÛÜÇ\s-]+)$/;
21
- if (regEx.exec(firstName) == null) {
22
- return false;
23
- }
24
-
25
- return true;
20
+ let regEx = /^([a-zA-Z'àâäéèêëìîïòôöùûüçÀÂÄÉÈÊËÌÎÏÒÔÖÙÛÜÇ\s-]+)$/;
21
+ return regEx.exec(firstName) != null;
26
22
  }
27
23
 
28
24
  static checkLastName(lastName) {
@@ -30,30 +26,34 @@ class PersonName {
30
26
  return false;
31
27
  }
32
28
 
33
- var regEx = /^([a-zA-Z'àâäéèêëìîïòôöùûüçÀÂÄÉÈÊËÌÎÏÒÔÖÙÛÜÇ\s-]+)$/;
34
- if (regEx.exec(lastName) == null) {
35
- return false;
36
- }
37
-
38
- return true;
29
+ let regEx = /^([a-zA-Z'àâäéèêëìîïòôöùûüçÀÂÄÉÈÊËÌÎÏÒÔÖÙÛÜÇ\s-]+)$/;
30
+ return regEx.exec(lastName) != null;
39
31
  }
40
32
  }
41
33
 
42
34
  class Email {
43
35
  static validateEmail(email) {
44
- var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
36
+ let re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
45
37
  return re.test(email);
46
38
  }
47
39
 
48
40
  static checkEmail(email) {
49
- var regExEmail = /^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$/;
50
- return (regExEmail.exec(email) != null);
41
+ let regExEmail = /^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$/;
42
+ return regExEmail.exec(email) != null;
43
+ }
44
+
45
+ static getMailToLink(email) {
46
+ return '<a href="mailto:'+email+'">'+email+'</a>';
51
47
  }
52
48
  }
53
49
 
54
50
  class TelephoneNumber {
55
51
  //this class works with libphonenumber-max.min.js
56
-
52
+
53
+ static setIntlTelInputUtilsPath(path) {
54
+ TelephoneNumber.intlTelInputUtilsPath = path;
55
+ }
56
+
57
57
  static getCountryIsoCode(phoneNumber, localCountryIsoCode) {
58
58
  localCountryIsoCode = (typeof localCountryIsoCode != 'undefined' ? localCountryIsoCode.toUpperCase() : serviceCountry);
59
59
  return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode).country || '';
@@ -72,11 +72,14 @@ class TelephoneNumber {
72
72
  localCountryIsoCode = (typeof localCountryIsoCode != 'undefined' ? localCountryIsoCode.toUpperCase() : serviceCountry);
73
73
  return libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode).formatInternational();
74
74
  }
75
+ static formatInternationalWithTelLink(phoneNumber, localCountryIsoCode) {
76
+ return '<a href="tel:'+phoneNumber+'">'+TelephoneNumber.formatInternational(phoneNumber, localCountryIsoCode)+'</a>';
77
+ }
75
78
  static formatNationalWithFlagImg(phoneNumber, localCountryIsoCode) {
76
- return TelephoneNumber.getFlagImg(phoneNumber, localCountryIsoCode)+'&nbsp;'+TelephoneNumber.formatNational(phoneNumber);
79
+ return TelephoneNumber.getFlagImg(phoneNumber, localCountryIsoCode)+'&nbsp;'+TelephoneNumber.formatNational(phoneNumber, localCountryIsoCode);
77
80
  }
78
81
  static formatNationalWithFlagImgAndTelLink(phoneNumber, localCountryIsoCode) {
79
- return TelephoneNumber.getFlagImg(phoneNumber, localCountryIsoCode)+'&nbsp;<a href="tel:'+phoneNumber+'">'+TelephoneNumber.formatNational(phoneNumber)+'</a>';
82
+ return TelephoneNumber.getFlagImg(phoneNumber, localCountryIsoCode)+'&nbsp;<a href="tel:'+phoneNumber+'">'+TelephoneNumber.formatNational(phoneNumber, localCountryIsoCode)+'</a>';
80
83
  }
81
84
 
82
85
  static parse(phoneNumber, localCountryIsoCode) {
@@ -99,19 +102,12 @@ class TelephoneNumber {
99
102
  }
100
103
 
101
104
  static checkSyntaxe(phoneNumber) {
102
- var verifPhoneFr = /^(0)[1-9]{1}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}$/;
103
- var verifPhoneInt = /^((\+)|(00))[1-9]{1}[0-9]{0,3}([ \.\-\/]?[0-9]{1}){4,20}$/;
104
- // var verifPhoneInt = /^((\+)|(00))([ \.\-\/]?[0-9]{1}){6-20}$/;
105
- //var verifPhone = /^[0-9+() .-]{6,32}$/;
105
+ let verifPhoneFr = /^(0)[1-9]{1}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}$/;
106
+ let verifPhoneInt = /^((\+)|(00))[1-9]{1}[0-9]{0,3}([ \.\-\/]?[0-9]{1}){4,20}$/;
106
107
  if (verifPhoneFr.exec(phoneNumber) != null) {
107
108
  return true;
108
109
  }
109
- if (verifPhoneInt.exec(phoneNumber) != null) {
110
- return true;
111
- }
112
- //console.log(verifPhoneInt);
113
- // console.log('"'+phoneNumber+'" not valid');
114
- return false;
110
+ return verifPhoneInt.exec(phoneNumber) != null;
115
111
  }
116
112
 
117
113
  static getType(phoneNumber, localCountryIsoCode) {
@@ -150,7 +146,7 @@ class TelephoneNumber {
150
146
  return window.intlTelInput(input[0], {
151
147
  initialCountry: serviceCountry,
152
148
  placeholderNumberType: placeholderNumberType || 'FIXED_LINE_OR_MOBILE',
153
- utilsScript: intlTelInputUtilsPath
149
+ utilsScript: typeof TelephoneNumber.intlTelInputUtilsPath != 'undefined' ? TelephoneNumber.intlTelInputUtilsPath : null
154
150
  });
155
151
  }
156
152
 
@@ -159,7 +155,7 @@ class TelephoneNumber {
159
155
  }
160
156
 
161
157
  static formatNumberFromIntlTelInput(intlTelInput) {
162
- var number = intlTelInput.getNumber();
158
+ let number = intlTelInput.getNumber();
163
159
  if (number != '' && number.substr(0, 1) !== '+') {
164
160
  number = '+' + intlTelInput.getSelectedCountryData().dialCode + number;
165
161
  }
package/data_table.js CHANGED
@@ -1,9 +1,11 @@
1
1
 
2
2
  class DataTable {
3
- // criteres = {};
4
3
 
5
- constructor() {
6
- this.criteres = {};
4
+ static setOptions(options) {
5
+ DataTable.dateTableOptions = Object.assign(...DataTable.getOptions(), options);
6
+ }
7
+ static getOptions() {
8
+ return DataTable.dateTableOptions || {};
7
9
  }
8
10
 
9
11
  static setCallbackOnLoadData(callback) {
@@ -39,8 +41,8 @@ class DataTable {
39
41
  // ------------------------------------------------------------
40
42
 
41
43
  static init(options) {
42
- var div = options.div;
43
- var defaultFilters = options.default_filters || {};
44
+ let div = options.div;
45
+ let defaultFilters = options.default_filters || {};
44
46
 
45
47
  //let form = div.find('.filter_popover_content form');
46
48
  //if (typeof form != 'undefined') {
@@ -49,7 +51,7 @@ class DataTable {
49
51
  //}
50
52
 
51
53
  // Bouton filtrer
52
- var filterLink = div.find('a.filter_link');
54
+ let filterLink = div.find('a.filter_link');
53
55
  if (filterLink.length) {
54
56
  filterLink.popover({
55
57
  content: div.find('.filter_popover_content').html(),
@@ -68,7 +70,7 @@ class DataTable {
68
70
  });
69
71
 
70
72
  filterLink.on('shown.bs.popover', function () {
71
- var form = $('.filter_popover form');
73
+ let form = $('.filter_popover form');
72
74
 
73
75
  DataTable.populateFormFromFilters(form);
74
76
 
@@ -89,7 +91,7 @@ class DataTable {
89
91
  }
90
92
 
91
93
  // Bouton exporter
92
- var exportLink = div.find('a.export_link');
94
+ let exportLink = div.find('a.export_link');
93
95
  if (exportLink.length) {
94
96
  if (typeof options.export_modal_enabled == 'undefined' || !options.export_modal_enabled) {
95
97
  // sans modal
@@ -111,9 +113,9 @@ class DataTable {
111
113
  });
112
114
 
113
115
  $('div#modal_export').on('show.bs.modal', function (event) {
114
- var button = $(event.relatedTarget);
115
- var modal = $(this);
116
- var form = modal.find('form');
116
+ let button = $(event.relatedTarget);
117
+ let modal = $(this);
118
+ let form = modal.find('form');
117
119
 
118
120
  // Fonction de callback permettant d'initialiser contenu du modal export, cette fonction doit renvoyer le contenu du modal
119
121
  if (typeof options.set_export_form != 'undefined' && options.set_export_form != null) {
@@ -125,7 +127,7 @@ class DataTable {
125
127
  modal.find('modal-body').html(options.on_show_export_form(modal, button));
126
128
  }
127
129
 
128
- var btnSubmit = form.find('button[type="submit"]').attr('disabled', false).button('reset');
130
+ let btnSubmit = form.find('button[type="submit"]').attr('disabled', false).button('reset');
129
131
  btnSubmit.off('click').click(function(e) {
130
132
  e.preventDefault();
131
133
  $(this).attr('disabled', true).button('loading');
@@ -202,7 +204,7 @@ class DataTable {
202
204
  queryString = queryString.includes('?') ? queryString.substring(1) : queryString;
203
205
  //console.log('new queryString', queryString);
204
206
 
205
- let newUrl = UrlAndQueryString.getPath(url) + '?' + queryString;
207
+ let newUrl = UrlAndQueryString.getHostAndPath(url) + '?' + queryString;
206
208
  window.history.pushState("", "", newUrl);
207
209
  }
208
210
 
@@ -255,9 +257,9 @@ class DataTable {
255
257
  }
256
258
  static displayMessage(div, msg, cssClass /*, removeLoader=false*/) {
257
259
  this.resetContent(div);
258
- var table = div.find('table');
260
+ let table = div.find('table');
259
261
  table.find('thead,tfoot').addClass('hide');
260
- var msgHtml = '<div class="text-'+cssClass+' center">'+msg+'</div>';
262
+ let msgHtml = '<div class="text-'+cssClass+' center">'+msg+'</div>';
261
263
  if (table.find('tbody').length == 0) {
262
264
  table.append('<tbody></tbody>');
263
265
  }
@@ -269,7 +271,7 @@ class DataTable {
269
271
  }
270
272
 
271
273
  static displayError(div, data, defaultMessage) {
272
- var error = null;
274
+ let error = null;
273
275
  if (data != null) {
274
276
  if (typeof data.error != 'undefined') {
275
277
  error = data.error;
@@ -286,9 +288,9 @@ class DataTable {
286
288
  }
287
289
 
288
290
  static getDefaultColumnsForDisplayedTable(div) {
289
- var table = div.find('table');
290
- var columns = [];
291
- var defaultHiddenColumns = table.data('hidden_fields') != null ? table.data('hidden_fields').split(',') : [];
291
+ let table = div.find('table');
292
+ let columns = [];
293
+ let defaultHiddenColumns = table.data('hidden_fields') != null ? table.data('hidden_fields').split(',') : [];
292
294
  table.find('thead tr th').each(function(idx, th) {
293
295
  if (defaultHiddenColumns.indexOf($(th).data('key')) == -1) {
294
296
  columns.push($(th).data('key'));
@@ -300,12 +302,12 @@ class DataTable {
300
302
 
301
303
  static setDataContent(div, data, displayLineCallback, completeCallback) {
302
304
  //console.log('setDataContent');
303
- var table = div.find('table').removeClass('hide');
305
+ let table = div.find('table').removeClass('hide');
304
306
 
305
307
  try {
306
308
  DataTable.resetContent(div);
307
- var tableBody = table.find('tbody');
308
- for (var i = 0; i < data.length; i++) {
309
+ let tableBody = table.find('tbody');
310
+ for (let i = 0; i < data.length; i++) {
309
311
  tableBody.append(displayLineCallback(data[i]));
310
312
  }
311
313
 
@@ -339,7 +341,7 @@ class DataTable {
339
341
 
340
342
  static initDataContent(div) {
341
343
  //console.log('initDataContent');
342
- var table = div.find('table');
344
+ let table = div.find('table');
343
345
 
344
346
  // Popover/Tooltip
345
347
  div.find('[data-toggle="popover"]').popover({'trigger':'hover', 'html':true});
@@ -355,16 +357,16 @@ class DataTable {
355
357
 
356
358
  if (table.length > 0 && !table.is('[data-no_datatables="1"]') && !$.fn.dataTable.isDataTable(table)) {
357
359
  if (table.data('page_length') != null) {
358
- dateTablesOptions.pageLength = table.data('page_length');
360
+ DataTable.getOptions()['pageLength'] = table.data('page_length');
359
361
  }
360
- table.DataTable(dateTablesOptions);
362
+ table.DataTable(DataTable.getOptions());
361
363
  }
362
364
 
363
365
  DataTable.updateDataContent(div);
364
366
  }
365
367
 
366
368
  static updateDataContent(div) {
367
- var table = div.find('table');
369
+ let table = div.find('table');
368
370
 
369
371
  // Maj colonnes
370
372
  if (table.length > 0 && typeof div.data('table_name') != 'undefined' && div.data('table_name') != null && div.data('display_items').split(',').indexOf('table_columns') != -1) {
@@ -372,7 +374,7 @@ class DataTable {
372
374
  // table.find('.'+$(th).data('key')+':not(.select):not(.action)').hide();
373
375
  table.find('.'+$(th).data('key')+':not(.select):not(.action)').addClass('hide');
374
376
  });
375
- var columns = this.getDisplayParam(div, 'html', null, 'columns').split(',').removeEmptyValues();
377
+ let columns = this.getDisplayParam(div, 'html', null, 'columns').split(',').removeEmptyValues();
376
378
  $.each(columns, function(idx, key) {
377
379
  table.find('.'+key).removeClass('hide');
378
380
  // table.find('.'+key).show();
@@ -391,7 +393,7 @@ class DataTable {
391
393
 
392
394
  $.fn.dataTable.ext.search = [];
393
395
  //$.fn.dataTable.ext.search.pop();
394
- var dataTableObject = table.DataTable();
396
+ let dataTableObject = table.DataTable();
395
397
  $.fn.dataTable.ext.search.push(
396
398
  function(settings, searchData, index, rowData, counter) {
397
399
  return callback($(dataTableObject.row(index).node()));
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) {
@@ -81,7 +81,7 @@ class DetailsSubArray {
81
81
  }
82
82
 
83
83
  //link.attr('disabled', true).button('loading');
84
- HTTPRequest.get(link.data('url_details'), {},
84
+ HTTPClient.request('GET', link.data('url_details'), null,
85
85
  (jsonObj) => {
86
86
  if (jsonObj == null) {
87
87
  if (typeof callbackOnDetailsActionRequestError != 'undefined' && callbackOnDetailsActionRequestError != null) {
@@ -108,7 +108,7 @@ class DetailsSubArray {
108
108
 
109
109
  onComplete();
110
110
  //window.location.replace(decodeURIComponent(urlRetour));
111
- },
111
+ }
112
112
  );
113
113
  }
114
114
 
package/draw.js ADDED
@@ -0,0 +1,53 @@
1
+ class HexColor {
2
+ static check(hexColor) {
3
+ return hexColor.match(/^[0-9a-fA-F]{6}$/).length;
4
+ }
5
+
6
+ static convertToRgb(hexColor) {
7
+ if (hexColor.substring(0, 1) === '#') {
8
+ hexColor = hexColor.substring(1);
9
+ }
10
+
11
+ if (hexColor.length === 3) {
12
+ hexColor = hexColor+hexColor;
13
+ }
14
+
15
+ if (!HexColor.check(hexColor)) {
16
+ return null;
17
+ }
18
+
19
+ let hexRed = hexColor.substring(0,2);
20
+ let hexGreen = hexColor.substring(2,4);
21
+ let hexBlue = hexColor.substring(4,6);
22
+
23
+ let red = parseInt(hexRed, 16);
24
+ let green = parseInt(hexGreen, 16);
25
+ let blue = parseInt(hexBlue, 16);
26
+
27
+ return [red, green, blue];
28
+ }
29
+
30
+ static isLight(hexColor) {
31
+ let rgb = HexColor.convertToRgb(hexColor);
32
+ if (rgb === null) {
33
+ return false;
34
+ }
35
+ return RgbColor.isLight(rgb[0], rgb[1], rgb[2]);
36
+ }
37
+ }
38
+
39
+ class RgbColor {
40
+ static isLight(red, green, blue) {
41
+ const PERCENT_RED = 0.2125;
42
+ const PERCENT_GREEN = 0.7154;
43
+ const PERCENT_BLUE = 0.0721;
44
+ // $percentageRed = 0.3;
45
+ // $percentageGreen = 0.59;
46
+ // $percentageBlue = 0.11;
47
+
48
+ let coeff = (PERCENT_RED*red) + (PERCENT_GREEN*green) + (PERCENT_BLUE*blue);
49
+ return coeff > 128;
50
+ }
51
+ }
52
+
53
+ module.exports = { HexColor, RgbColor };
package/duration.js CHANGED
@@ -21,7 +21,8 @@ class Duration {
21
21
  minutes = Math.floor(minutes / 60);
22
22
  // minutes = minutes - (minutes % 60);
23
23
  let minCentieme = Math.round( (minutes / 60 ) * 100 );
24
- return parseFloat(hour+'.'+minCentieme);
24
+ return hour+(minCentieme/100);
25
+ //return parseFloat(hour+'.'+minCentieme);
25
26
  }
26
27
 
27
28
  static convertToDurationAsInputTimeValue(durationInSeconds) {
@@ -115,7 +116,7 @@ class Duration {
115
116
  // pas d'arrondissement
116
117
  }
117
118
  else {
118
- var halfRoundPrecision = roundPrecision / 2;
119
+ let halfRoundPrecision = roundPrecision / 2;
119
120
  hoursRounded = hours;
120
121
  secondsRounded = 0;
121
122
  if (roundMode === 'up' || (roundMode === 'close' && minutesRemainingAndSecondsAsCentieme > halfRoundPrecision)) {
@@ -148,14 +149,10 @@ class Duration {
148
149
  return Math.floor(durationInSeconds / 60);
149
150
  }
150
151
 
151
- /*
152
- static getNbMinutesRemaining(durationInSeconds) {
152
+ /*static getNbMinutesRemaining(durationInSeconds) {
153
153
  var remander = ( durationInSeconds % 3600 ) - ( durationInSeconds % 60 );
154
154
  return ( remander / 60 );
155
155
  }
156
- */
157
-
158
- /*
159
156
  static getNbHoursOfDurationInSeconds(durationInSeconds) {
160
157
  // return (this.getNbDaysOfDurationInSeconds(durationInSeconds)*24)+this.getNbHoursRemainingOfDurationInSeconds(durationInSeconds);
161
158
  return (durationInSeconds - (durationInSeconds % 3600)) / 3600;
@@ -163,8 +160,7 @@ class Duration {
163
160
  static getNbMinutesOfDurationInSeconds(durationInSeconds) {
164
161
  // return (this.getNbDaysOfDurationInSeconds(durationInSeconds)*24*60)+(this.getNbHoursRemainingOfDurationInSeconds(durationInSeconds)*60)+this.getNbMinutesRemainingOfDurationInSeconds(durationInSeconds);
165
162
  return (durationInSeconds - (durationInSeconds % 60)) / 60;
166
- }
167
- */
163
+ }*/
168
164
 
169
165
  static getNbHoursRemainingOfDurationInSeconds(durationInSeconds) {
170
166
  return this.getNbHoursOfDurationInSeconds(durationInSeconds % 86400);
package/file.js CHANGED
@@ -113,7 +113,7 @@ class Img {
113
113
  $.ajax({
114
114
  type: 'GET',
115
115
  url: url,
116
- headers: HTTPRequest.getHeaders(true),
116
+ headers: HTTPClient.getHeaders(true),
117
117
  cache: false,
118
118
  xhrFields: {responseType: 'blob'},
119
119
  success: (data) => {
@@ -121,7 +121,7 @@ class Img {
121
121
  // $(img).attr('src', urlCreator.createObjectURL(data));
122
122
  Img.setBlobToImg($(img), data);
123
123
  },
124
- error: (jqxhr, status, errorThrown) => HTTPRequest.logJqueryRequestFailure(jqxhr, status, errorThrown),
124
+ error: (jqxhr, status, errorThrown) => HTTPClient.logJqueryRequestFailure(jqxhr, status, errorThrown),
125
125
  });
126
126
  }
127
127
 
package/flash_message.js CHANGED
@@ -2,7 +2,9 @@ class FlashMessage {
2
2
  static displaySuccess(message, reload, modal) {
3
3
  this.display('success', message, reload, modal);
4
4
  }
5
-
5
+ static displayWarning(message, modal) {
6
+ this.display('warning', message, false, modal);
7
+ }
6
8
  static displayError(message, modal) {
7
9
  this.display('danger', message, false, modal);
8
10
  }
@@ -14,7 +16,7 @@ class FlashMessage {
14
16
  if ($('div.snackbar').length !== 0) {
15
17
  $('div.snackbar').remove();
16
18
  }
17
- var snackbar = $('<div class="snackbar '+type+'"></div>');
19
+ let snackbar = $('<div class="snackbar '+type+'"></div>');
18
20
  $('html body').append(snackbar);
19
21
  snackbar.html(message);
20
22
  snackbar.addClass('show');
@@ -27,12 +29,6 @@ class FlashMessage {
27
29
  document.location.reload();
28
30
  }
29
31
  }
30
-
31
- /** @deprecated **/
32
- static displayRequestFailure(status, exception, modal) {
33
- console.log('request failure. Status: ', status, ' Exception: ', exception);
34
- this.display('danger', typeof labelErrorOccured != 'undefined' ? labelErrorOccured : 'Une erreur s’est produite.', false, modal);
35
- }
36
32
  }
37
33
 
38
34
  module.exports = { FlashMessage };