saasufy-components 7.4.0 → 7.5.0
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/README.md +1 -0
- package/collection-deleter.js +23 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -445,6 +445,7 @@ OR (with confirmation step)
|
|
|
445
445
|
- `model-id` (required): Specifies the ID of the resource to delete from the parent collection when this component is activated. This can be achieved by invoking either the `deleteItem()` or `confirmDeleteItem()` function from inside an event handler. The example above shows how to achieve deletion via the `onclick` event. You can either invoke `deleteItem()` to delete the resource immediately or you can invoke `confirmDeleteItem()` to require additional confirmation prior to deletion.
|
|
446
446
|
- `onclick` (required): The logic to execute to delete the item. Should be either `deleteItem()` or `confirmDeleteItem()`.
|
|
447
447
|
- `confirm-message`: The confirmation message to show the user when this component's `confirmDeleteItem()` function is invoked.
|
|
448
|
+
- `model-field`: If specified, this attribute can be used to delete a single field of a model instance, instead of the whole instance.
|
|
448
449
|
|
|
449
450
|
If `confirmDeleteItem()` is used, then the parent `collection-viewer` must have a `confirm-modal` element slotted into it as shown here:
|
|
450
451
|
|
package/collection-deleter.js
CHANGED
|
@@ -38,6 +38,29 @@ class CollectionDeleter extends HTMLElement {
|
|
|
38
38
|
})
|
|
39
39
|
)
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
deleteItemField() {
|
|
43
|
+
let modelId = this.getAttribute('model-id');
|
|
44
|
+
let modelField = this.getAttribute('model-field');
|
|
45
|
+
this.dispatchEvent(
|
|
46
|
+
new CustomEvent('crudDelete', { detail: { id: modelId, field: modelField }, bubbles: true })
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
confirmDeleteItemField() {
|
|
51
|
+
let confirmMessage = this.getAttribute('confirm-message');
|
|
52
|
+
this.dispatchEvent(
|
|
53
|
+
new CustomEvent('showModal', {
|
|
54
|
+
detail: {
|
|
55
|
+
message: confirmMessage,
|
|
56
|
+
callback: () => {
|
|
57
|
+
this.deleteItemField();
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
bubbles: true
|
|
61
|
+
})
|
|
62
|
+
)
|
|
63
|
+
}
|
|
41
64
|
}
|
|
42
65
|
|
|
43
66
|
window.customElements.define('collection-deleter', CollectionDeleter);
|