@dile/crud 1.7.7 → 1.8.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-form/confirmed-ajax-form.js +2 -0
- package/components/ajax-form/index.js +2 -1
- package/components/ajax-form/src/DileConfirmedAjaxForm.js +89 -0
- package/components/list/src/DileCrudList.js +14 -2
- package/lib/defaultConfig.js +6 -3
- package/lib/i18n/en.js +2 -0
- package/lib/i18n/es.js +2 -0
- package/package.json +2 -2
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { DileAjaxForm } from './src/DileAjaxForm.js';
|
|
1
|
+
export { DileAjaxForm } from './src/DileAjaxForm.js';
|
|
2
|
+
export { DileConfirmedAjaxForm } from './src/DileConfirmedAjaxForm.js';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* # DileConfirmedAjaxForm
|
|
4
|
+
*
|
|
5
|
+
* Ajax form component that requires confirmation before submission
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { LitElement, html } from 'lit';
|
|
10
|
+
import '@dile/ui/components/confirm/confirm.js';
|
|
11
|
+
import { DileAjaxForm } from './DileAjaxForm.js';
|
|
12
|
+
|
|
13
|
+
export class DileConfirmedAjaxForm extends DileAjaxForm {
|
|
14
|
+
|
|
15
|
+
static get properties() {
|
|
16
|
+
return {
|
|
17
|
+
...super.properties,
|
|
18
|
+
confirmText: { type: String },
|
|
19
|
+
acceptLabel: { type: String },
|
|
20
|
+
cancelLabel: { type: String },
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
this.confirmText = null;
|
|
27
|
+
this.acceptLabel = null;
|
|
28
|
+
this.cancelLabel = null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
render() {
|
|
32
|
+
return html`
|
|
33
|
+
${super.render()}
|
|
34
|
+
<dile-confirm
|
|
35
|
+
id="confirmDialog"
|
|
36
|
+
@dile-confirm-accepted="${this.onConfirmAccepted}"
|
|
37
|
+
@dile-confirm-cancelled="${this.onConfirmCancelled}"
|
|
38
|
+
.acceptLabel="${this.computeAcceptLabel()}"
|
|
39
|
+
.cancelLabel="${this.computeCancelLabel()}"
|
|
40
|
+
blocking
|
|
41
|
+
>
|
|
42
|
+
<p>${this.computeConfirmText()}</p>
|
|
43
|
+
</dile-confirm>
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
firstUpdated() {
|
|
48
|
+
super.firstUpdated();
|
|
49
|
+
this.confirmDialog = this.shadowRoot.getElementById('confirmDialog');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
doAction() {
|
|
53
|
+
this.feedback.clear();
|
|
54
|
+
this.confirmDialog.open();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
onConfirmAccepted() {
|
|
58
|
+
// Call the parent's doAction method directly, bypassing our override
|
|
59
|
+
const formData = this.form.getData();
|
|
60
|
+
this.ajaxsave.data = formData;
|
|
61
|
+
this.ajaxsave.generateRequest();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
onConfirmCancelled() {
|
|
65
|
+
// Silently cancel, just close the dialog
|
|
66
|
+
// No action needed
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
computeConfirmText() {
|
|
70
|
+
if (this.confirmText) {
|
|
71
|
+
return this.confirmText;
|
|
72
|
+
}
|
|
73
|
+
return this.translations?.confirm_submit_text || 'Are you sure you want to submit this form?';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
computeAcceptLabel() {
|
|
77
|
+
if (this.acceptLabel) {
|
|
78
|
+
return this.acceptLabel;
|
|
79
|
+
}
|
|
80
|
+
return this.translations?.accept_label || 'Accept';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
computeCancelLabel() {
|
|
84
|
+
if (this.cancelLabel) {
|
|
85
|
+
return this.cancelLabel;
|
|
86
|
+
}
|
|
87
|
+
return this.translations?.cancel_label || 'Cancel';
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -205,8 +205,8 @@ export class DileCrudList extends DileI18nMixin(DileLoading(LitElement)) {
|
|
|
205
205
|
<dile-crud-list-item
|
|
206
206
|
itemId="${this.computeItemId(element)}"
|
|
207
207
|
.actionIds="${this.actionIds}"
|
|
208
|
-
?disableEdit=${this.
|
|
209
|
-
?disableDelete=${this.
|
|
208
|
+
?disableEdit=${!this.isItemEditable(element)}
|
|
209
|
+
?disableDelete=${!this.isItemDeletable(element)}
|
|
210
210
|
?disableRestore=${this.config?.customization?.disableRestore}
|
|
211
211
|
?hideCheckboxSelection="${this.config?.customization?.hideCheckboxSelection}"
|
|
212
212
|
@item-checkbox-changed=${this.onItemsCheckboxChanged}
|
|
@@ -229,6 +229,18 @@ export class DileCrudList extends DileI18nMixin(DileLoading(LitElement)) {
|
|
|
229
229
|
return this.config.computeItemId(element);
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
+
isItemEditable(element) {
|
|
233
|
+
const isGloballyDisabled = this.config?.customization?.disableEdit;
|
|
234
|
+
const isItemEditable = this.config?.isItemEditable(element) ?? true;
|
|
235
|
+
return !isGloballyDisabled && isItemEditable;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
isItemDeletable(element) {
|
|
239
|
+
const isGloballyDisabled = this.config?.customization?.disableDelete;
|
|
240
|
+
const isItemDeletable = this.config?.isItemDeletable(element) ?? true;
|
|
241
|
+
return !isGloballyDisabled && isItemDeletable;
|
|
242
|
+
}
|
|
243
|
+
|
|
232
244
|
get allIdsUrl() {
|
|
233
245
|
return `${this.config.endpoint}/allids`;
|
|
234
246
|
}
|
package/lib/defaultConfig.js
CHANGED
|
@@ -39,12 +39,15 @@ export const defaultConfig = {
|
|
|
39
39
|
updateOperation: {
|
|
40
40
|
type: 'modal'
|
|
41
41
|
},
|
|
42
|
-
insertOperation: {
|
|
43
|
-
type: 'modal'
|
|
44
|
-
},
|
|
45
42
|
computeItemId(element) {
|
|
46
43
|
return element.id;
|
|
47
44
|
},
|
|
45
|
+
isItemEditable(element) {
|
|
46
|
+
return true;
|
|
47
|
+
},
|
|
48
|
+
isItemDeletable(element) {
|
|
49
|
+
return true;
|
|
50
|
+
},
|
|
48
51
|
actions: {
|
|
49
52
|
list: [
|
|
50
53
|
{
|
package/lib/i18n/en.js
CHANGED
|
@@ -52,4 +52,6 @@ export const translations = {
|
|
|
52
52
|
select_file: "Select file",
|
|
53
53
|
selected_file: "Selected file",
|
|
54
54
|
extension_allowed: "Only this file extensions are allowed: ",
|
|
55
|
+
confirm_submit_title: "Confirm submission",
|
|
56
|
+
confirm_submit_text: "Are you sure you want to submit this form?",
|
|
55
57
|
};
|
package/lib/i18n/es.js
CHANGED
|
@@ -52,4 +52,6 @@ export const translations = {
|
|
|
52
52
|
select_file: "Seleccionar archivo",
|
|
53
53
|
selected_file: "Archivo seleccionado",
|
|
54
54
|
extension_allowed: "Solo se permiten estas extensiones: ",
|
|
55
|
+
confirm_submit_title: "Confirmar envío",
|
|
56
|
+
confirm_submit_text: "¿Estás seguro de que deseas enviar este formulario?",
|
|
55
57
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dile/crud",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "Components to create a generic crud system based on Web Components and Lit",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "5c09eb3ba4a0f9fcc4235d670c00ab91bf68860c"
|
|
35
35
|
}
|