@osimatic/helpers-js 1.0.77 → 1.0.78

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/index.js CHANGED
@@ -26,7 +26,7 @@ const { DataTable } = require('./data_table');
26
26
  const { Pagination, Navigation } = require('./paging');
27
27
  const { DetailsSubArray } = require('./details_sub_array');
28
28
  const { SelectAll } = require('./select_all');
29
- const { MultipleActionInTable } = require('./multiple_action_in_table');
29
+ const { MultipleActionInTable, MultipleActionInDivList } = require('./multiple_action_in_table');
30
30
  const { FormDate, InputPeriod } = require('./form_date');
31
31
  const { ShoppingCart } = require('./shopping_cart');
32
32
  const { FlashMessage } = require('./flash_message');
@@ -47,7 +47,7 @@ const { WebSocket } = require('./web_socket');
47
47
  module.exports = {
48
48
  Array, Object, Number, String,
49
49
  HTTPRequest, Cookie, UrlAndQueryString, IBAN, BankCard, AudioMedia, UserMedia, PersonName, Email, TelephoneNumber, DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, GeographicCoordinates, SocialNetwork,
50
- Browser, DataTable, Pagination, Navigation, DetailsSubArray, SelectAll, MultipleActionInTable, EditValue, FormDate, InputPeriod, ShoppingCart, FlashMessage, CountDown, ImportFromCsv, JwtToken, JwtSession, ApiTokenSession, ListBox, WebRTC, WebSocket, EventBus,
50
+ Browser, DataTable, Pagination, Navigation, DetailsSubArray, SelectAll, MultipleActionInTable, MultipleActionInDivList, EditValue, FormDate, InputPeriod, ShoppingCart, FlashMessage, CountDown, ImportFromCsv, JwtToken, JwtSession, ApiTokenSession, ListBox, WebRTC, WebSocket, EventBus,
51
51
  sleep, refresh, chr, ord, trim, empty,
52
52
  GoogleCharts, GoogleRecaptcha, GoogleMap, OpenStreetMap
53
53
  };
@@ -6,7 +6,7 @@ class MultipleActionInTable {
6
6
  return;
7
7
  }
8
8
 
9
- var divBtn = MultipleActionInTable.getDivBtn(table);
9
+ let divBtn = MultipleActionInTable.getDivBtn(table);
10
10
  if (divBtn == null) {
11
11
  return;
12
12
  }
@@ -26,23 +26,19 @@ class MultipleActionInTable {
26
26
  }
27
27
  });
28
28
 
29
- table.find('input.action_multiple_checkbox').each(function(idx, el) {
30
- var th = $(el).closest('table').find('thead tr th').first();
31
- if (th.find('input').length === 0) {
32
- // console.log(th);
33
- th.html('<input type="checkbox" class="action_multiple_check_all" />');
34
- // th.html('Coucou');
35
- }
36
- });
29
+ let firstTh = table.find('thead tr th').first();
30
+ if (firstTh.find('input').length === 0) {
31
+ firstTh.html('<input type="checkbox" class="action_multiple_check_all" />');
32
+ }
37
33
 
38
34
  table.find('input.action_multiple_checkbox').change(function() {
39
35
  MultipleActionInTable.updateCheckbox(table);
40
36
  });
41
37
 
