@osimatic/helpers-js 1.0.11 → 1.0.14
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/index.js +7 -4
- package/media.js +96 -10
- 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/{todos/select_all.js → select_all.js} +1 -16
- package/shopping_cart.js +32 -0
- package/.idea/helpers-js.iml +0 -8
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
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/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');
|
|
@@ -22,9 +22,12 @@ const { chr, ord, trim, empty } = require('./php.min');
|
|
|
22
22
|
// exports plugins "maison"
|
|
23
23
|
const { DataTable } = require('./data_table');
|
|
24
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, Navigation, 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
|
};
|
package/media.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
class AudioMedia {
|
|
2
2
|
|
|
3
3
|
static getPlayer(playUrl) {
|
|
4
|
-
return '<audio controls preload="none"><source src="'+playUrl+'" type="audio/x-wav"></audio>';
|
|
4
|
+
return '<audio controls preload="none"><source src="' + playUrl + '" type="audio/x-wav"></audio>';
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
static initPlayLinks(div) {
|
|
8
8
|
// Affiche un lecteur audio
|
|
9
|
-
div.find('.play_link').off('click').click(function() {
|
|
9
|
+
div.find('.play_link').off('click').click(function () {
|
|
10
10
|
let audio = $(AudioMedia.getPlayer($(this).data('play_url')));
|
|
11
11
|
audio[0].play();
|
|
12
12
|
$(this).after(audio);
|
|
@@ -14,7 +14,7 @@ class AudioMedia {
|
|
|
14
14
|
return false;
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
div.find('.play_asynchronously_link').off('click').click(function() {
|
|
17
|
+
div.find('.play_asynchronously_link').off('click').click(function () {
|
|
18
18
|
if ($(this).buttonLoader('loading') != null) {
|
|
19
19
|
let button = $(this).buttonLoader('loading');
|
|
20
20
|
AudioMedia.playAudioUrl($(this).data('url'), () => button.buttonLoader('reset'));
|
|
@@ -22,11 +22,11 @@ class AudioMedia {
|
|
|
22
22
|
let button = $(this).attr('disabled', true).button('loading');
|
|
23
23
|
AudioMedia.playAudioUrl($(this).data('url'), () => button.attr('disabled', false).button('reset'));
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
return false;
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
div.find('.modal_play_link').off('click').click(function() {
|
|
29
|
+
div.find('.modal_play_link').off('click').click(function () {
|
|
30
30
|
$('#modal_voice_message_play').on('show.bs.modal', function (event) {
|
|
31
31
|
let button = $(event.relatedTarget);
|
|
32
32
|
let modal = $(this);
|
|
@@ -49,15 +49,15 @@ class AudioMedia {
|
|
|
49
49
|
Object.entries(httpHeaders).forEach(([key, value]) => request.setRequestHeader(key, value));
|
|
50
50
|
request.responseType = "arraybuffer";
|
|
51
51
|
|
|
52
|
-
request.onload = function() {
|
|
53
|
-
context.decodeAudioData(request.response, function(buffer) {
|
|
52
|
+
request.onload = function () {
|
|
53
|
+
context.decodeAudioData(request.response, function (buffer) {
|
|
54
54
|
let source = context.createBufferSource();
|
|
55
55
|
source.buffer = buffer;
|
|
56
56
|
source.connect(context.destination);
|
|
57
57
|
// auto play
|
|
58
58
|
source.start(0); // start was previously noteOn
|
|
59
59
|
|
|
60
|
-
source.onended = function(event) {
|
|
60
|
+
source.onended = function (event) {
|
|
61
61
|
if (typeof onPlayed == 'function') {
|
|
62
62
|
onPlayed(event);
|
|
63
63
|
}
|
|
@@ -66,7 +66,7 @@ class AudioMedia {
|
|
|
66
66
|
};
|
|
67
67
|
request.send();
|
|
68
68
|
}
|
|
69
|
-
catch(e) {
|
|
69
|
+
catch (e) {
|
|
70
70
|
console.log(e);
|
|
71
71
|
console.log('web audio api not supported');
|
|
72
72
|
}
|
|
@@ -74,7 +74,93 @@ class AudioMedia {
|
|
|
74
74
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
//Source : https://www.npmjs.com/package/mic-check
|
|
78
|
+
class UserMedia {
|
|
79
|
+
/** SystemPermissionDenied => (macOS) browser does not have permission to access cam/mic */
|
|
80
|
+
/** UserPermissionDenied => user denied permission for site to access cam/mic */
|
|
81
|
+
/** CouldNotStartVideoSource = > (Windows) browser does not have permission to access cam/mic OR camera is in use by another application or browser tab */
|
|
82
|
+
/** Generic => all other errors */
|
|
83
|
+
|
|
84
|
+
static requestMediaPermissions(constraints) {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
let userAgent = navigator.userAgent;
|
|
87
|
+
let browser;
|
|
88
|
+
|
|
89
|
+
if (userAgent.match(/chrome|chromium|crios/i)) {
|
|
90
|
+
browser = "Chrome";
|
|
91
|
+
} else if (userAgent.match(/firefox|fxios/i)) {
|
|
92
|
+
browser = "firefox";
|
|
93
|
+
} else if (userAgent.match(/safari/i)) {
|
|
94
|
+
browser = "Safari";
|
|
95
|
+
} else if(userAgent.match(/opr\//i)) {
|
|
96
|
+
browser = "Opera";
|
|
97
|
+
} else if (userAgent.match(/edg/i)) {
|
|
98
|
+
browser = "Edge";
|
|
99
|
+
} else {
|
|
100
|
+
browser = "No browser detection";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
navigator.mediaDevices.getUserMedia(constraints !== 'undefined' ? constraints : { audio: true, video: true })
|
|
104
|
+
.then((stream) => {
|
|
105
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
106
|
+
resolve();
|
|
107
|
+
}).catch((error) => {
|
|
108
|
+
const errName = error.name;
|
|
109
|
+
const errMessage = error.message;
|
|
110
|
+
let errorType = "Generic";
|
|
111
|
+
|
|
112
|
+
if (browser === 'Chrome') {
|
|
113
|
+
if (errName === 'NotAllowedError') {
|
|
114
|
+
if (errMessage === 'Permission denied by system') {
|
|
115
|
+
errorType = "SystemPermissionDenied";
|
|
116
|
+
} else if (errMessage === 'Permission denied') {
|
|
117
|
+
errorType = "UserPermissionDenied";
|
|
118
|
+
}
|
|
119
|
+
} else if (errName === 'NotReadableError') {
|
|
120
|
+
errorType = "CouldNotStartVideoSource";
|
|
121
|
+
}
|
|
122
|
+
} else if (browser === 'Safari') {
|
|
123
|
+
if (errName === 'NotAllowedError') {
|
|
124
|
+
errorType = "UserPermissionDenied";
|
|
125
|
+
}
|
|
126
|
+
} else if (browser === 'Microsoft Edge') {
|
|
127
|
+
if (errName === 'NotAllowedError') {
|
|
128
|
+
errorType = "UserPermissionDenied";
|
|
129
|
+
} else if (errName === 'NotReadableError') {
|
|
130
|
+
errorType = "CouldNotStartVideoSource";
|
|
131
|
+
}
|
|
132
|
+
} else if (browser === 'Firefox') {
|
|
133
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#exceptions
|
|
134
|
+
if (errName === 'NotFoundError') {
|
|
135
|
+
errorType = "SystemPermissionDenied";
|
|
136
|
+
} else if (errName === 'NotReadableError') {
|
|
137
|
+
errorType = "SystemPermissionDenied";
|
|
138
|
+
} else if (errName === 'NotAllowedError') {
|
|
139
|
+
errorType = "UserPermissionDenied";
|
|
140
|
+
} else if (errName === 'AbortError') {
|
|
141
|
+
errorType = "CouldNotStartVideoSource";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
reject({ type: errorType, name: error.name, message: error.message });
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static requestAudioPermissions(audioConstraints) {
|
|
151
|
+
return this.requestMediaPermissions({ audio: (audioConstraints !== 'undefined' ? audioConstraints : true), video: false });
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
static requestVideoPermissions(audioConstraints, videoConstraints) {
|
|
155
|
+
return this.requestMediaPermissions({ audio: (audioConstraints !== 'undefined' ? audioConstraints : true), video: (videoConstraints !== 'undefined' ? videoConstraints : true )});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
static requestMutedVideoPermissions(videoConstraints) {
|
|
159
|
+
return this.requestMediaPermissions({ audio: false, video: (videoConstraints !== 'undefined' ? videoConstraints : true )});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
module.exports = { AudioMedia, UserMedia };
|
|
78
164
|
|
|
79
165
|
//deprecated
|
|
80
166
|
function hasGetUserMedia() {
|
|
@@ -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
|
@@ -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 };
|
package/.idea/helpers-js.iml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="WEB_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$" />
|
|
5
|
-
<orderEntry type="inheritedJdk" />
|
|
6
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
|
-
</component>
|
|
8
|
-
</module>
|
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/helpers-js.iml" filepath="$PROJECT_DIR$/.idea/helpers-js.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|