@osimatic/helpers-js 1.0.7 → 1.0.10
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/.idea/helpers-js.iml +8 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README +1 -0
- package/array.js +4 -6
- package/changelog.txt +28 -0
- package/flash_message.js +1 -2
- package/form_helper.js +20 -0
- package/{todos/google_charts.js → google_charts.js} +11 -8
- package/google_maps.js +1 -1
- package/google_recaptcha.js +78 -0
- package/index.js +29 -17
- package/location.js +249 -251
- package/number.js +69 -7
- package/open_street_map.js +132 -0
- package/package.json +1 -1
- package/paging.js +21 -20
- package/string.js +92 -52
- package/util.js +1 -9
- package/todos/google_charts_mytime.js +0 -295
- package/todos/google_recaptcha.js +0 -15
|
@@ -0,0 +1,8 @@
|
|
|
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>
|
|
@@ -0,0 +1,8 @@
|
|
|
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>
|
package/.idea/vcs.xml
ADDED
package/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npm install @osimatic/helpers-js
|
package/array.js
CHANGED
|
@@ -42,7 +42,7 @@ Array.prototype.filterUnique = function() {
|
|
|
42
42
|
return this.filter((v, i, a) => a.indexOf(v) === i);
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
function
|
|
45
|
+
Array.getValuesByKeyInArrayOfArrays = function(array, key) {
|
|
46
46
|
let listeValues = [];
|
|
47
47
|
for (let i in array) {
|
|
48
48
|
let subArray = array[i];
|
|
@@ -63,7 +63,7 @@ Object.filter = (obj, predicate) => {
|
|
|
63
63
|
.reduce( (res, key) => (res[key] = obj[key], res), {} );
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
function
|
|
66
|
+
Object.renameKeys = function(obj, keysMap) {
|
|
67
67
|
return Object.keys(obj).reduce(
|
|
68
68
|
(acc, key) => ({
|
|
69
69
|
...acc,
|
|
@@ -71,9 +71,9 @@ function renameKeys(obj, keysMap) {
|
|
|
71
71
|
}),
|
|
72
72
|
{}
|
|
73
73
|
);
|
|
74
|
-
}
|
|
74
|
+
};
|
|
75
75
|
|
|
76
|
-
function
|
|
76
|
+
Object.renameKeysByCallback = function(obj, callback) {
|
|
77
77
|
return Object.keys(obj).reduce(
|
|
78
78
|
(acc, key) => ({
|
|
79
79
|
...acc,
|
|
@@ -82,5 +82,3 @@ function renameKeysByCallback(obj, callback) {
|
|
|
82
82
|
{}
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
module.exports = { getValuesByKeyInArrayOfArrays, renameKeys, renameKeysByCallback };
|
package/changelog.txt
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
1.0.9 :
|
|
3
|
+
copierTexte(str) -> str.copyToClipboard()
|
|
4
|
+
truncateString(str, ...) -> str.truncateString(...)
|
|
5
|
+
|
|
6
|
+
NumberValue.isNumeric(str) -> str.isNumeric()
|
|
7
|
+
NumberValue.format(number, nbDecimal, locale) -> number.format(nbDecimal, locale) OU Number.format(number, nbDecimal, locale)
|
|
8
|
+
NumberValue.formatCurrency(montant, currency, nbDecimal, locale) -> montant.formatCurrency(currency, nbDecimal, locale)
|
|
9
|
+
NumberValue.formatPercent(number, nbDecimal, locale) -> number.formatPercent(nbDecimal, locale)
|
|
10
|
+
NumberValue.random(min, max) -> Number.random(min, max)
|
|
11
|
+
NumberValue.padLeft2(n) -> n.padLeft2()
|
|
12
|
+
NumberValue.roundDecimal(nombre, precision) -> nombre.roundDecimal(precision)
|
|
13
|
+
|
|
14
|
+
nombre.formatAsString(locale, minimumFractionDigits) -> nombre.format(nbDecimal, locale)
|
|
15
|
+
montant.formatAsCurrency(locale, currency, nbFractionDigits) -> montant.formatCurrency(currency, nbDecimal, locale)
|
|
16
|
+
number.formatAsPercent(locale, minimumFractionDigits) -> number.formatPercent(nbDecimal, locale)
|
|
17
|
+
|
|
18
|
+
constante COUNTRIES_LIST -> Country.getCountryList()
|
|
19
|
+
activateTab(...) -> Pagination.activateTab(...)
|
|
20
|
+
|
|
21
|
+
renameKeys(...) -> Object.renameKeys(...)
|
|
22
|
+
renameKeysByCallback(...) -> Object.renameKeysByCallback(...)
|
|
23
|
+
getValuesByKeyInArrayOfArrays(...) -> Array.getValuesByKeyInArrayOfArrays(...)
|
|
24
|
+
getValuesByKeyInArrayOfArrays(array, ...) -> array.getValuesByKeyInArrayOfArrays(...)
|
|
25
|
+
|
|
26
|
+
hasGetUserMedia() -> non remplacé
|
|
27
|
+
|
|
28
|
+
paginationAsList(...) -> Pagination.paginate(...)
|
package/flash_message.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
class FlashMessage {
|
|
2
|
-
|
|
3
2
|
static displayRequestFailure(status, exception, modal) {
|
|
4
3
|
console.log('request failure. Status: ', status, ' Exception: ', exception);
|
|
5
|
-
this.display('danger', "Une erreur s'est produite.", false, modal);
|
|
4
|
+
this.display('danger', typeof labelErrorOccured != 'undefined' ? labelErrorOccured : "Une erreur s'est produite.", false, modal);
|
|
6
5
|
}
|
|
7
6
|
|
|
8
7
|
static displaySuccess(message, reload, modal) {
|
package/form_helper.js
CHANGED
|
@@ -161,6 +161,26 @@ class FormHelper {
|
|
|
161
161
|
// Messages
|
|
162
162
|
// ------------------------------------------------------------
|
|
163
163
|
|
|
164
|
+
static extractErrorKeyOfJson(json, onlyIfUniqueError) {
|
|
165
|
+
if (typeof json == 'undefined' || json == null) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (typeof json.error != 'undefined') {
|
|
170
|
+
return json.error;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (typeof onlyIfUniqueError != 'undefined' && onlyIfUniqueError && !json.length || json.length > 1) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (typeof json[0] != 'undefined' && typeof json[0].error != 'undefined') {
|
|
178
|
+
return json[0].error;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
|
|
164
184
|
static hideFormErrors(form) {
|
|
165
185
|
form.find('div.form_errors').remove();
|
|
166
186
|
return form;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
class GoogleCharts {
|
|
2
|
+
static init(onLoadCallback) {
|
|
3
|
+
// google.load("visualization", "1", {packages:["corechart"]});
|
|
4
|
+
google.charts.load('current', {'packages':['bar','line','corechart']});
|
|
5
|
+
// google.charts.load('current', {packages:['corechart']});
|
|
6
|
+
|
|
7
|
+
if (onLoadCallback !== 'undefined') {
|
|
8
|
+
google.charts.setOnLoadCallback(onLoadCallback);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
1
11
|
|
|
2
|
-
// google.load("visualization", "1", {packages:["corechart"]});
|
|
3
|
-
google.charts.load('current', {'packages':['bar','line','corechart']});
|
|
4
|
-
// google.charts.load('current', {packages:['corechart']});
|
|
5
|
-
|
|
6
|
-
google.charts.setOnLoadCallback(drawAllCharts);
|
|
7
|
-
|
|
8
|
-
class GoogleCharts
|
|
9
|
-
{
|
|
10
12
|
static drawCharts(chartsList, onComplete) {
|
|
11
13
|
// on supprime du tableau la liste des graphiques dont l'id div n'a pas été trouvé (le graphique ne pourra pas être généré)
|
|
12
14
|
chartsList = chartsList.filter(chartData => typeof chartData.div_id != 'undefined' && $('#'+chartData.div_id).length);
|
|
@@ -342,3 +344,4 @@ class GoogleCharts
|
|
|
342
344
|
|
|
343
345
|
}
|
|
344
346
|
|
|
347
|
+
module.exports = { GoogleCharts };
|
package/google_maps.js
CHANGED
|
@@ -19,7 +19,7 @@ class GoogleMap {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
static getUrl(latitude, longitude) {
|
|
22
|
-
return '
|
|
22
|
+
return 'https://maps.google.com/?q='+latitude+','+longitude+'';
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
static getUrlFromCoordinates(locationCoordinates) {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
class GoogleRecaptcha {
|
|
2
|
+
static onLoad() {
|
|
3
|
+
console.log('GoogleRecaptcha.onLoad');
|
|
4
|
+
if (typeof grecaptcha == 'undefined' || typeof grecaptcha.render != 'function') {
|
|
5
|
+
console.log('var grecaptcha undefined');
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (typeof GoogleRecaptcha.googleCaptchaRendersCallback == 'undefined') {
|
|
10
|
+
GoogleRecaptcha.googleCaptchaRendersCallback = [];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
GoogleRecaptcha.googleCaptchaRendersCallback.forEach(callback => callback());
|
|
14
|
+
GoogleRecaptcha.googleCaptchaRendersCallback = [];
|
|
15
|
+
|
|
16
|
+
/*document.querySelectorAll('.grecaptcha').forEach(element => {
|
|
17
|
+
try {
|
|
18
|
+
console.log(element.id);
|
|
19
|
+
//grecaptchaWidgets[element.id] = grecaptcha.render(element.id, googleReCaptchaDatas);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
console.log('Exception during grecaptcha.render', e);
|
|
23
|
+
}
|
|
24
|
+
});*/
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static addRenderCallback(callback) {
|
|
28
|
+
if (typeof GoogleRecaptcha.googleCaptchaRendersCallback == 'undefined') {
|
|
29
|
+
GoogleRecaptcha.googleCaptchaRendersCallback = [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
GoogleRecaptcha.googleCaptchaRendersCallback.push(callback);
|
|
33
|
+
console.log('GoogleRecaptcha.addRenderCallback');
|
|
34
|
+
GoogleRecaptcha.onLoad();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static reset(id) {
|
|
38
|
+
if (typeof grecaptcha == 'undefined' || typeof grecaptcha.render != 'function') {
|
|
39
|
+
console.log('var grecaptcha.render undefined');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (typeof GoogleRecaptcha.grecaptchaWidgets == 'undefined') {
|
|
44
|
+
GoogleRecaptcha.grecaptchaWidgets = [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (typeof GoogleRecaptcha.grecaptchaWidgets[id] == 'undefined') {
|
|
48
|
+
try {
|
|
49
|
+
GoogleRecaptcha.grecaptchaWidgets[id] = grecaptcha.render(id, googleReCaptchaDatas);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
console.log('Exception during grecaptcha.render', e);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
grecaptcha.reset(GoogleRecaptcha.grecaptchaWidgets[id]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = { GoogleRecaptcha };
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
var grecaptchaWidgets = [];
|
|
65
|
+
|
|
66
|
+
function grecaptchaOnload () {
|
|
67
|
+
if (typeof grecaptcha == 'undefined') {
|
|
68
|
+
console.log('var grecaptcha undefined');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
document.querySelectorAll('.grecaptcha').forEach(element => {
|
|
72
|
+
grecaptchaWidgets[element.id] = grecaptcha.render(element.id, googleReCaptchaDatas);
|
|
73
|
+
});
|
|
74
|
+
//$('.grecaptcha').each(function(idx, el) {
|
|
75
|
+
// grecaptchaWidgets[$(el).attr('id')] = grecaptcha.render($(el).attr('id'), googleReCaptchaDatas);
|
|
76
|
+
//});
|
|
77
|
+
}
|
|
78
|
+
*/
|
package/index.js
CHANGED
|
@@ -1,35 +1,47 @@
|
|
|
1
1
|
//A noter : les réécritures de prototypes définies dans certains fichiers n'ont pas besoin d'être exportés depuis le module en question (exemple Array / Object dans array.js).
|
|
2
2
|
//Il faut uniquement appeler require() (sans récupérer le retour) et ajouter la/les classe(s) concernée(s) dans l'export ci-dessous (l'appel de require() applique l'extension).
|
|
3
3
|
|
|
4
|
+
// rien à exporter (que des extensions d'objet natif)
|
|
5
|
+
require('./string');
|
|
6
|
+
require('./array');
|
|
7
|
+
|
|
8
|
+
// exports d'ojets non natif
|
|
4
9
|
const { HTTPRequest, Cookie, UrlAndQueryString } = require('./network');
|
|
5
10
|
const { IBAN } = require('./bank');
|
|
6
11
|
const { AudioMedia } = require('./media');
|
|
7
12
|
const { PersonName, Email, TelephoneNumber } = require('./contact_details');
|
|
8
|
-
const { CountDown } = require('./count_down');
|
|
9
|
-
const { DataTable } = require('./data_table');
|
|
10
13
|
const { DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, InputPeriod } = require('./date_time');
|
|
11
|
-
const { DetailsSubArray } = require('./details_sub_array');
|
|
12
14
|
const { Duration } = require('./duration');
|
|
13
15
|
const { File, CSV, Img } = require('./file');
|
|
14
|
-
const { FlashMessage } = require('./flash_message');
|
|
15
16
|
const { FormHelper } = require('./form_helper');
|
|
16
|
-
const {
|
|
17
|
+
const { Country, PostalAddress, Location } = require('./location');
|
|
18
|
+
const { SocialNetwork } = require('./social_network');
|
|
19
|
+
const { sleep, refresh } = require('./util');
|
|
20
|
+
const { chr, ord, trim, empty } = require('./php.min');
|
|
21
|
+
|
|
22
|
+
// exports plugins "maison"
|
|
23
|
+
const { DataTable } = require('./data_table');
|
|
24
|
+
const { Pagination, activateTab } = require('./paging');
|
|
25
|
+
const { FlashMessage } = require('./flash_message');
|
|
26
|
+
const { CountDown } = require('./count_down');
|
|
27
|
+
const { DetailsSubArray } = require('./details_sub_array');
|
|
17
28
|
const { ImportFromCsv } = require('./import_from_csv');
|
|
18
29
|
const { JwtToken, JwtSession } = require('./jwt');
|
|
19
30
|
const { ListBox } = require('./list_box');
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const {
|
|
31
|
+
|
|
32
|
+
// exports surcouche lib externe
|
|
33
|
+
const { GoogleCharts } = require('./google_charts');
|
|
34
|
+
const { GoogleRecaptcha } = require('./google_recaptcha');
|
|
35
|
+
const { GoogleMap } = require('./google_maps');
|
|
36
|
+
const { OpenStreetMap } = require('./open_street_map');
|
|
37
|
+
|
|
38
|
+
// deprecated
|
|
23
39
|
const { NumberValue } = require('./number');
|
|
24
|
-
const { selectionnerContenuNode, copierTexte } = require('./string');
|
|
25
|
-
const { addBookmark, sleep, refresh } = require('./util');
|
|
26
|
-
const { chr, ord, trim, empty } = require('./php.min');
|
|
27
|
-
const { Pagination, activateTab } = require('./paging');
|
|
28
40
|
|
|
29
41
|
module.exports = {
|
|
30
|
-
|
|
31
|
-
DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, InputPeriod,
|
|
32
|
-
FlashMessage,
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
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, DetailsSubArray, ImportFromCsv, JwtToken, JwtSession, ListBox,
|
|
45
|
+
sleep, refresh, chr, ord, trim, empty,
|
|
46
|
+
GoogleCharts, GoogleRecaptcha, GoogleMap, OpenStreetMap
|
|
35
47
|
};
|