@osimatic/helpers-js 1.1.18 → 1.1.20

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
@@ -21,6 +21,7 @@ const { HexColor, RgbColor } = require('./draw');
21
21
  const { SocialNetwork } = require('./social_network');
22
22
  const { sleep, refresh } = require('./util');
23
23
  const { chr, ord, trim, empty } = require('./php.min');
24
+ const { NumberFormatter } = require('./number');
24
25
 
25
26
  // exports plugins "maison"
26
27
  const { Browser, UserAgent } = require('./visitor');
@@ -48,7 +49,7 @@ const { WebSocket } = require('./web_socket');
48
49
 
49
50
  module.exports = {
50
51
  Array, Object, Number, String,
51
- HTTPClient, HTTPRequest, Cookie, UrlAndQueryString, IBAN, BankCard, AudioMedia, VideoMedia, UserMedia, PersonName, Email, TelephoneNumber, DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, GeographicCoordinates, HexColor, RgbColor, SocialNetwork,
52
+ HTTPClient, HTTPRequest, Cookie, UrlAndQueryString, IBAN, BankCard, AudioMedia, VideoMedia, UserMedia, PersonName, Email, TelephoneNumber, DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, GeographicCoordinates, HexColor, RgbColor, SocialNetwork, NumberFormatter
52
53
  Browser, DataTable, Pagination, Navigation, DetailsSubArray, SelectAll, MultipleActionInTable, MultipleActionInDivList, EditValue, FormDate, InputPeriod, ShoppingCart, FlashMessage, CountDown, ImportFromCsv, JwtToken, JwtSession, ApiTokenSession, ListBox, WebRTC, WebSocket, EventBus,
53
54
  sleep, refresh, chr, ord, trim, empty,
54
55
  GoogleCharts, GoogleRecaptcha, GoogleMap, OpenStreetMap
package/number.js CHANGED
@@ -1,3 +1,31 @@
1
+ class NumberFormatter {
2
+ static getDecimalFormatter(locale, digits = 2) {
3
+ this.decimalFormatter = this.decimalFormatter || {};
4
+ if (typeof this.decimalFormatter[locale+digits] == 'undefined') {
5
+ this.decimalFormatter[locale+digits] = new Intl.NumberFormat(locale, { minimumFractionDigits: digits, maximumFractionDigits: digits });
6
+ }
7
+
8
+ return this.decimalFormatter[locale+digits];
9
+ }
10
+
11
+ static getCurrencyFormatter(locale, currency, digits = 2) {
12
+ this.currencyFormatter = this.currencyFormatter || {};
13
+ if (typeof this.currencyFormatter[locale+currency+digits] == 'undefined') {
14
+ this.currencyFormatter[locale+currency+digits] = new Intl.NumberFormat(locale, { minimumFractionDigits: digits, maximumFractionDigits: digits, style: 'currency', currency });
15
+ }
16
+
17
+ return this.currencyFormatter[locale+currency+digits];
18
+ }
19
+
20
+ static getPercentFormatter(locale, digits = 2) {
21
+ this.percentFormatter = this.percentFormatter || {};
22
+ if (typeof this.percentFormatter[locale+digits] == 'undefined') {
23
+ this.percentFormatter[locale+digits] = new Intl.NumberFormat(locale, { minimumFractionDigits: digits, maximumFractionDigits: digits, style: 'percent' });
24
+ }
25
+
26
+ return this.percentFormatter[locale+digits];
27
+ }
28
+ }
1
29
 
2
30
  Number.prototype.format = Number.prototype.format || function(nbDecimal, locale) {
3
31
  return Number.format(this, nbDecimal, locale);
@@ -5,14 +33,26 @@ Number.prototype.format = Number.prototype.format || function(nbDecimal, locale)
5
33
 
6
34
  if (!Number.format) {
7
35
  Number.format = function(number, nbDecimal, locale) {
8
- nbDecimal = (typeof nbDecimal != 'undefined'?nbDecimal:2);
9
- return new Intl.NumberFormat(locale, {
10
- minimumFractionDigits: nbDecimal,
11
- maximumFractionDigits: nbDecimal
12
- }).format(number);
36
+ return NumberFormatter.getDecimalFormatter(locale, (typeof nbDecimal != 'undefined' ? nbDecimal : 2)).format(number);
13
37
  };
14
38
  }
15
39
 
40
+ Number.prototype.formatCurrency = Number.prototype.formatCurrency || function(currency, nbDecimal, locale) {
41
+ return Number.formatCurrency(this, currency, nbDecimal, locale);
42
+ }
43
+
44
+ Number.formatCurrency = Number.formatCurrency || function(number, currency, nbDecimal, locale) {
45
+ return NumberFormatter.getCurrencyFormatter(locale, currency, (typeof nbDecimal != 'undefined' ? nbDecimal : 2)).format(number);
46
+ }
47
+
48
+ Number.prototype.formatPercent = Number.prototype.formatPercent || function(nbDecimal, locale) {
49
+ return Number.formatPercent(this, nbDecimal, locale);
50
+ }
51
+
52
+ Number.formatPercent = Number.formatPercent || function(number, nbDecimal, locale) {
53
+ return NumberFormatter.getPercentFormatter(locale, (typeof nbDecimal != 'undefined'?nbDecimal:2)).format(number);
54
+ }
55
+
16
56
  /**
17
57
  * Number.prototype.format(n, x, s, c)
18
58
  *
@@ -27,31 +67,6 @@ Number.prototype.formatForDisplay = Number.prototype.formatForDisplay || functio
27
67
  return (c ? num.replace('.', c) : num).replace(new RegExp(re, 'g'), '$&' + (s || ','));
28
68
  };
29
69
 
30
- Number.prototype.formatCurrency = Number.prototype.formatCurrency || function(currency, nbDecimal, locale) {
31
- return Number.formatCurrency(this, currency, nbDecimal, locale);
32
- }
33
- Number.formatCurrency = Number.formatCurrency || function(number, currency, nbDecimal, locale) {
34
- nbDecimal = (typeof nbDecimal != 'undefined'?nbDecimal:2);
35
- return new Intl.NumberFormat(locale, {
36
- style: 'currency',
37
- currency: currency,
38
- minimumFractionDigits: nbDecimal,
39
- maximumFractionDigits: nbDecimal
40
- }).format(number);
41
- }
42
-
43
- Number.prototype.formatPercent = Number.prototype.formatPercent || function(nbDecimal, locale) {
44
- return Number.formatPercent(this, nbDecimal, locale);
45
- }
46
- Number.formatPercent = Number.formatPercent || function(number, nbDecimal, locale) {
47
- nbDecimal = (typeof nbDecimal != 'undefined'?nbDecimal:2);
48
- return new Intl.NumberFormat(locale, {
49
- style: 'percent',
50
- minimumFractionDigits: nbDecimal,
51
- maximumFractionDigits: nbDecimal
52
- }).format(number);
53
- }
54
-
55
70
  Number.prototype.padLeft2 = Number.prototype.padLeft2 || function() {
56
71
  return Number.padLeft2(this);
57
72
  }
@@ -73,3 +88,5 @@ if (!Number.random) {
73
88
  return Math.floor(Math.random() * (max - min + 1)) + min;
74
89
  };
75
90
  }
91
+
92
+ module.exports = { NumberFormatter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.1.18",
3
+ "version": "1.1.20",
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.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
+ */
package/select_all.js CHANGED
@@ -95,9 +95,7 @@ class SelectAll {
95
95
  div.find('div.checkbox, div.form-check').find('input[type="checkbox"]').change(function() {
96
96
  SelectAll.updateDiv($(this).closest('div.checkbox_with_check_all'));
97
97
  });
98
- div.find('div.checkbox_with_check_all').each(function(idx, divWithCheckAll) {
99
- SelectAll.updateDiv($(divWithCheckAll));
100
- });
98
+ SelectAll.updateDiv(div);
101
99
  }
102
100
 
103
101
  static updateDiv(div) {