@osimatic/helpers-js 1.5.5 → 1.5.7

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/chartjs.js CHANGED
@@ -1,3 +1,6 @@
1
+ const { toEl } = require('./util');
2
+ const deepmerge = require('deepmerge');
3
+
1
4
  class Chartjs {
2
5
  static init() {
3
6
  if (typeof Chartjs.initialized == 'undefined' || Chartjs.initialized) {
@@ -37,8 +40,9 @@ class Chartjs {
37
40
  }
38
41
 
39
42
  static createStackedChart(chartDiv, chartData, title=null, options={}) {
40
- chartDiv.empty();
41
- new Chart(chartDiv.get(0).getContext("2d"), $.extend(true, {}, {
43
+ chartDiv = toEl(chartDiv);
44
+ chartDiv.innerHTML = '';
45
+ new Chart(chartDiv.getContext("2d"), deepmerge({
42
46
  type: "bar",
43
47
  data: {
44
48
  labels: chartData.labels,
@@ -86,8 +90,9 @@ class Chartjs {
86
90
  }
87
91
 
88
92
  static createBarChart(chartDiv, chartData, title=null, options={}) {
89
- chartDiv.empty();
90
- new Chart(chartDiv.get(0).getContext("2d"), $.extend(true, {}, {
93
+ chartDiv = toEl(chartDiv);
94
+ chartDiv.innerHTML = '';
95
+ new Chart(chartDiv.getContext("2d"), deepmerge({
91
96
  type: "bar",
92
97
  data: {
93
98
  labels: chartData.labels,
@@ -102,15 +107,11 @@ class Chartjs {
102
107
  grid: {
103
108
  display: false
104
109
  },
105
- /*ticks: {
106
- font: { size: 12 }
107
- }*/
108
110
  },
109
111
  y: {
110
112
  beginAtZero: true,
111
113
  ticks: {
112
114
  precision: 0
113
- //stepSize: 10, font: { size: 12 }
114
115
  },
115
116
  grid: {
116
117
  color: "#eee"
@@ -132,7 +133,6 @@ class Chartjs {
132
133
  tooltip: {
133
134
  callbacks: {
134
135
  label: context => context.dataset.label + ' : ' + context.parsed.y
135
- //label: (context) => `${context.formattedValue} pointages`
136
136
  }
137
137
  }
138
138
  },
@@ -147,8 +147,9 @@ class Chartjs {
147
147
  static createLineChart(chartDiv, chartData, title=null, options={}) {
148
148
  Chartjs.init();
149
149
 
150
- chartDiv.empty();
151
- new Chart(chartDiv.get(0).getContext("2d"), $.extend(true, {}, {
150
+ chartDiv = toEl(chartDiv);
151
+ chartDiv.innerHTML = '';
152
+ new Chart(chartDiv.getContext("2d"), deepmerge({
152
153
  type: "line",
153
154
  data: {
154
155
  labels: chartData.labels,
@@ -199,8 +200,9 @@ class Chartjs {
199
200
  static createDoughnutChart(chartDiv, chartData, title=null, options={}) {
200
201
  Chartjs.init();
201
202
 
202
- chartDiv.empty();
203
- new Chart(chartDiv.get(0).getContext("2d"), $.extend(true, {}, {
203
+ chartDiv = toEl(chartDiv);
204
+ chartDiv.innerHTML = '';
205
+ new Chart(chartDiv.getContext("2d"), deepmerge({
204
206
  type: "doughnut",
205
207
  data: {
206
208
  labels: chartData.labels,
@@ -256,10 +258,7 @@ class Chartjs {
256
258
  static groupByPeriod(data, period, metrics) {
257
259
  const grouped = {};
258
260
 
259
- //data = Object.entries(dataObj).map(([date, values]) => ({ date, ...values }));
260
-
261
261
  Object.entries(data).forEach(([date, values]) => {
262
- //data.forEach(entry => {
263
262
  const d = new Date(date);
264
263
  let key;
265
264
 
package/count_down.js CHANGED
@@ -1,23 +1,23 @@
1
+ const { toEl } = require('./util');
2
+
1
3
  class CountDown {
2
4
 
3
5
  static init(div, options = {}) {
6
+ div = toEl(div);
4
7
  const {
5
8
  onRefreshData,
6
9
  labelNextUpdate = 'Prochaine mise à jour',
7
10
  labelDoUpdate = 'Mettre à jour',
8
11
  } = options;
9
12
 
10
- if (!div.length) {
13
+ if (!div) {
11
14
  return;
12
15
  }
13
16
 
14
- div
15
- .append('<div class="count_down_title">'+labelNextUpdate+'</div>')
16
- .append('<div class="count_down_progress"><div class="count_down_current"></div></div>')
17
- .append('<div class="count_down_text"></div>')
18
- //.append('<div class="cl"></div>')
19
- .append('<div class="count_down_link"><a href="#" data-loading-text="<i class=\'fa fa-circle-notch fa-spin\'></i>">'+labelDoUpdate+'</a></div>')
20
- ;
17
+ div.insertAdjacentHTML('beforeend', '<div class="count_down_title">'+labelNextUpdate+'</div>');
18
+ div.insertAdjacentHTML('beforeend', '<div class="count_down_progress"><div class="count_down_current"></div></div>');
19
+ div.insertAdjacentHTML('beforeend', '<div class="count_down_text"></div>');
20
+ div.insertAdjacentHTML('beforeend', '<div class="count_down_link"><a href="#">'+labelDoUpdate+'</a></div>');
21
21
 
22
22
  let alreadyMakingRequest = false;
23
23
  let secondsBefRefresh = 10;
@@ -25,6 +25,10 @@ class CountDown {
25
25
  let currentMillis = 0;
26
26
  let currentSecond = 0;
27
27
 
28
+ function getLinkA() {
29
+ return div.querySelector('.count_down_link a');
30
+ }
31
+
28
32
  function refreshData() {
29
33
  currentMillis = 0;
30
34
 
@@ -36,27 +40,31 @@ class CountDown {
36
40
 
37
41
  if (typeof onRefreshData == 'function') {
38
42
  alreadyMakingRequest = true;
39
- div.find('.count_down_link a').attr('disabled', true).button('loading');
43
+ const linkA = getLinkA();
44
+ if (linkA) linkA.disabled = true;
40
45
 
41
46
  onRefreshData(
42
47
  // completeCallback
43
48
  () => {
44
49
  alreadyMakingRequest = false;
45
- div.find('.count_down_link a').attr('disabled', false).button('reset');
50
+ const linkA = getLinkA();
51
+ if (linkA) linkA.disabled = false;
46
52
  }
47
53
  );
48
54
  }
49
55
  }
50
56
 
51
- if (div.find('.count_down_link a').length) {
52
- div.find('.count_down_link a').click(() => {
57
+ const linkA = getLinkA();
58
+ if (linkA) {
59
+ linkA.addEventListener('click', (e) => {
60
+ e.preventDefault();
53
61
  refreshData();
54
- return false;
55
62
  });
56
63
  }
57
64
 
58
65
  setInterval(() => {
59
- if (!div.find('.count_down_link a').length || !div.find('.count_down_link a').prop('disabled')) {
66
+ const linkA = getLinkA();
67
+ if (!linkA || !linkA.disabled) {
60
68
  currentMillis += refreshIntervalMillis;
61
69
  }
62
70
  else {
@@ -65,9 +73,8 @@ class CountDown {
65
73
 
66
74
  currentSecond = parseInt(currentMillis / 1000);
67
75
 
68
- //countDownRefresh();
69
- var divCountDownText;
70
- var divCountDownCurrentSizePx;
76
+ let divCountDownText;
77
+ let divCountDownCurrentSizePx;
71
78
 
72
79
  if (currentSecond >= secondsBefRefresh) {
73
80
  divCountDownCurrentSizePx = 120;
@@ -78,11 +85,13 @@ class CountDown {
78
85
  divCountDownText = (secondsBefRefresh-currentSecond) + 's';
79
86
  }
80
87
 
81
- if (div.find('.count_down_current').length) {
82
- div.find('.count_down_current').width(divCountDownCurrentSizePx);
88
+ const countDownCurrent = div.querySelector('.count_down_current');
89
+ if (countDownCurrent) {
90
+ countDownCurrent.style.width = divCountDownCurrentSizePx + 'px';
83
91
  }
84
- if (div.find('.count_down_text').length) {
85
- div.find('.count_down_text').html(divCountDownText);
92
+ const countDownText = div.querySelector('.count_down_text');
93
+ if (countDownText) {
94
+ countDownText.innerHTML = divCountDownText;
86
95
  }
87
96
 
88
97
  if (currentSecond >= secondsBefRefresh) {
@@ -1,8 +1,10 @@
1
1
  const { HTTPClient } = require('./http_client');
2
+ const { toEl } = require('./util');
2
3
 
3
4
  class DetailsSubArray {
4
5
 
5
6
  static initDetailsLink(table, options = {}) {
7
+ table = toEl(table);
6
8
  const {
7
9
  onSuccess,
8
10
  onError,
package/file.js CHANGED
@@ -1,3 +1,4 @@
1
+ const { HTTPClient } = require('./http_client');
1
2
 
2
3
  class File {
3
4
  static download(data, contentType, contentDisposition) {
@@ -102,30 +103,33 @@ class Img {
102
103
  }
103
104
 
104
105
  static initImg(div) {
105
- div.find('.asynchronously_img').each(function(idx, img) {
106
- Img.loadImgUrl($(img).data('url'), $(img));
106
+ div.querySelectorAll('.asynchronously_img').forEach(img => {
107
+ Img.loadImgUrl(img.dataset.url, img);
107
108
  });
108
109
  }
109
110
 
110
111
  static loadImgUrl(url, img) {
111
- $.ajax({
112
- type: 'GET',
113
- url: url,
114
- headers: HTTPClient.getHeaders(true),
115
- cache: false,
116
- xhrFields: {responseType: 'blob'},
117
- success: (data) => {
118
- // var urlCreator = window.URL || window.webkitURL;
119
- // $(img).attr('src', urlCreator.createObjectURL(data));
120
- Img.setBlobToImg($(img), data);
121
- },
122
- error: (jqxhr, status, errorThrown) => HTTPClient.logJqueryRequestFailure(jqxhr, status, errorThrown),
123
- });
112
+ fetch(url, {
113
+ method: 'GET',
114
+ headers: HTTPClient.getHeaders(false),
115
+ cache: 'no-cache',
116
+ })
117
+ .then(response => {
118
+ if (!response.ok) {
119
+ HTTPClient.logRequestFailure(response, null);
120
+ return null;
121
+ }
122
+ return response.blob();
123
+ })
124
+ .then(blob => {
125
+ if (blob) Img.setBlobToImg(img, blob);
126
+ })
127
+ .catch(error => console.error('Error loading image:', error));
124
128
  }
125
129
 
126
130
  static setBlobToImg(img, blob) {
127
131
  // Validation de l'élément img
128
- if (!img || !img.length) {
132
+ if (!img) {
129
133
  console.error('Invalid img element provided to setBlobToImg');
130
134
  return;
131
135
  }
@@ -138,8 +142,7 @@ class Img {
138
142
 
139
143
  try {
140
144
  let urlCreator = window.URL || window.webkitURL;
141
- let objectURL = urlCreator.createObjectURL(blob);
142
- img.attr('src', objectURL);
145
+ img.src = urlCreator.createObjectURL(blob);
143
146
  } catch (error) {
144
147
  console.error('Error creating object URL from blob:', error);
145
148
  }
package/form_date.js CHANGED
@@ -494,108 +494,6 @@ class FormDate {
494
494
  if (monthSelect) monthSelect.value = month;
495
495
  if (yearSelect) yearSelect.value = year;
496
496
  }
497
-
498
-
499
-
500
- /*
501
- // deprecated
502
-
503
- static majSelectPeriode(select) {
504
- if (select.find(':selected').attr('value') === 'perso') {
505
- select.parent().parent().next().removeClass('hide');
506
- }
507
- else {
508
- select.parent().parent().next().addClass('hide');
509
- }
510
- }
511
-
512
- static majSelectCompare() {
513
- if ($('form select#periodeCompare').length === 0) {
514
- return;
515
- }
516
-
517
- let listValues = [];
518
- let periodeSelected = $('form select.periode :selected').attr('value');
519
- let selectCompare = $('form select#periodeCompare');
520
- let periodeCompareSelected = selectCompare.find(':selected').attr('value');
521
- let valueDefault = null;
522
-
523
- selectCompare.find('option').removeAttr('disabled');
524
-
525
- $.each(listePeriodeCompare, function (idx, tabListPeriode) {
526
- if (idx != 0) {
527
- let listKeyPeriode = array_keys(tabListPeriode.list);
528
- if (in_array(periodeSelected, listKeyPeriode)) {
529
- listValues = listKeyPeriode;
530
- valueDefault = listKeyPeriode[1];
531
- }
532
- else {
533
- selectCompare.find('option[value="' + listKeyPeriode[0] + '"]').parent().children().attr('disabled', 'disabled');
534
- }
535
- }
536
- });
537
-
538
- if (periodeSelected === 'perso') {
539
- valueDefault = 'perso';
540
- }
541
- else if (periodeCompareSelected !== 'perso' && in_array(periodeCompareSelected, listValues)) {
542
- valueDefault = periodeCompareSelected;
543
- }
544
- selectCompare.find('option[value="' + valueDefault + '"]').attr('selected', 'selected');
545
-
546
- FormDate.majSelectPeriode(selectCompare);
547
- }
548
-
549
- static selectFormDateToday(lien) {
550
- let date = new Date();
551
- FormDate.selectFormDate(lien, date.getDate(), (date.getMonth() + 1), date.getFullYear());
552
- }
553
- static selectFormDateDayMoinsNb(lien, nbJoursMoins) {
554
- let date = new Date();
555
- date.setDate(date.getDate() - nbJoursMoins);
556
- FormDate.selectFormDate(lien, date.getDate(), (date.getMonth() + 1), date.getFullYear());
557
- }
558
- static selectFormDateCurrentMonth(lien) {
559
- let date = new Date();
560
- FormDate.selectFormDate(lien, -1, (date.getMonth() + 1), date.getFullYear());
561
- }
562
- static selectFormDateMonthMoinsNb(lien, nbMoisMoins) {
563
- let date = new Date();
564
- date.setDate(1);
565
- date.setMonth(date.getMonth() - nbMoisMoins);
566
- FormDate.selectFormDate(lien, -1, (date.getMonth() + 1), date.getFullYear());
567
- }
568
- static selectFormDateCurrentYear(lien) {
569
- let today = new Date();
570
- FormDate.selectFormDate(lien, -1, -1, today.getFullYear());
571
- }
572
- static selectFormDateYearMoinsNb(lien, nbAnneesMoins) {
573
- let today = new Date();
574
- FormDate.selectFormDate(lien, -1, -1, today.getFullYear() - nbAnneesMoins);
575
- }
576
- static selectFormDateAddDayFromSelectedDay(lien, nbDaysAdded) {
577
- let date = FormDate.getDateObjectSelected(lien);
578
- date.setDate(date.getDate() + nbDaysAdded);
579
- FormDate.selectFormDate(lien, date.getDate(), (date.getMonth() + 1), date.getFullYear());
580
- }
581
- static getDateObjectSelected(lien) {
582
- let selectorDay = '#' + (lien.parent().prev().prev().prev().prev().attr('id')) + ' option:selected';
583
- let selectorMonth = '#' + (lien.parent().prev().prev().prev().attr('id')) + ' option:selected';
584
- let selectorYear = '#' + (lien.parent().prev().prev().attr('id')) + ' option:selected';
585
- if ($(selectorDay).length > 0 && $(selectorMonth).length > 0 && $(selectorYear).length > 0) {
586
- return new Date($(selectorYear).attr('value'), $(selectorMonth).attr('value') - 1, $(selectorDay).attr('value'));
587
- }
588
- return new Date();
589
- }
590
- static selectFormDate(lien, day, month, year) {
591
- let selectorDay = '#' + (lien.parent().prev().prev().prev().prev().attr('id')) + ' option[value=' + day + ']';
592
- let selectorMonth = '#' + (lien.parent().prev().prev().prev().attr('id')) + ' option[value=' + month + ']';
593
- let selectorYear = '#' + (lien.parent().prev().prev().attr('id')) + ' option[value=' + year + ']';
594
- if ($(selectorDay).length > 0) $(selectorDay).prop('selected', 'selected');
595
- if ($(selectorMonth).length > 0) $(selectorMonth).prop('selected', 'selected');
596
- if ($(selectorYear).length > 0) $(selectorYear).prop('selected', 'selected');
597
- }
598
- */
599
497
  }
600
498
 
601
499
  module.exports = { FormDate, InputPeriod };
package/form_helper.js CHANGED
@@ -1,5 +1,8 @@
1
+ const { toEl } = require('./util');
2
+
1
3
  class FormHelper {
2
4
  static init(form, onSubmitCallback, submitButton=null) {
5
+ form = toEl(form); submitButton = toEl(submitButton);
3
6
  FormHelper.reset(form, submitButton);
4
7
  submitButton = null != submitButton ? submitButton : form.querySelector('button[name="validate"]');
5
8
  submitButton.onclick = function(e) {
@@ -14,6 +17,7 @@ class FormHelper {
14
17
  }
15
18
 
16
19
  static reset(form, submitButton=null) {
20
+ form = toEl(form); submitButton = toEl(submitButton);
17
21
  submitButton = null != submitButton ? submitButton : form.querySelector('button[name="validate"]');
18
22
  form.querySelectorAll('input[name]:not([type="checkbox"]):not([type="radio"]), select:not(.selectpicker), textarea').forEach(el => {
19
23
  el.value = '';
@@ -26,6 +30,7 @@ class FormHelper {
26
30
  }
27
31
 
28
32
  static populateForm(form, data) {
33
+ form = toEl(form);
29
34
  const employeesDisplayType = form.querySelector('[name="employees_display_type"][value="NONE"]');
30
35
  if (employeesDisplayType) employeesDisplayType.checked = true; //todo à retirer
31
36
 
@@ -64,6 +69,7 @@ class FormHelper {
64
69
 
65
70
 
66
71
  static getFormData(form) {
72
+ form = toEl(form);
67
73
  return new FormData(form);
68
74
  }
69
75
 
@@ -77,6 +83,7 @@ class FormHelper {
77
83
  }
78
84
 
79
85
  static getFormDataQueryString(form) {
86
+ form = toEl(form);
80
87
  return new URLSearchParams(new FormData(form)).toString();
81
88
  }
82
89
 
@@ -87,6 +94,7 @@ class FormHelper {
87
94
  // ------------------------------------------------------------
88
95
 
89
96
  static getInputValue(input) {
97
+ input = toEl(input);
90
98
  if (typeof input == 'undefined' || input == null) {
91
99
  return null;
92
100
  }
@@ -98,10 +106,12 @@ class FormHelper {
98
106
  }
99
107
 
100
108
  static getLinesOfTextarea(textarea) {
109
+ textarea = toEl(textarea);
101
110
  return textarea.value.replace(/(\r\n|\n|\r)/g, "\n").split("\n").filter(word => word.length > 0);
102
111
  }
103
112
 
104
113
  static setOnInputChange(input, callback, doneTypingInterval=700) {
114
+ input = toEl(input);
105
115
  // setup before functions
106
116
  let typingTimer; // timer identifier
107
117
 
@@ -128,26 +138,32 @@ class FormHelper {
128
138
  // ------------------------------------------------------------
129
139
 
130
140
  static resetSelectOption(form, selectName) {
141
+ form = toEl(form);
131
142
  form.querySelectorAll('select[name="'+selectName+'"] option').forEach(o => {
132
143
  o.disabled = false;
133
144
  o.selected = false;
134
145
  });
135
146
  }
136
147
  static setSelectedSelectOption(form, selectName, optionValue) {
148
+ form = toEl(form);
137
149
  const opt = form.querySelector('select[name="'+selectName+'"] option[value="'+optionValue+'"]');
138
150
  if (opt) opt.selected = true;
139
151
  }
140
152
  static setSelectedSelectOptions(form, selectName, optionValues) {
153
+ form = toEl(form);
141
154
  optionValues.forEach(id => FormHelper.setSelectedSelectOption(form, selectName, id));
142
155
  }
143
156
  static disableSelectOption(form, selectName, optionValue) {
157
+ form = toEl(form);
144
158
  const opt = form.querySelector('select[name="'+selectName+'"] option[value="'+optionValue+'"]');
145
159
  if (opt) opt.disabled = true;
146
160
  }
147
161
  static disableSelectOptions(form, selectName, optionValues) {
162
+ form = toEl(form);
148
163
  optionValues.forEach(id => FormHelper.disableSelectOption(form, selectName, id));
149
164
  }
150
165
  static countSelectOptions(form, selectName) {
166
+ form = toEl(form);
151
167
  return form.querySelectorAll('select[name="'+selectName+'"] option:not([disabled])').length;
152
168
  }
153
169
 
@@ -180,6 +196,7 @@ class FormHelper {
180
196
  // ------------------------------------------------------------
181
197
 
182
198
  static initTypeFields(form) {
199
+ form = toEl(form);
183
200
  if (typeof Modernizr != 'undefined') {
184
201
  if (!Modernizr.inputtypes.date) {
185
202
  form.querySelectorAll('input[type="date"]').forEach(el => el.style.maxWidth = '120px');
@@ -215,6 +232,7 @@ class FormHelper {
215
232
  }
216
233
 
217
234
  static hideField(inputOrSelect) {
235
+ inputOrSelect = toEl(inputOrSelect);
218
236
  inputOrSelect.closest('.form-group')?.classList.add('hide');
219
237
  }
220
238
 
@@ -271,6 +289,7 @@ class FormHelper {
271
289
  }
272
290
 
273
291
  static hideFormErrors(form) {
292
+ form = toEl(form);
274
293
  form.querySelectorAll('div.form_errors').forEach(el => el.remove());
275
294
  return form;
276
295
  }
@@ -296,6 +315,7 @@ class FormHelper {
296
315
  }
297
316
 
298
317
  static displayFormErrors(form, btnSubmit, errors, errorWrapperDiv=null) {
318
+ form = toEl(form); btnSubmit = toEl(btnSubmit); errorWrapperDiv = toEl(errorWrapperDiv);
299
319
  this.displayFormErrorsFromText(form, this.getFormErrorText(errors), errorWrapperDiv);
300
320
  if (btnSubmit != null) {
301
321
  FormHelper.buttonLoader(btnSubmit, 'reset');
@@ -303,6 +323,7 @@ class FormHelper {
303
323
  }
304
324
 
305
325
  static displayFormErrorsFromText(form, errorLabels, errorWrapperDiv=null) {
326
+ form = toEl(form); errorWrapperDiv = toEl(errorWrapperDiv);
306
327
  let errorDiv = '<div class="alert alert-danger form_errors">'+errorLabels+'</div>';
307
328
 
308
329
  if (null != errorWrapperDiv) {
@@ -342,6 +363,7 @@ class FormHelper {
342
363
  // ------------------------------------------------------------
343
364
 
344
365
  static buttonLoader(button, action) {
366
+ button = toEl(button);
345
367
  if (action === 'start' || action === 'loading') {
346
368
  if (button.disabled) {
347
369
  return button;
@@ -387,6 +409,7 @@ class ArrayField {
387
409
  get_errors_callback: null,
388
410
 
389
411
  }) {
412
+ formGroupDiv = toEl(formGroupDiv);
390
413
  function isOptionDefined(optionName) {
391
414
  return typeof options[optionName] != 'undefined' && null !== options[optionName];
392
415
  }
@@ -694,6 +717,7 @@ class ArrayField {
694
717
 
695
718
  class EditValue {
696
719
  static init(valueDiv, onSubmitCallback, getInputCallback) {
720
+ valueDiv = toEl(valueDiv);
697
721
  const link = document.createElement('a');
698
722
  link.href = '#';
699
723
  link.className = 'text-warning';
package/google_charts.js CHANGED
@@ -1,3 +1,5 @@
1
+ const { toEl } = require('./util');
2
+
1
3
  class GoogleCharts {
2
4
  static init(onLoadCallback) {
3
5
  // google.load("visualization", "1", {packages:["corechart"]});
@@ -42,6 +44,7 @@ class GoogleCharts {
42
44
  }
43
45
 
44
46
  static draw(div, options) {
47
+ div = toEl(div);
45
48
  const {
46
49
  chart_type: chartType,
47
50
  title: title,
@@ -1,4 +1,5 @@
1
1
  require('./string');
2
+ const { toEl } = require('./util');
2
3
 
3
4
  class ImportFromCsv {
4
5
 
@@ -16,6 +17,7 @@ class ImportFromCsv {
16
17
  }
17
18
 
18
19
  static initForm(div, options = {}) {
20
+ div = toEl(div);
19
21
  const {
20
22
  importColumns,
21
23
  requestImportData,
@@ -169,6 +171,7 @@ class ImportFromCsv {
169
171
  }
170
172
 
171
173
  static displayData(divResult, data, header, formMatching) {
174
+ divResult = toEl(divResult);
172
175
  let table = divResult.querySelector('table');
173
176
  if (!table) {
174
177
  divResult.insertAdjacentHTML('beforeend', '<table class="table table-sm table-bordered"></table>');
package/location.js CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  const Address = require('ilib/lib/Address');
3
3
  const AddressFmt = require('ilib/lib/AddressFmt');
4
+ const { toEl } = require('./util');
4
5
 
5
6
  class Country {
6
7
  static setFlagsPath(flagsPath) {
@@ -15,17 +16,15 @@ class Country {
15
16
  }
16
17
 
17
18
  static fillCountrySelect(select, defaultValue=null, countriesList=null, addNoneValue=false, noneLabel='- Aucun -') {
18
- if (select.children().length === 0) {
19
+ select = toEl(select);
20
+ if (select.children.length === 0) {
19
21
  if (addNoneValue) {
20
- select.append('<option value="">'+noneLabel+'</option>');
22
+ select.insertAdjacentHTML('beforeend', '<option value="">'+noneLabel+'</option>');
21
23
  }
22
- Object.entries(null != countriesList ? countriesList : Country.getCountries()).forEach(([countryCode, countryName]) => select.append('<option value="' + countryCode + '">' + countryName + '</option>'));
24
+ Object.entries(null != countriesList ? countriesList : Country.getCountries()).forEach(([countryCode, countryName]) => select.insertAdjacentHTML('beforeend', '<option value="' + countryCode + '">' + countryName + '</option>'));
23
25
  }
24
26
  if (null != defaultValue) {
25
- select.val(defaultValue);
26
- }
27
- if (typeof select.selectpicker != 'undefined') {
28
- select.selectpicker('refresh');
27
+ select.value = defaultValue;
29
28
  }
30
29
  }
31
30
  static getCountryName(countryCode) {
@@ -303,8 +302,9 @@ class Country {
303
302
 
304
303
  class PostalAddress {
305
304
  static setAutocomplete(input, onPlaceChanged) {
305
+ input = toEl(input);
306
306
  const autocomplete = new google.maps.places.Autocomplete(
307
- input[0],
307
+ input,
308
308
  {types: ['geocode']}
309
309
  );
310
310
 
@@ -316,7 +316,7 @@ class PostalAddress {
316
316
 
317
317
  autocomplete.addListener('place_changed', function() {
318
318
  let place = autocomplete.getPlace();
319
- input.val('');
319
+ input.value = '';
320
320
  onPlaceChanged(place);
321
321
  });
322
322
 
@@ -415,13 +415,10 @@ class PostalAddress {
415
415
  addressData.countryCode = resultAddressComponent.short_name;
416
416
  }
417
417
  });
418
- var htmlAddress = $(googleApiResult.adr_address);
419
- // console.log(googleApiResult.adr_address);
420
- // console.log(htmlAddress);
421
- // console.log(htmlAddress.find('span.street-address'));
422
- //console.log($(htmlAddress[0]).text());
423
- if (htmlAddress.length && $(htmlAddress[0]).length) {
424
- addressData.streetAddress = $(htmlAddress[0]).text();
418
+ const tmp = document.createElement('div');
419
+ tmp.innerHTML = googleApiResult.adr_address || '';
420
+ if (tmp.children.length > 0) {
421
+ addressData.streetAddress = tmp.children[0].textContent;
425
422
  }
426
423
  else {
427
424
  addressData.streetAddress = streetNumber+' '+route;