@osimatic/helpers-js 1.1.7 → 1.1.9

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/location.js CHANGED
@@ -345,6 +345,9 @@ class PostalAddress {
345
345
  addressDataForPluging['locality'] = addressData['stateDistrict'];
346
346
  }
347
347
 
348
+ //var Address = require("ilib/js/lib/Address");
349
+ //var AddressFmt = require("ilib/lib/AddressFmt");
350
+
348
351
  let af = new AddressFmt();
349
352
  let formattedAddress = af.format(new Address(addressDataForPluging));
350
353
  return formattedAddress.replace(/\n+/g, separator);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@osimatic/helpers-js",
3
+ "version": "1.1.7",
4
+ "main": "main.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },
8
+ "keywords": [],
9
+ "author": "",
10
+ "license": "ISC",
11
+ "description": "",
12
+ "dependencies": {
13
+ "ilib": "^14.16.0"
14
+ }
15
+ }
package/paging.js CHANGED
@@ -2,15 +2,15 @@
2
2
  //Bootstrap class pagination https://getbootstrap.com/docs/3.3/components/#pagination
3
3
 
4
4
  class Pagination {
5
- static paginateCards(div, nbItemsPerPage) {
6
- Pagination.paginate(div, div.find('.pagination_item'), nbItemsPerPage);
5
+ static paginateCards(div, nbItemsPerPage, doublePagination) {
6
+ Pagination.paginate(div, div.find('.pagination_item'), nbItemsPerPage, undefined, doublePagination);
7
7
  }
8
8
 
9
- static paginateTable(table, select) {
10
- Pagination.paginate(table, table.find('tbody tr:not(.hide)'), parseInt(table.data('max_rows')), select);
9
+ static paginateTable(table, select, doublePagination) {
10
+ Pagination.paginate(table, table.find('tbody tr:not(.hide)'), parseInt(table.data('max_rows')), select, doublePagination);
11
11
  }
12
12
 
13
- static paginate(div, items, nbItemsPerPage, select) {
13
+ static paginate(div, items, nbItemsPerPage, select, doublePagination) {
14
14
  let maxItems = nbItemsPerPage;
15
15
 
16
16
  if (typeof div == 'undefined' || !div.length) {
@@ -35,65 +35,83 @@ class Pagination {
35
35
  select.change(update);
36
36
  }
37
37
 
38
- let paginationUl = $('ul.pagination');
39
- if (!paginationUl.length) {
40
- paginationUl = $('<ul class="pagination"></ul>');
38
+ const ulPagination = $('ul.pagination');
39
+ if (doublePagination) {
40
+ ulPagination.each((index, ul) => $(ul).remove());
41
+ Pagination.initPaginationDiv(div, ulPagination, true, true); //top
42
+ Pagination.initPaginationDiv(div, ulPagination, false, true); //bottom
43
+ } else {
44
+ Pagination.initPaginationDiv(div, ulPagination, false, false); //bottom
45
+ }
46
+
47
+ Pagination.initPaginationItems(items, maxItems, doublePagination);
48
+ }
49
+
50
+ static initPaginationDiv(div, ulDiv, onTop, doublePagination) {
51
+ if (!ulDiv.length || doublePagination) {
52
+ ulDiv = $('<ul class="pagination"></ul>');
41
53
  if (div.find('.pagination_links').length) {
42
- div.find('.pagination_links').append(paginationUl);
43
- }
44
- else {
45
- div.after(paginationUl);
54
+ (onTop ? div.find('.pagination_links').prepend(ulDiv) : div.find('.pagination_links').append(ulDiv))
55
+ } else {
56
+ (onTop ? div.before(ulDiv) : div.after(ulDiv));
46
57
  }
47
58
  }
59
+ }
48
60
 
49
- function update() {
50
- let totalItems = items.length;
61
+ static initPaginationItems(items, maxItems, doublePagination) {
62
+ const paginationUl = $('ul.pagination');
51
63
 
52
- let lineNum = 0;
53
- items.each(function () {
54
- lineNum++;
55
- if (0 === maxItems || lineNum <= maxItems) {
56
- $(this).show();
57
- }
58
- else {
59
- $(this).hide();
60
- }
61
- });
62
- paginationUl.find('li').remove();
64
+ let totalItems = items.length;
63
65
 
64
- if (0 === maxItems || totalItems < maxItems) {
65
- paginationUl.addClass('hide');
66
- return;
66
+ let lineNum = 0;
67
+ items.each(function () {
68
+ lineNum++;
69
+ if (0 === maxItems || lineNum <= maxItems) {
70
+ $(this).show();
67
71
  }
68
-
69
- let nbPages = Math.ceil(totalItems/maxItems);
70
- for (let i=1; i <= nbPages; i++) {
71
- paginationUl.append('<li class="page-item" data-page="'+i+'"><a href="#" class="page-link">'+i+'<span class="sr-only">(current)</span></a></li>').show();
72
+ else {
73
+ $(this).hide();
72
74
  }
73
- paginationUl.removeClass('hide');
75
+ });
74
76
 
75
- paginationUl.find('li:first-child').addClass('active');
76
- paginationUl.find('li').click(function () {
77
- paginationUl.find('li').removeClass('active');
77
+ paginationUl.each((index, ul) => $(ul).find('li').remove());
78
78
 
79
- let pageNum = $(this).data('page');
80
- let trIndex = 0;
79
+ if (0 === maxItems || totalItems < maxItems) {
80
+ paginationUl.each((index, ul) => $(ul).addClass('hide'));
81
+ return;
82
+ }
83
+
84
+ let nbPages = Math.ceil(totalItems/maxItems);
85
+ for (let i=1; i <= nbPages; i++) {
86
+ paginationUl.each((index, ul) => $(ul).append('<li class="page-item" data-page="'+i+'"><a href="#" class="page-link">'+i+'<span class="sr-only">(current)</span></a></li>').show());
87
+ }
88
+
89
+ paginationUl.each((index, ul) => $(ul).removeClass('hide'));
90
+ paginationUl.each((index, ul) => $(ul).find('li:first-child').addClass('active'));
91
+ paginationUl.each((index, ul) => $(ul).find('li').click(function () {
92
+ paginationUl.each((index, ul) => $(ul).find('li').removeClass('active'));
93
+
94
+ let pageNum = $(this).data('page');
95
+ let trIndex = 0;
96
+
97
+ if (doublePagination) {
98
+ $('li[data-page="' + pageNum + '"]').each((index, li) => $(li).addClass('active'));
99
+ } else {
81
100
  $(this).addClass('active');
82
- items.each(function () {
83
- trIndex++;
84
- if (trIndex > (maxItems*pageNum) || trIndex <= ((maxItems*pageNum)-maxItems)) {
85
- $(this).hide();
86
- }
87
- else{
88
- $(this).show();
89
- }
90
- });
101
+ }
91
102
 
92
- return false;
103
+ items.each(function () {
104
+ trIndex++;
105
+ if (trIndex > (maxItems*pageNum) || trIndex <= ((maxItems*pageNum)-maxItems)) {
106
+ $(this).hide();
107
+ }
108
+ else{
109
+ $(this).show();
110
+ }
93
111
  });
94
- }
95
112
 
96
- update();
113
+ return false;
114
+ }));
97
115
  }
98
116
  }
99
117
 
package/paging.js.bak ADDED
@@ -0,0 +1,258 @@
1
+ // Fonction commune de pagination
2
+ //Bootstrap class pagination https://getbootstrap.com/docs/3.3/components/#pagination
3
+
4
+ class Pagination {
5
+ static paginateCards(div, nbItemsPerPage, doublePagination) {
6
+ Pagination.paginate(div, div.find('.pagination_item'), nbItemsPerPage, undefined, doublePagination);
7
+ }
8
+
9
+ static paginateTable(table, select, doublePagination) {
10
+ Pagination.paginate(table, table.find('tbody tr:not(.hide)'), parseInt(table.data('max_rows')), select, doublePagination);
11
+ }
12
+
13
+ static paginate(div, items, nbItemsPerPage, select, doublePagination) {
14
+ let maxItems = nbItemsPerPage;
15
+
16
+ if (typeof div == 'undefined' || !div.length) {
17
+ return;
18
+ }
19
+
20
+ if (typeof select != 'undefined' && select.length) {
21
+ if (!select.children().length) {
22
+ select.append('<option value="0">'+labelDisplayAll+'</option>');
23
+ let nbRowsList = select.data('nb_rows_list') ? select.data('nb_rows_list').split(',') : [5, 10, 25, 50];
24
+ $.each(nbRowsList, function(idx, nbRows) {
25
+ select.append('<option value="'+nbRows+'">'+nbRows+'</option>');
26
+ });
27
+
28
+ if (select.data('default_nb_rows')) {
29
+ select.val(select.data('default_nb_rows'))
30
+ }
31
+ }
32
+
33
+ maxItems = parseInt(select.val());
34
+
35
+ select.change(update);
36
+ }
37
+
38
+ if (doublePagination) {
39
+ Pagination.initPaginationDiv(div, $('ul.pagination'), true, true); //top
40
+ Pagination.initPaginationDiv(div, $('ul.pagination'), false, true); //bottom
41
+ } else {
42
+ Pagination.initPaginationDiv(div, $('ul.pagination'), false, false); //bottom
43
+ }
44
+
45
+ Pagination.initPaginationItems(items, maxItems, doublePagination);
46
+ }
47
+
48
+ static initPaginationDiv(div, ulDiv, onTop, doublePagination) {
49
+ if (!ulDiv.length || doublePagination) {
50
+ ulDiv = $('<ul class="pagination"></ul>');
51
+ if (div.find('.pagination_links').length) {
52
+ (onTop ? div.find('.pagination_links').prepend(ulDiv) : div.find('.pagination_links').append(ulDiv))
53
+ } else {
54
+ (onTop ? div.before(ulDiv) : div.after(ulDiv));
55
+ }
56
+ }
57
+ }
58
+
59
+ static initPaginationItems(items, maxItems, doublePagination) {
60
+ const paginationUl = $('ul.pagination');
61
+
62
+ let totalItems = items.length;
63
+
64
+ let lineNum = 0;
65
+ items.each(function () {
66
+ lineNum++;
67
+ if (0 === maxItems || lineNum <= maxItems) {
68
+ $(this).show();
69
+ }
70
+ else {
71
+ $(this).hide();
72
+ }
73
+ });
74
+
75
+ paginationUl.each((index, ul) => $(ul).find('li').remove());
76
+
77
+ if (0 === maxItems || totalItems < maxItems) {
78
+ paginationUl.each((index, ul) => $(ul).addClass('hide'));
79
+ return;
80
+ }
81
+
82
+ let nbPages = Math.ceil(totalItems/maxItems);
83
+ for (let i=1; i <= nbPages; i++) {
84
+ paginationUl.each((index, ul) => $(ul).append('<li class="page-item" data-page="'+i+'"><a href="#" class="page-link">'+i+'<span class="sr-only">(current)</span></a></li>').show());
85
+ }
86
+
87
+ paginationUl.each((index, ul) => $(ul).removeClass('hide'));
88
+ paginationUl.each((index, ul) => $(ul).find('li:first-child').addClass('active'));
89
+ paginationUl.each((index, ul) => $(ul).find('li').click(function () {
90
+ paginationUl.each((index, ul) => $(ul).find('li').removeClass('active'));
91
+
92
+ let pageNum = $(this).data('page');
93
+ let trIndex = 0;
94
+
95
+ if (doublePagination) {
96
+ $('li[data-page="' + pageNum + '"]').each((index, li) => $(li).addClass('active'));
97
+ } else {
98
+ $(this).addClass('active');
99
+ }
100
+
101
+ items.each(function () {
102
+ trIndex++;
103
+ if (trIndex > (maxItems*pageNum) || trIndex <= ((maxItems*pageNum)-maxItems)) {
104
+ $(this).hide();
105
+ }
106
+ else{
107
+ $(this).show();
108
+ }
109
+ });
110
+
111
+ return false;
112
+ }));
113
+ }
114
+ }
115
+
116
+ class Navigation {
117
+ static activateTab(a) {
118
+ //console.log(a);
119
+ //a.click();
120
+ let ulNav = a.closest('.nav');
121
+ let tabContent = ulNav.parent().find('.tab-content');
122
+
123
+ // déselection éventuel des onglets
124
+ ulNav.find('a.nav-link').each(function(idx, navLink) {
125
+ $(navLink).removeClass('active');
126
+ let id = $(navLink).attr('href');
127
+ if (id.substr(0, 1) === '#') {
128
+ tabContent.find(id).removeClass('active').removeClass('show');
129
+ }
130
+ });
131
+
132
+ // sélection de l'onglet correspondant au navLink passé en paramètre
133
+ a.addClass('active');
134
+ tabContent.find(a.attr('href')).addClass('active').addClass('show');
135
+ }
136
+ }
137
+
138
+ module.exports = { Pagination, Navigation };
139
+
140
+ // deprecated
141
+ /*
142
+ function paginationAsList(nbResultatsTotal, nbResultatsParPage, urlPage, nomParamPage) {
143
+ var currentUrl = urlPage || window.location.href;
144
+ var afficherLienFirstLastPage = true;
145
+ var afficherLienPagePrecedenteSuivante = true;
146
+ var emptyStringIfOnlyOnePage = true;
147
+ var nbLiensPageDebutFin = 3;
148
+ var nbLiensPageAvantApresPageCourante = 2;
149
+ var strEntreLiensPageDebutFinEtAvantApresPageCourante = '…';
150
+ nomParamPage = nomParamPage || 'page';
151
+
152
+ // Si le nombre de résultat total est inférieur au nombre d'affichage par page, il n'y a qu'une seule page.
153
+ if (nbResultatsTotal < nbResultatsParPage && emptyStringIfOnlyOnePage) {
154
+ return '';
155
+ }
156
+
157
+ // Initialisation du nombre de pages
158
+ var nbPages = Math.ceil(nbResultatsTotal/nbResultatsParPage);
159
+
160
+ // Initialisation du numéro de la page courante
161
+ //var query = window.location.search.substring(1).query.split("&");
162
+
163
+ var url = new URL(currentUrl);
164
+ var params = url.searchParams;
165
+
166
+ var numPageCourante = 1;
167
+ if (typeof params.get(nomParamPage) != 'undefined' && params.get(nomParamPage) != null) {
168
+ numPageCourante = parseInt(params.get(nomParamPage));
169
+ }
170
+ if (numPageCourante < 0) {
171
+ numPageCourante = 1;
172
+ }
173
+ if (numPageCourante > nbPages) {
174
+ numPageCourante = nbPages;
175
+ }
176
+
177
+ var strPagination = '<ul class="pagination">';
178
+
179
+ // Lien pour la première page
180
+ if (afficherLienFirstLastPage) {
181
+ var strLienFirstPage = '&lt;&lt;';
182
+ if (numPageCourante > 1) {
183
+ strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, 1, currentUrl)+'">'+strLienFirstPage+'</a></li>';
184
+ }
185
+ else {
186
+ strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strLienFirstPage+'</a></li>';
187
+ }
188
+ }
189
+
190
+ // Lien pour la page précédente
191
+ if (afficherLienPagePrecedenteSuivante) {
192
+ var strLienPagePrecedente = '&lt;';
193
+ if (numPageCourante > 1) {
194
+ strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, (numPageCourante - 1), currentUrl)+'">'+strLienPagePrecedente+'</a></li>';
195
+ }
196
+ else {
197
+ strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strLienPagePrecedente+'</a></li>';
198
+ }
199
+ }
200
+
201
+ var strEntreLiensPageDebutEtAvantPageCouranteDejaAffiche = false;
202
+ var strEntreLiensPageFinEtApresPageCouranteDejaAffiche = false;
203
+
204
+ for (var numPage=1; numPage<=nbPages; numPage++) {
205
+ if (numPage < numPageCourante) {
206
+ if (numPage <= nbLiensPageDebutFin || numPage >= (numPageCourante-nbLiensPageAvantApresPageCourante)) {
207
+ strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, numPage, currentUrl)+'">'+numPage+'</a></li>';
208
+ }
209
+ else {
210
+ if (!strEntreLiensPageDebutEtAvantPageCouranteDejaAffiche) {
211
+ strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strEntreLiensPageDebutFinEtAvantApresPageCourante+'</a></li>';
212
+ strEntreLiensPageDebutEtAvantPageCouranteDejaAffiche = true;
213
+ }
214
+ }
215
+ }
216
+ else if (numPage > numPageCourante) {
217
+ if (numPage >= (nbPages-(nbLiensPageDebutFin-1)) || numPage <= (numPageCourante+nbLiensPageAvantApresPageCourante)) {
218
+ strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, numPage, currentUrl)+'">'+numPage+'</a></li>';
219
+ }
220
+ else {
221
+ if (!strEntreLiensPageFinEtApresPageCouranteDejaAffiche) {
222
+ strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strEntreLiensPageDebutFinEtAvantApresPageCourante+'</a></li>';
223
+ strEntreLiensPageFinEtApresPageCouranteDejaAffiche = true;
224
+ }
225
+ }
226
+ }
227
+ else {
228
+ strPagination += '<li class="page-item active"><a class="page-link" href="#">'+numPage+'</a></li>';
229
+ }
230
+ }
231
+
232
+ // Lien pour la page suivante
233
+ if (afficherLienPagePrecedenteSuivante) {
234
+ var strLienPageSuivante = '&gt;';
235
+ if (numPageCourante < nbPages) {
236
+ strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, (numPageCourante + 1), currentUrl)+'">'+strLienPageSuivante+'</a></li>';
237
+ }
238
+ else {
239
+ strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strLienPageSuivante+'</a></li>';
240
+ }
241
+ }
242
+
243
+ // Lien pour la dernière page
244
+ if (afficherLienFirstLastPage) {
245
+ var strLienLastPage = '&gt;&gt;';
246
+ if (numPageCourante < nbPages) {
247
+ strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, nbPages, currentUrl)+'">'+strLienLastPage+'</a></li>';
248
+ }
249
+ else {
250
+ strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strLienLastPage+'</a></li>';
251
+ }
252
+ }
253
+
254
+ strPagination += '</ul>';
255
+
256
+ return strPagination;
257
+ }
258
+ */