@dile/crud 2.12.3 → 2.14.1
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/components/ajax-input-suggestions/ajax-input-suggestions.js +5 -0
- package/components/ajax-input-suggestions/index.js +1 -0
- package/components/ajax-input-suggestions/src/DileAjaxInputSuggestions.js +59 -0
- package/components/ajax-input-tags/ajax-input-tags.js +5 -0
- package/components/ajax-input-tags/index.js +1 -0
- package/components/ajax-input-tags/src/DileAjaxInputTags.js +10 -0
- package/components/crud/src/DileCrud.js +2 -1
- package/components/item-delete/src/DileCrudItemDelete.js +21 -5
- package/lib/defaultConfig.js +3 -0
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DileAjaxInputSuggestions } from './src/DileAjaxInputSuggestions.js';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DileInputSuggestionsBase } from '@dile/ui/components/input-suggestions/index.js';
|
|
2
|
+
import { DileAxios } from '../../../lib/DileAxios.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* # dile-ajax-input-suggestions
|
|
6
|
+
*
|
|
7
|
+
* Ajax variant of DileInputSuggestionsBase (`@dile/ui`), with the same request API as
|
|
8
|
+
* dile-ajax-select-crud-overlay. It requests the suggestions to `endpoint` with Axios
|
|
9
|
+
* (DileAxios), sending the typed text in `queryStringVariable`.
|
|
10
|
+
*
|
|
11
|
+
* How the list is extracted from the response, by priority:
|
|
12
|
+
* 1. `getSelectResultList(response)`, which receives the whole body;
|
|
13
|
+
* 2. `resultDataProperty`, name of the first-level property holding the array;
|
|
14
|
+
* 3. the whole body, when it already is the array.
|
|
15
|
+
*/
|
|
16
|
+
export class DileAjaxInputSuggestions extends DileAxios(DileInputSuggestionsBase) {
|
|
17
|
+
static get properties() {
|
|
18
|
+
return {
|
|
19
|
+
endpoint: { type: String },
|
|
20
|
+
queryStringVariable: { type: String },
|
|
21
|
+
additionalQueryString: { type: Object },
|
|
22
|
+
resultDataProperty: { type: String },
|
|
23
|
+
maxResults: { type: Number },
|
|
24
|
+
pageParamName: { type: String },
|
|
25
|
+
getSelectResultList: { type: Object },
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
this.queryStringVariable = 'q';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
loadData() {
|
|
35
|
+
const requestId = this._requestId;
|
|
36
|
+
const params = { ...(this.additionalQueryString || {}) };
|
|
37
|
+
if (this.pageParamName && this.maxResults) {
|
|
38
|
+
params[this.pageParamName] = this.maxResults;
|
|
39
|
+
}
|
|
40
|
+
params[this.queryStringVariable] = this.keyword;
|
|
41
|
+
this.axiosInstance
|
|
42
|
+
.get(this.endpoint, { params })
|
|
43
|
+
.then((response) => {
|
|
44
|
+
const body = response.data;
|
|
45
|
+
this.setResults(body?.error ? [] : this.getResultList(body), requestId);
|
|
46
|
+
})
|
|
47
|
+
.catch(() => this.setResults([], requestId));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getResultList(body) {
|
|
51
|
+
if (typeof this.getSelectResultList === 'function') {
|
|
52
|
+
return this.getSelectResultList(body);
|
|
53
|
+
}
|
|
54
|
+
if (this.resultDataProperty) {
|
|
55
|
+
return body?.[this.resultDataProperty];
|
|
56
|
+
}
|
|
57
|
+
return body;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DileAjaxInputTags } from './src/DileAjaxInputTags.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DileInputTagsMixin } from '@dile/ui/components/input-tags/index.js';
|
|
2
|
+
import { DileAjaxInputSuggestions } from '../../ajax-input-suggestions/src/DileAjaxInputSuggestions.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* # dile-ajax-input-tags
|
|
6
|
+
*
|
|
7
|
+
* Tags editor that requests its suggestions to `endpoint`, with the same API as
|
|
8
|
+
* dile-ajax-input-suggestions. See DileInputTagsMixin in `@dile/ui`.
|
|
9
|
+
*/
|
|
10
|
+
export class DileAjaxInputTags extends DileInputTagsMixin(DileAjaxInputSuggestions) {}
|
|
@@ -203,6 +203,7 @@ export class DileCrud extends DileI18nMixin(DileCrudMixin(LitElement)) {
|
|
|
203
203
|
<dile-crud-item-delete
|
|
204
204
|
id="eldelete"
|
|
205
205
|
endpoint="${this.config.endpoint}"
|
|
206
|
+
.confirmMessageTemplate=${this.config.templates.deleteConfirmMessage}
|
|
206
207
|
@delete-success=${this.deleteSuccess}
|
|
207
208
|
language="${this.language}"
|
|
208
209
|
></dile-crud-item-delete>
|
|
@@ -550,7 +551,7 @@ export class DileCrud extends DileI18nMixin(DileCrudMixin(LitElement)) {
|
|
|
550
551
|
}
|
|
551
552
|
|
|
552
553
|
itemDeleteRequest(e) {
|
|
553
|
-
this.deleteElement.delete(e.detail.itemId)
|
|
554
|
+
this.deleteElement.delete(e.detail.itemId, e.detail.item);
|
|
554
555
|
}
|
|
555
556
|
|
|
556
557
|
itemRestoreRequest(e) {
|
|
@@ -23,9 +23,10 @@ export class DileCrudItemDelete extends DileI18nMixin(LitElement) {
|
|
|
23
23
|
--dile-confirm-cancel-button-color: var(--neutral-icon-color, #337aad);
|
|
24
24
|
--dile-confirm-cancel-text-button-color: #fff;
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
.message {
|
|
27
27
|
text-align: center;
|
|
28
28
|
color: #303030;
|
|
29
|
+
margin: 1em 0;
|
|
29
30
|
}
|
|
30
31
|
`
|
|
31
32
|
];
|
|
@@ -39,6 +40,8 @@ export class DileCrudItemDelete extends DileI18nMixin(LitElement) {
|
|
|
39
40
|
cancelLabel: { type: String },
|
|
40
41
|
acceptLabel: { type: String },
|
|
41
42
|
method: { type: String },
|
|
43
|
+
confirmMessageTemplate: { attribute: false },
|
|
44
|
+
itemToDelete: { state: true },
|
|
42
45
|
};
|
|
43
46
|
}
|
|
44
47
|
|
|
@@ -48,7 +51,8 @@ export class DileCrudItemDelete extends DileI18nMixin(LitElement) {
|
|
|
48
51
|
this.errorEventName = 'delete-error';
|
|
49
52
|
this.responseAdapter = new ResponseApiAdapter();
|
|
50
53
|
this.method = 'delete';
|
|
51
|
-
this.
|
|
54
|
+
this.confirmMessageTemplate = null;
|
|
55
|
+
this.itemToDelete = null;
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
firstUpdated() {
|
|
@@ -70,8 +74,9 @@ export class DileCrudItemDelete extends DileI18nMixin(LitElement) {
|
|
|
70
74
|
acceptLabel="${this.acceptLabelComputed(this.acceptLabel, this.translations)}"
|
|
71
75
|
id="elconfirm"
|
|
72
76
|
@dile-confirm-accepted=${this.deleteAccepted}
|
|
77
|
+
@dile-confirm-cancelled=${this.deleteCancelled}
|
|
73
78
|
>
|
|
74
|
-
<
|
|
79
|
+
<div class="message">${this.confirmMessageComputed(this.confirmMessage, this.translations, this.confirmMessageTemplate, this.itemToDelete)}</div>
|
|
75
80
|
</dile-confirm>
|
|
76
81
|
`;
|
|
77
82
|
}
|
|
@@ -80,9 +85,11 @@ export class DileCrudItemDelete extends DileI18nMixin(LitElement) {
|
|
|
80
85
|
return `${endpoint}/${relatedId}`
|
|
81
86
|
}
|
|
82
87
|
|
|
83
|
-
delete(itemId) {
|
|
88
|
+
delete(itemId, item = null) {
|
|
84
89
|
if(itemId != "" && itemId != undefined) {
|
|
85
90
|
this.relatedId = itemId;
|
|
91
|
+
// Reactive: the confirm message is re-rendered with this item
|
|
92
|
+
this.itemToDelete = item;
|
|
86
93
|
this.elconfirm.open();
|
|
87
94
|
} else {
|
|
88
95
|
throw new Error(OPERATION_ITEM_MISSING_ERROR);
|
|
@@ -93,7 +100,12 @@ export class DileCrudItemDelete extends DileI18nMixin(LitElement) {
|
|
|
93
100
|
this.ajaxdelete.generateRequest();
|
|
94
101
|
}
|
|
95
102
|
|
|
103
|
+
deleteCancelled() {
|
|
104
|
+
this.itemToDelete = null;
|
|
105
|
+
}
|
|
106
|
+
|
|
96
107
|
doSuccessDelete(e) {
|
|
108
|
+
this.itemToDelete = null;
|
|
97
109
|
let msg = this.computeResponseMessage(e.detail);
|
|
98
110
|
this.dispatchEvent(new CustomEvent(this.successEventName, {
|
|
99
111
|
bubbles: true,
|
|
@@ -106,6 +118,7 @@ export class DileCrudItemDelete extends DileI18nMixin(LitElement) {
|
|
|
106
118
|
}
|
|
107
119
|
|
|
108
120
|
doErrorDelete(e) {
|
|
121
|
+
this.itemToDelete = null;
|
|
109
122
|
let msg = this.computeResponseMessage(e.detail);
|
|
110
123
|
this.dispatchEvent(new CustomEvent(this.errorEventName, {
|
|
111
124
|
bubbles: true,
|
|
@@ -134,7 +147,10 @@ export class DileCrudItemDelete extends DileI18nMixin(LitElement) {
|
|
|
134
147
|
return label ? label : translations?.delete_label ? translations.delete_label : 'Delete';
|
|
135
148
|
}
|
|
136
149
|
|
|
137
|
-
confirmMessageComputed(message, translations) {
|
|
150
|
+
confirmMessageComputed(message, translations, template = null, item = null) {
|
|
151
|
+
if(typeof template === 'function' && item) {
|
|
152
|
+
return template(item);
|
|
153
|
+
}
|
|
138
154
|
return message ? message : translations?.delete_confirm_message ? translations.delete_confirm_message : 'Are you sure?';
|
|
139
155
|
}
|
|
140
156
|
}
|
package/lib/defaultConfig.js
CHANGED
|
@@ -77,6 +77,9 @@ export const defaultConfig = {
|
|
|
77
77
|
`,
|
|
78
78
|
relations: () => '',
|
|
79
79
|
formSingleActions: () => '',
|
|
80
|
+
// Optional. (item) => string | TemplateResult with the confirmation message
|
|
81
|
+
// shown when deleting an item. If null, the delete_confirm_message translation is used.
|
|
82
|
+
deleteConfirmMessage: null,
|
|
80
83
|
},
|
|
81
84
|
labels: {
|
|
82
85
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dile/crud",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.1",
|
|
4
4
|
"description": "Components to create a generic crud system based on Web Components and Lit",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"homepage": "https://dile-components.com/",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@dile/image-cropper": "^0.1.1",
|
|
29
|
-
"@dile/ui": "^3.
|
|
29
|
+
"@dile/ui": "^3.21.0",
|
|
30
30
|
"axios": "^1.19.0",
|
|
31
31
|
"lit": "^2.7.0 || ^3.0.0"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "f21f7ada6b7c1252b9efb0f0143e1ae487cbc314"
|
|
37
37
|
}
|