42
38
  table.find('input.action_multiple_check_all').off('click').click(function() {
43
- var table = $(this).closest('table');
44
- var checkbox = table.find('input.action_multiple_checkbox');
45
- var checkboxChecked = table.find('input.action_multiple_checkbox:checked');
39
+ let table = $(this).closest('table');
40
+ let checkbox = table.find('input.action_multiple_checkbox');
41
+ let checkboxChecked = table.find('input.action_multiple_checkbox:checked');
46
42
  if (checkbox.length === checkboxChecked.length) {
47
43
  checkbox.prop('checked', false);
48
44
  }
@@ -58,9 +54,9 @@ class MultipleActionInTable {
58
54
  static updateCheckbox(table) {
59
55
  MultipleActionInTable.showButtonsAction(table);
60
56
 
61
- var allCheckbox = table.find('input.action_multiple_checkbox');
62
- var allCheckboxChecked = table.find('input.action_multiple_checkbox:checked');
63
- var checkboxSelectAll = table.find('thead tr th input.action_multiple_check_all');
57
+ let allCheckbox = table.find('input.action_multiple_checkbox');
58
+ let allCheckboxChecked = table.find('input.action_multiple_checkbox:checked');
59
+ let checkboxSelectAll = table.find('thead tr th input.action_multiple_check_all');
64
60
  if (allCheckbox.length === allCheckboxChecked.length) {
65
61
  checkboxSelectAll.prop('checked', true);
66
62
  }
@@ -70,8 +66,8 @@ class MultipleActionInTable {
70
66
  }
71
67
 
72
68
  static getDivBtn(table) {
73
- var divTableResponsive = table.parent();
74
- var divBtn = divTableResponsive.next();
69
+ let divTableResponsive = table.parent();
70
+ let divBtn = divTableResponsive.next();
75
71
  if (divBtn.hasClass('action_multiple_buttons')) {
76
72
  return divBtn;
77
73
  }
@@ -111,7 +107,107 @@ class MultipleActionInTable {
111
107
 
112
108
  }
113
109
 
114
- module.exports = { MultipleActionInTable };
110
+ class MultipleActionInDivList {
111
+ // init checkbox
112
+ static init(contentDiv) {
113
+ // Si aucune div sélectionnable, on n'applique pas le plugin
114
+ if (!contentDiv.find('.multiple_action').length) {
115
+ return;
116
+ }
117
+
118
+ let buttonsDiv = MultipleActionInDivList.getButtonsDiv(contentDiv);
119
+ if (buttonsDiv == null) {
120
+ return;
121
+ }
122
+
123
+ if (!buttonsDiv.data('action_multiple_buttons_initialized')) {
124
+ buttonsDiv.prepend($('<img src="'+ROOT_PATH+DOSSIER_IMAGES+'arrow_ltr.png" alt="" /> &nbsp;'));
125
+ buttonsDiv.append($('<br/><br/>'));
126
+ buttonsDiv.data('action_multiple_buttons_initialized', 1);
127
+ }
128
+
129
+ // Ajout checkbox pour chaque div sélectionnable
130
+ contentDiv.find('.multiple_action').each(function(idx, div) {
131
+ if ($(div).find('div.multi_select').length === 0) {
132
+ $(div).prepend($('<div class="multi_select float-start me-2"><input type="checkbox" class="action_multiple_checkbox" name="'+$(div).data('action_multiple_input_name')+'" value="'+$(div).data('action_multiple_item_id')+'"></div>'));
133
+ }
134
+ });
135
+
136
+ // Ajout checkbox select all
137
+ if (contentDiv.find('input.action_multiple_check_all').length === 0) {
138
+ contentDiv.prepend('<p class="mb-2"><input type="checkbox" class="action_multiple_check_all" /> Tout sélectionner</p>');
139
+ }
140
+
141
+ contentDiv.find('input.action_multiple_checkbox').change(function() {
142
+ MultipleActionInDivList.updateCheckbox(contentDiv);
143
+ });
144
+
145
+ contentDiv.find('input.action_multiple_check_all').off('click').click(function() {
146
+ let checkbox = contentDiv.find('input.action_multiple_checkbox');
147
+ let checkboxChecked = contentDiv.find('input.action_multiple_checkbox:checked');
148
+ if (checkbox.length === checkboxChecked.length) {
149
+ checkbox.prop('checked', false);
150
+ }
151
+ else {
152
+ checkbox.prop('checked', true);
153
+ }
154
+ MultipleActionInDivList.updateCheckbox(contentDiv);
155
+ });
156
+
157
+ MultipleActionInDivList.updateCheckbox(contentDiv);
158
+ }
159
+
160
+ static updateCheckbox(contentDiv) {
161
+ MultipleActionInDivList.showButtonsAction(contentDiv);
162
+
163
+ let allCheckbox = contentDiv.find('input.action_multiple_checkbox');
164
+ let allCheckboxChecked = contentDiv.find('input.action_multiple_checkbox:checked');
165
+ let checkboxSelectAll = contentDiv.find('input.action_multiple_check_all');
166
+ if (allCheckbox.length === allCheckboxChecked.length) {
167
+ checkboxSelectAll.prop('checked', true);
168
+ }
169
+ else {
170
+ checkboxSelectAll.prop('checked', false);
171
+ }
172
+ }
173
+
174
+ static getButtonsDiv(contentDiv) {
175
+ let buttonsDiv = contentDiv.next();
176
+ if (buttonsDiv.hasClass('action_multiple_buttons')) {
177
+ return buttonsDiv;
178
+ }
179
+ return null;
180
+ }
181
+
182
+ static showButtonsAction(contentDiv) {
183
+ let buttonsDiv = MultipleActionInDivList.getButtonsDiv(contentDiv);
184
+ if (buttonsDiv == null) {
185
+ return;
186
+ }
187
+
188
+ // console.log(divBtn);
189
+ //var nbItems = $('input[name="' + checkbox.attr('name') + '"]:checked').length;
190
+ let nbItems = contentDiv.find('input.action_multiple_checkbox:checked').length;
191
+
192
+ if (nbItems > 0 && buttonsDiv.is(':hidden')) {
193
+ buttonsDiv.removeClass('hide');
194
+ }
195
+ // 13/04/2021 : si le tableau est caché cela veut dire qu'il est en train de s'initialiser (après avoir chargé les données) et donc s'il n'y a pas de ligne sélectionnées, on cache la div buttons
196
+ else if ((nbItems === 0 && buttonsDiv.is(':visible')) || (nbItems === 0 && contentDiv.is(':hidden'))) {
197
+ buttonsDiv.addClass('hide');
198
+ }
199
+
200
+ // affichage aucune action possible si aucun bouton n'est visible
201
+ if (buttonsDiv.is(':visible')) {
202
+ buttonsDiv.find('span.no_button').remove();
203
+ if (buttonsDiv.find('button:visible, a:visible').length === 0) {
204
+ buttonsDiv.find('img').after('<span class="no_button"><em>aucune action possible</em></span>');
205
+ }
206
+ }
207
+ }
208
+ }
209
+
210
+ module.exports = { MultipleActionInTable, MultipleActionInDivList };
115
211
 
116
212
  /*
117
213
  // init checkbox
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.0.77",
3
+ "version": "1.0.78",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"