saasufy-components 7.4.0 → 7.6.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 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
 
@@ -4,13 +4,6 @@ class CollectionDeleter extends HTMLElement {
4
4
  this.attachShadow({ mode: 'open' });
5
5
  }
6
6
 
7
- static get observedAttributes() {
8
- return [
9
- 'model-id',
10
- 'confirm-message'
11
- ];
12
- }
13
-
14
7
  connectedCallback() {
15
8
  this.shadowRoot.innerHTML = `
16
9
  <slot></slot>
@@ -24,19 +17,45 @@ class CollectionDeleter extends HTMLElement {
24
17
  );
25
18
  }
26
19
 
27
- confirmDeleteItem() {
28
- let confirmMessage = this.getAttribute('confirm-message');
20
+ deleteItemField() {
21
+ let modelId = this.getAttribute('model-id');
22
+ let modelField = this.getAttribute('model-field');
23
+ this.dispatchEvent(
24
+ new CustomEvent('crudDelete', { detail: { id: modelId, field: modelField }, bubbles: true })
25
+ );
26
+ }
27
+
28
+ showConfirmModal(deleteField) {
29
+ let message = this.getAttribute('confirm-message');
30
+ let title = this.getAttribute('confirm-title');
31
+ let confirmButtonLabel = this.getAttribute('confirm-button-label');
32
+ let cancelButtonLabel = this.getAttribute('cancel-button-label');
29
33
  this.dispatchEvent(
30
34
  new CustomEvent('showModal', {
31
35
  detail: {
32
- message: confirmMessage,
36
+ message,
37
+ title,
38
+ confirmButtonLabel,
39
+ cancelButtonLabel,
33
40
  callback: () => {
34
- this.deleteItem();
41
+ if (deleteField) {
42
+ this.deleteItemField();
43
+ } else {
44
+ this.deleteItem();
45
+ }
35
46
  }
36
47
  },
37
48
  bubbles: true
38
49
  })
39
- )
50
+ );
51
+ }
52
+
53
+ confirmDeleteItem() {
54
+ this.showConfirmModal();
55
+ }
56
+
57
+ confirmDeleteItemField() {
58
+ this.showConfirmModal(true);
40
59
  }
41
60
  }
42
61
 
@@ -15,7 +15,8 @@ class CollectionViewer extends SocketConsumer {
15
15
  this.handleShowModalEvent = (event) => {
16
16
  event.stopPropagation();
17
17
  let modal = this.shadowRoot.querySelector('slot[name="modal"]').assignedNodes()[0];
18
- modal.show(event.detail.message, event.detail.callback);
18
+ let { callback, ...confirmOptions } = event.detail;
19
+ modal.show(confirmOptions, callback);
19
20
  };
20
21
 
21
22
  this.handleCRUDCreateEvent = async (event) => {
package/confirm-modal.js CHANGED
@@ -21,14 +21,29 @@ class ConfirmModal extends HTMLElement {
21
21
  this.render();
22
22
  }
23
23
 
24
- show(message, confirmCallback) {
24
+ show(options, confirmCallback) {
25
25
  let overlayModal = this.querySelector('overlay-modal');
26
26
  if (overlayModal) {
27
27
  overlayModal.removeAttribute('style');
28
28
  }
29
29
  this.confirmCallback = confirmCallback;
30
30
  this.hidden = false;
31
- this.setAttribute('message', message);
31
+ if (typeof options === 'string') {
32
+ this.setAttribute('message', options);
33
+ } else {
34
+ if (options.title != null) {
35
+ this.setAttribute('title', options.title);
36
+ }
37
+ if (options.confirmButtonLabel != null) {
38
+ this.setAttribute('confirm-button-label', options.confirmButtonLabel);
39
+ }
40
+ if (options.cancelButtonLabel != null) {
41
+ this.setAttribute('cancel-button-label', options.cancelButtonLabel);
42
+ }
43
+ if (options.message != null) {
44
+ this.setAttribute('message', options.message);
45
+ }
46
+ }
32
47
  }
33
48
 
34
49
  render() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "7.4.0",
3
+ "version": "7.6.0",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {