@osimatic/helpers-js 1.5.3 → 1.5.4

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.
@@ -13,66 +13,73 @@ class DetailsSubArray {
13
13
  } = options;
14
14
 
15
15
  function getNbColumns(tr) {
16
- return tr.closest('table').find('thead tr').children().length;
16
+ return tr.closest('table').querySelector('thead tr').children.length;
17
17
  }
18
18
  function displayErrorRow(tr) {
19
- tr.after($('<tr class="text-error"><td colspan="'+getNbColumns(tr)+'">'+labelErrorOccurred+'</td></tr>'));
19
+ tr.insertAdjacentHTML('afterend', '<tr class="text-error"><td colspan="'+getNbColumns(tr)+'">'+labelErrorOccurred+'</td></tr>');
20
20
  }
21
21
  function displayDetailsRow(tr, content) {
22
- var trContent = $(''
23
- + '<tr class="participants">'
24
- + '<td colspan="'+getNbColumns(tr)+'">'
25
- + '</td>'
26
- + '</tr>'
27
- );
28
- trContent.find('td').append(content);
29
- tr.after(trContent);
22
+ const td = document.createElement('td');
23
+ td.setAttribute('colspan', getNbColumns(tr));
24
+ if (content instanceof Node) {
25
+ td.appendChild(content);
26
+ } else {
27
+ td.innerHTML = content || '';
28
+ }
29
+ const trContent = document.createElement('tr');
30
+ trContent.className = 'participants';
31
+ trContent.appendChild(td);
32
+ tr.insertAdjacentElement('afterend', trContent);
30
33
  }
31
34
 
32
35
  function hideDetailsRow(link) {
33
- var tr = link.closest('tr').addClass('folded');
34
- if (tr.next().hasClass('participants') ) {
35
- tr.next().remove();
36
+ const tr = link.closest('tr');
37
+ tr.classList.add('folded');
38
+ const next = tr.nextElementSibling;
39
+ if (next && next.classList.contains('participants')) {
40
+ next.remove();
36
41
  }
37
42
  showPlusButton(link);
38
43
  }
39
44
 
40
45
  function showPlusButton(link) {
41
- link.prop('title', showDetailsLabel).attr('disabled', false).html($('<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>'));
46
+ link.title = showDetailsLabel;
47
+ link.disabled = false;
48
+ link.innerHTML = '<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>';
42
49
  }
43
50
  function showMinusButton(link) {
44
- link.prop('title', hideDetailsLabel).attr('disabled', false).html($('<span class="glyphicon glyphicon-minus" aria-hidden="true"></span>'));
51
+ link.title = hideDetailsLabel;
52
+ link.disabled = false;
53
+ link.innerHTML = '<span class="glyphicon glyphicon-minus" aria-hidden="true"></span>';
45
54
  }
46
55
 
47
56
  function displayLoading(link) {
48
- link.attr('disabled', true).html($('<i class="fa fa-circle-notch fa-spin"></i>'));
49
- var tr = link.closest('tr');
50
- tr.after($('<tr class="waiting_icon"><td colspan="'+getNbColumns(tr)+'" class="center"><i class="fa fa-circle-notch fa-spin"></i></td></tr>'));
57
+ link.disabled = true;
58
+ link.innerHTML = '<i class="fa fa-circle-notch fa-spin"></i>';
59
+ const tr = link.closest('tr');
60
+ tr.insertAdjacentHTML('afterend', '<tr class="waiting_icon"><td colspan="'+getNbColumns(tr)+'" class="center"><i class="fa fa-circle-notch fa-spin"></i></td></tr>');
51
61
  }
52
- function hideLoading(link) {
62
+ function hideLoading() {
53
63
  // todo : cacher que le loader du lien au lieu de tous les loaders (cas ou l'user clique sur tous les boutons rapidement)
54
- if ($('tr.waiting_icon').length > 0) {
55
- $(('tr.waiting_icon')).remove();
56
- }
64
+ document.querySelectorAll('tr.waiting_icon').forEach(el => el.remove());
57
65
  }
58
66
 
59
67
  function setHideDetailsLink(link) {
60
68
  showMinusButton(link);
61
- link.click(function() {
62
- $(this).stop();
69
+ link.onclick = function(e) {
70
+ e.preventDefault();
63
71
  hideDetailsRow(link);
64
72
  setDisplayDetailsLink(link);
65
- return false;
66
- });
73
+ };
67
74
  }
68
75
 
69
76
  function setDisplayDetailsLink(link) {
70
- link.click(function() {
71
- $(this).stop().off('click');
77
+ link.onclick = function(e) {
78
+ e.preventDefault();
79
+ link.onclick = null;
72
80
  hideDetailsRow(link);
73
81
  doDetailsActionRequest(link);
74
- return false;
75
- });
82
+ };
76
83
  }
77
84
 
78
85
  function doDetailsActionRequest(link) {
@@ -80,19 +87,17 @@ class DetailsSubArray {
80
87
 
81
88
  if (onBeforeSend != null) {
82
89
  displayDetailsRow(link.closest('tr'), onBeforeSend(link));
83
- hideLoading(link);
90
+ hideLoading();
84
91
  setHideDetailsLink(link);
85
92
  return;
86
93
  }
87
94
 
88
95
  function onComplete() {
89
- hideLoading(link);
96
+ hideLoading();
90
97
  setHideDetailsLink(link);
91
- //link.attr('disabled', false).button('reset');
92
98
  }
93
99
 
94
- //link.attr('disabled', true).button('loading');
95
- HTTPClient.request('GET', link.data('url_details'), null,
100
+ HTTPClient.request('GET', link.dataset.url_details, null,
96
101
  (jsonObj) => {
97
102
  if (jsonObj == null) {
98
103
  if (onError != null) {
@@ -115,18 +120,17 @@ class DetailsSubArray {
115
120
  return;
116
121
  }
117
122
 
118
- link.closest('tr').after($('<tr class="error"><td colspan="6" class="center">'+(labelErrorOccurred ??'Une erreur sest produite.')+'</td></tr>'));
123
+ link.closest('tr').insertAdjacentHTML('afterend', '<tr class="error"><td colspan="6" class="center">'+(labelErrorOccurred ?? 'Une erreur s\'est produite.')+'</td></tr>');
119
124
 
120
125
  onComplete();
121
- //window.location.replace(decodeURIComponent(urlRetour));
122
126
  }
123
127
  );
124
128
  }
125
129
 
126
- table.find('a.details_link').each(function(idx, link) {
127
- $(link).removeClass('hide');
128
- setDisplayDetailsLink($(link));
129
- showPlusButton($(link));
130
+ table.querySelectorAll('a.details_link').forEach((link) => {
131
+ link.classList.remove('hide');
132
+ setDisplayDetailsLink(link);
133
+ showPlusButton(link);
130
134
  });
131
135
  }
132
136