@osimatic/helpers-js 1.0.58 → 1.0.61
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/CHANGELOG +4 -1
- package/data_table.js +0 -4
- package/file.js +1 -1
- package/import_from_csv.js +5 -5
- package/network.js +49 -4
- package/package.json +1 -1
|
@@ -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/CHANGELOG
CHANGED
|
@@ -45,4 +45,7 @@ FormHelper.getFormErrorTextBis(...) -> FormHelper.getFormErrorText(...)
|
|
|
45
45
|
FormHelper.displayFormErrorsFromXhr(form, btnSubmit, xhr) -> FormHelper.displayFormErrors(form, btnSubmit, xhr.responseJSON)
|
|
46
46
|
|
|
47
47
|
1.0.35 :
|
|
48
|
-
ajout méthode HTTPRequest.init() (charge le polyfill de fetch)
|
|
48
|
+
ajout méthode HTTPRequest.init() (charge le polyfill de fetch)
|
|
49
|
+
|
|
50
|
+
1.0.61
|
|
51
|
+
DataTable.displayErrorFromXhr -> DataTable.displayError
|
package/data_table.js
CHANGED
|
@@ -268,10 +268,6 @@ class DataTable {
|
|
|
268
268
|
// }
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
static displayErrorFromXhr(div, jqxhr, defaultMessage) {
|
|
272
|
-
this.displayError(div, JSON.parse(jqxhr.responseJSON), defaultMessage);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
271
|
static displayError(div, data, defaultMessage) {
|
|
276
272
|
var error = null;
|
|
277
273
|
if (data != null) {
|
package/file.js
CHANGED
|
@@ -111,7 +111,7 @@ class Img {
|
|
|
111
111
|
// $(img).attr('src', urlCreator.createObjectURL(data));
|
|
112
112
|
Img.setBlobToImg($(img), data);
|
|
113
113
|
},
|
|
114
|
-
error: (jqxhr, status,
|
|
114
|
+
error: (jqxhr, status, errorThrown) => HTTPRequest.logJqueryRequestFailure(jqxhr, status, errorThrown),
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
|
package/import_from_csv.js
CHANGED
|
@@ -95,13 +95,13 @@ class ImportFromCsv {
|
|
|
95
95
|
|
|
96
96
|
requestImportData(dataToImport,
|
|
97
97
|
// fonction callback en cas d'erreur de formulaire
|
|
98
|
-
|
|
99
|
-
console.log(
|
|
100
|
-
if (typeof
|
|
101
|
-
formMatching.find('div.errors').html(
|
|
98
|
+
(json) => {
|
|
99
|
+
console.log(json);
|
|
100
|
+
if (typeof json['import_list'] !== 'undefined') {
|
|
101
|
+
formMatching.find('div.errors').html(json['import_list']).removeClass('hide');
|
|
102
102
|
}
|
|
103
103
|
else {
|
|
104
|
-
formMatching.find('div.errors').html(ImportFromCsv.getErrorsHtmlOfImportData(
|
|
104
|
+
formMatching.find('div.errors').html(ImportFromCsv.getErrorsHtmlOfImportData(json, divResult)).removeClass('hide');
|
|
105
105
|
}
|
|
106
106
|
formMatching.find('button[type="submit"]').buttonLoader('reset');
|
|
107
107
|
}
|
package/network.js
CHANGED
|
@@ -53,6 +53,48 @@ class HTTPRequest {
|
|
|
53
53
|
this.headers['Authorization'] = 'Bearer ' + accessToken;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
static convertObjectToFormData(obj) {
|
|
57
|
+
// 30/05/2022 : ancienne version, qui ne fonctionne pas avec des tableaux
|
|
58
|
+
// let formData = new FormData();
|
|
59
|
+
// Object.entries(data).forEach(([key, value]) => formData.append(key, value));
|
|
60
|
+
// return formData;
|
|
61
|
+
|
|
62
|
+
var formData = new FormData();
|
|
63
|
+
|
|
64
|
+
function appendFormData(data, root) {
|
|
65
|
+
//console.log('appendFormData', data, root);
|
|
66
|
+
root = root || '';
|
|
67
|
+
if (data instanceof File) {
|
|
68
|
+
formData.append(root, data);
|
|
69
|
+
}
|
|
70
|
+
else if (Array.isArray(data)) {
|
|
71
|
+
for (var i = 0; i < data.length; i++) {
|
|
72
|
+
appendFormData(data[i], root + '[' + i + ']');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else if (typeof data === 'object' && data) {
|
|
76
|
+
for (var key in data) {
|
|
77
|
+
if (data.hasOwnProperty(key)) {
|
|
78
|
+
if (root === '') {
|
|
79
|
+
appendFormData(data[key], key);
|
|
80
|
+
} else {
|
|
81
|
+
appendFormData(data[key], root + '.' + key);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
if (data !== null && typeof data !== 'undefined') {
|
|
88
|
+
formData.append(root, data);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
appendFormData(obj);
|
|
94
|
+
|
|
95
|
+
return formData;
|
|
96
|
+
}
|
|
97
|
+
|
|
56
98
|
static formatQueryString(data) {
|
|
57
99
|
if (data == null) {
|
|
58
100
|
return '';
|
|
@@ -68,9 +110,7 @@ class HTTPRequest {
|
|
|
68
110
|
|
|
69
111
|
static formatFormData(data) {
|
|
70
112
|
if (!(data instanceof FormData)) {
|
|
71
|
-
|
|
72
|
-
Object.entries(data).forEach(([key, value]) => formData.append(key, value));
|
|
73
|
-
return formData;
|
|
113
|
+
return HTTPRequest.convertObjectToFormData(data);
|
|
74
114
|
}
|
|
75
115
|
return data;
|
|
76
116
|
}
|
|
@@ -580,13 +620,18 @@ class UrlAndQueryString {
|
|
|
580
620
|
if (typeof (object) == 'object') {
|
|
581
621
|
for (var name in object) {
|
|
582
622
|
value = object[name];
|
|
623
|
+
// 06/06/2022 : ajout de ce if pour éviter bug sur fonction HTTPRequest.formatQueryString
|
|
624
|
+
if (typeof (value) == 'undefined') {
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
583
627
|
// 14/01/2020 : les tableaux avec param[0], param[1] en query string fonctionne pas, il faut mettre param[]=x¶m[]=y
|
|
584
628
|
//name = p == '' ? name : '['+name+']';
|
|
585
629
|
name = p == '' ? name : '[]';
|
|
586
630
|
if (typeof (value) == 'object') {
|
|
587
631
|
buildStringFromParam(value, p + name);
|
|
588
632
|
}
|
|
589
|
-
|
|
633
|
+
// 06/06/2022 : ajout null !== value pour éviter bug sur fonction HTTPRequest.formatQueryString
|
|
634
|
+
else if (null !== value && typeof (value) != 'function' && name != '') {
|
|
590
635
|
// 27/01/2020 : correction bug boolean affiché en string true/false
|
|
591
636
|
if (typeof (value) == 'boolean') {
|
|
592
637
|
value = (value ? 1 : 0);
|