@osimatic/helpers-js 1.0.10 → 1.0.13
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/bank.js +16 -1
- package/changelog.txt +1 -1
- package/duration.js +32 -28
- package/index.js +8 -5
- package/{todos/multiple_action_in_table.js → multiple_action_in_table.js} +1 -5
- package/network.js +3 -0
- package/package.json +1 -1
- package/paging.js +3 -1
- package/{todos/select_all.js → select_all.js} +1 -16
- package/shopping_cart.js +32 -0
package/bank.js
CHANGED
|
@@ -4,4 +4,19 @@ class IBAN {
|
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
class BankCard {
|
|
8
|
+
static formatCardNumber(cardNumber) {
|
|
9
|
+
if (cardNumber.length === 16) {
|
|
10
|
+
cardNumber = cardNumber.substring(0, 4)+'-'+cardNumber.substring(4, 8)+'-'+cardNumber.substring(8, 12)+'-'+cardNumber.substring(12, 16);
|
|
11
|
+
cardNumber = cardNumber.replace(/(\*)/gi, 'X');
|
|
12
|
+
}
|
|
13
|
+
return cardNumber;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static formatExpirationDate(expirationDate) {
|
|
17
|
+
let locale = typeof locale != 'undefined' ? locale : 'fr-FR';
|
|
18
|
+
return SqlDateTime.getMonthName(expirationDate, locale)+' '+SqlDateTime.getYear(expirationDate);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = { IBAN, BankCard };
|
package/changelog.txt
CHANGED
|
@@ -16,7 +16,7 @@ montant.formatAsCurrency(locale, currency, nbFractionDigits) -> montant.formatCu
|
|
|
16
16
|
number.formatAsPercent(locale, minimumFractionDigits) -> number.formatPercent(nbDecimal, locale)
|
|
17
17
|
|
|
18
18
|
constante COUNTRIES_LIST -> Country.getCountryList()
|
|
19
|
-
activateTab(...) ->
|
|
19
|
+
activateTab(...) -> Navigation.activateTab(...)
|
|
20
20
|
|
|
21
21
|
renameKeys(...) -> Object.renameKeys(...)
|
|
22
22
|
renameKeysByCallback(...) -> Object.renameKeysByCallback(...)
|
package/duration.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
class Duration {
|
|
3
3
|
|
|
4
|
-
static formatNbDays(nbDays) {
|
|
5
|
-
|
|
4
|
+
static formatNbDays(nbDays, locale) {
|
|
5
|
+
locale = (typeof locale != 'undefined'?locale:'fr-FR');
|
|
6
|
+
return new Intl.NumberFormat(locale, {
|
|
7
|
+
minimumFractionDigits: 2,
|
|
8
|
+
maximumFractionDigits: 2
|
|
9
|
+
}).format(nbDays);
|
|
6
10
|
}
|
|
7
11
|
static formatNbDaysIfPositive(nbDays) {
|
|
8
12
|
return nbDays < 0 ? '-' : this.formatNbDays(nbDays);
|
|
@@ -12,11 +16,11 @@ class Duration {
|
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
static convertToDurationAsCentieme(durationInSeconds) {
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
let hour = Math.floor(durationInSeconds / 3600);
|
|
20
|
+
let minutes = durationInSeconds % 3600;
|
|
17
21
|
minutes = Math.floor(minutes / 60);
|
|
18
22
|
// minutes = minutes - (minutes % 60);
|
|
19
|
-
|
|
23
|
+
let minCentieme = Math.round( (minutes / 60 ) * 100 );
|
|
20
24
|
return parseFloat(hour+'.'+minCentieme);
|
|
21
25
|
}
|
|
22
26
|
|
|
@@ -27,17 +31,17 @@ class Duration {
|
|
|
27
31
|
static convertToDurationInHourChronoDisplay(durationInSeconds, displayMode) {
|
|
28
32
|
displayMode = typeof displayMode != 'undefined' ? displayMode : 'chrono';
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
let durationInSecondsOriginal = durationInSeconds;
|
|
31
35
|
durationInSeconds = Math.abs(durationInSeconds);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
let seconds = ( durationInSeconds % 60 );
|
|
37
|
+
let remander = ( durationInSeconds % 3600 ) - seconds;
|
|
38
|
+
let minutes = ( remander / 60 );
|
|
35
39
|
remander = ( durationInSeconds ) - ( durationInSeconds % 3600 );
|
|
36
|
-
|
|
40
|
+
let hours = ( remander / 3600 );
|
|
37
41
|
if(hours.toString().length < 2) hours = '0'+hours;
|
|
38
|
-
if(hours.toString().charAt(0)
|
|
42
|
+
if(hours.toString().charAt(0) === "-") hours[0] = '0';
|
|
39
43
|
if(minutes.toString().length < 2) minutes = '0'+minutes;
|
|
40
|
-
if(minutes.toString().charAt(0)
|
|
44
|
+
if(minutes.toString().charAt(0) === "-") minutes[0] = '0';
|
|
41
45
|
if(seconds.toString().length < 2) seconds = '0'+seconds;
|
|
42
46
|
return (durationInSecondsOriginal < 0 ? '- ' : '')+hours+':'+minutes+(displayMode==='input_time'?':':'.')+seconds;
|
|
43
47
|
}
|
|
@@ -49,8 +53,8 @@ class Duration {
|
|
|
49
53
|
if (libelleEntier == null) libelleEntier = false;
|
|
50
54
|
|
|
51
55
|
// Heures
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
let strHeure = '';
|
|
57
|
+
let nbHeures = this.getNbHoursOfDurationInSeconds(durationInSeconds);
|
|
54
58
|
strHeure += nbHeures;
|
|
55
59
|
if (libelleEntier) {
|
|
56
60
|
strHeure += ' heure'+(nbHeures>1?'s':'');
|
|
@@ -60,8 +64,8 @@ class Duration {
|
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
// Minutes
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
let strMinute = '';
|
|
68
|
+
let nbMinutes = 0;
|
|
65
69
|
if (withMinutes) {
|
|
66
70
|
nbMinutes = this.getNbMinutesRemainingOfDurationInSeconds(durationInSeconds);
|
|
67
71
|
strMinute += ' ';
|
|
@@ -78,9 +82,9 @@ class Duration {
|
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
// Secondes
|
|
81
|
-
|
|
85
|
+
let strSeconde = '';
|
|
82
86
|
if (withSecondes) {
|
|
83
|
-
|
|
87
|
+
let nbSecondes = this.getNbSecondsRemainingOfDurationInSeconds(durationInSeconds);
|
|
84
88
|
strSeconde += ' ';
|
|
85
89
|
//strSeconde += sprintf('%02d', nbSecondes);
|
|
86
90
|
strSeconde += nbSecondes.toString().padStart(2, '0');
|
|
@@ -96,25 +100,25 @@ class Duration {
|
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
static roundNbSeconds(durationInSeconds, roundPrecision, roundMode) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
let hours = Math.floor(durationInSeconds / 3600);
|
|
104
|
+
let minutes = Math.floor((durationInSeconds % 3600) / 60);
|
|
105
|
+
let seconds = durationInSeconds % 60;
|
|
102
106
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
let hoursRounded = hours;
|
|
108
|
+
let minutesRounded = minutes;
|
|
109
|
+
let secondsRounded = seconds;
|
|
106
110
|
|
|
107
111
|
if (roundPrecision > 0) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (minutesRemainingAndSecondsAsCentieme
|
|
112
|
+
let minutesRemaining = minutes % roundPrecision;
|
|
113
|
+
let minutesRemainingAndSecondsAsCentieme = minutesRemaining + seconds/60;
|
|
114
|
+
if (minutesRemainingAndSecondsAsCentieme === 0) {
|
|
111
115
|
// pas d'arrondissement
|
|
112
116
|
}
|
|
113
117
|
else {
|
|
114
118
|
var halfRoundPrecision = roundPrecision / 2;
|
|
115
119
|
hoursRounded = hours;
|
|
116
120
|
secondsRounded = 0;
|
|
117
|
-
if (roundMode
|
|
121
|
+
if (roundMode === 'up' || (roundMode === 'close' && minutesRemainingAndSecondsAsCentieme > halfRoundPrecision)) {
|
|
118
122
|
// Arrondissement au dessus
|
|
119
123
|
if (minutes > (60-roundPrecision)) {
|
|
120
124
|
minutesRounded = 0;
|
package/index.js
CHANGED
|
@@ -7,7 +7,7 @@ require('./array');
|
|
|
7
7
|
|
|
8
8
|
// exports d'ojets non natif
|
|
9
9
|
const { HTTPRequest, Cookie, UrlAndQueryString } = require('./network');
|
|
10
|
-
const { IBAN } = require('./bank');
|
|
10
|
+
const { IBAN, BankCard } = require('./bank');
|
|
11
11
|
const { AudioMedia } = require('./media');
|
|
12
12
|
const { PersonName, Email, TelephoneNumber } = require('./contact_details');
|
|
13
13
|
const { DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, InputPeriod } = require('./date_time');
|
|
@@ -21,10 +21,13 @@ const { chr, ord, trim, empty } = require('./php.min');
|
|
|
21
21
|
|
|
22
22
|
// exports plugins "maison"
|
|
23
23
|
const { DataTable } = require('./data_table');
|
|
24
|
-
const { Pagination,
|
|
24
|
+
const { Pagination, Navigation } = require('./paging');
|
|
25
|
+
const { DetailsSubArray } = require('./details_sub_array');
|
|
26
|
+
const { SelectAll } = require('./select_all');
|
|
27
|
+
const { MultipleActionInTable } = require('./multiple_action_in_table');
|
|
28
|
+
const { ShoppingCart } = require('./shopping_cart');
|
|
25
29
|
const { FlashMessage } = require('./flash_message');
|
|
26
30
|
const { CountDown } = require('./count_down');
|
|
27
|
-
const { DetailsSubArray } = require('./details_sub_array');
|
|
28
31
|
const { ImportFromCsv } = require('./import_from_csv');
|
|
29
32
|
const { JwtToken, JwtSession } = require('./jwt');
|
|
30
33
|
const { ListBox } = require('./list_box');
|
|
@@ -40,8 +43,8 @@ const { NumberValue } = require('./number');
|
|
|
40
43
|
|
|
41
44
|
module.exports = {
|
|
42
45
|
Array, Object, Number, String,
|
|
43
|
-
HTTPRequest, Cookie, UrlAndQueryString, IBAN, AudioMedia, PersonName, Email, TelephoneNumber, DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, InputPeriod, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, Location, SocialNetwork, NumberValue,
|
|
44
|
-
DataTable, Pagination, FlashMessage, CountDown,
|
|
46
|
+
HTTPRequest, Cookie, UrlAndQueryString, IBAN, BankCard, AudioMedia, PersonName, Email, TelephoneNumber, DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, InputPeriod, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, Location, SocialNetwork, NumberValue,
|
|
47
|
+
DataTable, Pagination, Navigation, DetailsSubArray, SelectAll, MultipleActionInTable, ShoppingCart, FlashMessage, CountDown, ImportFromCsv, JwtToken, JwtSession, ListBox,
|
|
45
48
|
sleep, refresh, chr, ord, trim, empty,
|
|
46
49
|
GoogleCharts, GoogleRecaptcha, GoogleMap, OpenStreetMap
|
|
47
50
|
};
|
|
@@ -111,11 +111,7 @@ class MultipleActionInTable {
|
|
|
111
111
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
$('table.table-action_multiple').each(function(idx, table) {
|
|
116
|
-
MultipleActionInTable.init($(table));
|
|
117
|
-
});
|
|
118
|
-
});
|
|
114
|
+
module.exports = { MultipleActionInTable };
|
|
119
115
|
|
|
120
116
|
/*
|
|
121
117
|
// init checkbox
|
package/network.js
CHANGED
|
@@ -36,6 +36,7 @@ class HTTPRequest {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
catch (e) {
|
|
39
|
+
console.log(e);
|
|
39
40
|
errorCallback(response, response.status, e);
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
@@ -101,6 +102,7 @@ class HTTPRequest {
|
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
catch (e) {
|
|
105
|
+
console.log(e);
|
|
104
106
|
if (typeof errorCallback != 'undefined' && errorCallback != null) {
|
|
105
107
|
errorCallback(response, response.status, e);
|
|
106
108
|
}
|
|
@@ -170,6 +172,7 @@ class HTTPRequest {
|
|
|
170
172
|
}
|
|
171
173
|
}
|
|
172
174
|
catch (e) {
|
|
175
|
+
console.log(e);
|
|
173
176
|
errorCallback(response, response.status, e);
|
|
174
177
|
return;
|
|
175
178
|
}
|
package/package.json
CHANGED
package/paging.js
CHANGED
|
@@ -95,7 +95,9 @@ class Pagination {
|
|
|
95
95
|
|
|
96
96
|
update();
|
|
97
97
|
}
|
|
98
|
+
}
|
|
98
99
|
|
|
100
|
+
class Navigation {
|
|
99
101
|
static activateTab(a) {
|
|
100
102
|
//console.log(a);
|
|
101
103
|
//a.click();
|
|
@@ -117,7 +119,7 @@ class Pagination {
|
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
|
|
120
|
-
module.exports = { Pagination };
|
|
122
|
+
module.exports = { Pagination, Navigation };
|
|
121
123
|
|
|
122
124
|
// deprecated
|
|
123
125
|
/*
|
|
@@ -114,19 +114,4 @@ class SelectAll {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
// Dans un form-group
|
|
119
|
-
$('a.check_all').each(function(idx, link) {
|
|
120
|
-
SelectAll.initLinkInFormGroup($(link));
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// Dans tableau
|
|
124
|
-
$('table tr input.check_all').each(function(idx, inputCheckAll) {
|
|
125
|
-
SelectAll.initInTable($(inputCheckAll).closest('table'));
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// Dans un div
|
|
129
|
-
$('div.checkbox_with_check_all').each(function(idx, div) {
|
|
130
|
-
SelectAll.initDiv($(div));
|
|
131
|
-
});
|
|
132
|
-
});
|
|
117
|
+
module.exports = { SelectAll };
|
package/shopping_cart.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
class ShoppingCart {
|
|
2
|
+
static addProduct(productId, quantity, data) {
|
|
3
|
+
let cart = this.getCart();
|
|
4
|
+
let item = cart.find(element => element.product_id == productId);
|
|
5
|
+
if (typeof item != 'undefined') {
|
|
6
|
+
cart.unsetVal(item);
|
|
7
|
+
quantity += item.quantity;
|
|
8
|
+
}
|
|
9
|
+
cart.push({product_id: productId, quantity: quantity, data: data});
|
|
10
|
+
localStorage.setItem('cart', JSON.stringify(cart));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static deleteProduct(productId) {
|
|
14
|
+
let cart = this.getCart();
|
|
15
|
+
cart.unsetVal(cart.find(element => element.product_id == productId));
|
|
16
|
+
localStorage.setItem('cart', JSON.stringify(cart));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static removeAllItems() {
|
|
20
|
+
localStorage.removeItem('cart');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static getCart() {
|
|
24
|
+
let cart = [];
|
|
25
|
+
if (localStorage.getItem('cart') != null) {
|
|
26
|
+
cart = JSON.parse(localStorage.getItem('cart'));
|
|
27
|
+
}
|
|
28
|
+
return cart;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = { ShoppingCart };
|