@dile/crud 0.0.45 → 0.0.47
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.
|
@@ -9,22 +9,32 @@ export class DileAjax extends DileAxios(DileI18nMixin(LitElement)) {
|
|
|
9
9
|
method: { type: String },
|
|
10
10
|
url: { type: String },
|
|
11
11
|
statusSuccessCodes: { type: Array },
|
|
12
|
+
sendDataAsFormData: { type: Boolean },
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
constructor() {
|
|
16
17
|
super();
|
|
17
|
-
this.data = {};
|
|
18
18
|
this.method = 'post';
|
|
19
19
|
this.url = '';
|
|
20
20
|
this.statusSuccessCodes = [200, 201];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
get computedData() {
|
|
24
|
+
if(this.formData) {
|
|
25
|
+
return this.formData;
|
|
26
|
+
}
|
|
27
|
+
return this.data || {};
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
generateRequest() {
|
|
24
31
|
let request;
|
|
32
|
+
if(this.sendDataAsFormData) {
|
|
33
|
+
this._prepareFormData();
|
|
34
|
+
}
|
|
25
35
|
switch(this.method.toLowerCase().trim()) {
|
|
26
36
|
case 'post':
|
|
27
|
-
request = this.axiosInstance.post(this.url, this.
|
|
37
|
+
request = this.axiosInstance.post(this.url, this.computedData);
|
|
28
38
|
break;
|
|
29
39
|
case 'get':
|
|
30
40
|
request = this.axiosInstance.get(this.url, {
|
|
@@ -32,13 +42,13 @@ export class DileAjax extends DileAxios(DileI18nMixin(LitElement)) {
|
|
|
32
42
|
});
|
|
33
43
|
break;
|
|
34
44
|
case 'put':
|
|
35
|
-
request = this.axiosInstance.put(this.url, this.
|
|
45
|
+
request = this.axiosInstance.put(this.url, this.computedData);
|
|
36
46
|
break;
|
|
37
47
|
case 'delete':
|
|
38
|
-
request = this.axiosInstance.delete(this.url, this.
|
|
48
|
+
request = this.axiosInstance.delete(this.url, this.computedData);
|
|
39
49
|
break;
|
|
40
50
|
case 'patch':
|
|
41
|
-
request = this.axiosInstance.patch(this.url, this.
|
|
51
|
+
request = this.axiosInstance.patch(this.url, this.computedData);
|
|
42
52
|
break
|
|
43
53
|
}
|
|
44
54
|
request.then((response) => {
|
|
@@ -62,6 +72,9 @@ export class DileAjax extends DileAxios(DileI18nMixin(LitElement)) {
|
|
|
62
72
|
.catch(err => {
|
|
63
73
|
this.describeError(err);
|
|
64
74
|
})
|
|
75
|
+
.finally(() => {
|
|
76
|
+
this.formData = null;
|
|
77
|
+
});
|
|
65
78
|
}
|
|
66
79
|
|
|
67
80
|
describeError(err) {
|
|
@@ -110,5 +123,23 @@ export class DileAjax extends DileAxios(DileI18nMixin(LitElement)) {
|
|
|
110
123
|
}
|
|
111
124
|
}));
|
|
112
125
|
}
|
|
126
|
+
|
|
127
|
+
_prepareFormData() {
|
|
128
|
+
this._createFormData();
|
|
129
|
+
this._addObjectToFormData(this.data);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
_createFormData() {
|
|
133
|
+
this.formData = new FormData();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
_addObjectToFormData(data) {
|
|
137
|
+
if (!this.formData) {
|
|
138
|
+
this.createFormData();
|
|
139
|
+
}
|
|
140
|
+
for (const key in data) {
|
|
141
|
+
this.formData.append(key, data[key]);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
113
144
|
}
|
|
114
145
|
|
|
@@ -18,7 +18,7 @@ export class DileAjaxForm extends DileI18nMixin(LitElement) {
|
|
|
18
18
|
--dile-button-font-size: 0.875rem;
|
|
19
19
|
}
|
|
20
20
|
.actions {
|
|
21
|
-
margin-top: var(--dile-ajax-form-actions-margin-top,
|
|
21
|
+
margin-top: var(--dile-ajax-form-actions-margin-top, 1rem);
|
|
22
22
|
padding-left: 3px;
|
|
23
23
|
}
|
|
24
24
|
`
|
|
@@ -36,6 +36,7 @@ export class DileAjaxForm extends DileI18nMixin(LitElement) {
|
|
|
36
36
|
formIdentifier: { type: String, },
|
|
37
37
|
setDataOnInit: { type: Boolean },
|
|
38
38
|
responseAdapter: { type: Object },
|
|
39
|
+
sendDataAsFormData: { type: Boolean },
|
|
39
40
|
};
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -98,6 +99,7 @@ export class DileAjaxForm extends DileI18nMixin(LitElement) {
|
|
|
98
99
|
@ajax-success="${this.doSuccessSave}"
|
|
99
100
|
@ajax-error="${this.doErrorSave}"
|
|
100
101
|
language="${this.language}"
|
|
102
|
+
?sendDataAsFormData=${this.sendDataAsFormData}
|
|
101
103
|
></dile-ajax>
|
|
102
104
|
`
|
|
103
105
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dile/crud",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47",
|
|
4
4
|
"description": "Components to create a generic crud system based on Web Components and Lit",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://dile-components.polydile.com/",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@dile/ui": "^2.1.
|
|
27
|
+
"@dile/ui": "^2.1.24",
|
|
28
28
|
"axios": "^1.7.2",
|
|
29
29
|
"lit": "^2.7.0 || ^3.0.0"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "a4a717f1aa0deee5f86b7c74b53a9ccaee11552d"
|
|
35
35
|
}
|