@unicef-polymer/etools-form-builder 2.1.0 → 2.1.2

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.
Files changed (87) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +1 -1
  3. package/dist/assets/translations.d.ts +6 -0
  4. package/dist/assets/translations.js +67 -0
  5. package/dist/form-attachments-popup/form-attachments-popup.d.ts +86 -85
  6. package/dist/form-attachments-popup/form-attachments-popup.helper.d.ts +8 -8
  7. package/dist/form-attachments-popup/form-attachments-popup.helper.js +14 -14
  8. package/dist/form-attachments-popup/form-attachments-popup.js +255 -248
  9. package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +3 -3
  10. package/dist/form-attachments-popup/form-attachments-popup.tpl.js +91 -89
  11. package/dist/form-attachments-popup/index.d.ts +2 -2
  12. package/dist/form-attachments-popup/index.js +2 -2
  13. package/dist/form-fields/abstract-field-base.class.d.ts +33 -28
  14. package/dist/form-fields/abstract-field-base.class.js +194 -176
  15. package/dist/form-fields/field-renderer-component.d.ts +20 -20
  16. package/dist/form-fields/field-renderer-component.js +249 -249
  17. package/dist/form-fields/index.d.ts +12 -12
  18. package/dist/form-fields/index.js +12 -12
  19. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.d.ts +17 -17
  20. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +209 -208
  21. package/dist/form-fields/repeatable-fields/repeatable-base-field.d.ts +20 -20
  22. package/dist/form-fields/repeatable-fields/repeatable-base-field.js +124 -123
  23. package/dist/form-fields/repeatable-fields/repeatable-number-field.d.ts +10 -10
  24. package/dist/form-fields/repeatable-fields/repeatable-number-field.js +67 -66
  25. package/dist/form-fields/repeatable-fields/repeatable-scale-field.d.ts +15 -15
  26. package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +108 -108
  27. package/dist/form-fields/repeatable-fields/repeatable-text-field.d.ts +8 -8
  28. package/dist/form-fields/repeatable-fields/repeatable-text-field.js +53 -53
  29. package/dist/form-fields/single-fields/attachment-field.d.ts +16 -16
  30. package/dist/form-fields/single-fields/attachment-field.js +98 -97
  31. package/dist/form-fields/single-fields/base-field.d.ts +11 -11
  32. package/dist/form-fields/single-fields/base-field.js +58 -57
  33. package/dist/form-fields/single-fields/boolean-field.d.ts +8 -8
  34. package/dist/form-fields/single-fields/boolean-field.js +49 -49
  35. package/dist/form-fields/single-fields/number-field.d.ts +10 -10
  36. package/dist/form-fields/single-fields/number-field.js +67 -66
  37. package/dist/form-fields/single-fields/scale-field.d.ts +18 -18
  38. package/dist/form-fields/single-fields/scale-field.js +108 -107
  39. package/dist/form-fields/single-fields/text-field.d.ts +8 -8
  40. package/dist/form-fields/single-fields/text-field.js +54 -54
  41. package/dist/form-groups/form-abstract-group.d.ts +65 -60
  42. package/dist/form-groups/form-abstract-group.js +375 -353
  43. package/dist/form-groups/form-card.d.ts +32 -32
  44. package/dist/form-groups/form-card.js +113 -108
  45. package/dist/form-groups/form-collapsed-card.d.ts +70 -70
  46. package/dist/form-groups/form-collapsed-card.js +254 -253
  47. package/dist/form-groups/index.d.ts +3 -3
  48. package/dist/form-groups/index.js +3 -3
  49. package/dist/index.d.ts +3 -3
  50. package/dist/index.js +3 -3
  51. package/dist/lib/additional-components/confirmation-dialog.d.ts +18 -16
  52. package/dist/lib/additional-components/confirmation-dialog.js +72 -65
  53. package/dist/lib/additional-components/etools-fb-card.d.ts +21 -16
  54. package/dist/lib/additional-components/etools-fb-card.js +238 -215
  55. package/dist/lib/styles/attachments.styles.d.ts +2 -2
  56. package/dist/lib/styles/attachments.styles.js +72 -72
  57. package/dist/lib/styles/card-styles.d.ts +2 -2
  58. package/dist/lib/styles/card-styles.js +154 -154
  59. package/dist/lib/styles/dialog.styles.d.ts +2 -2
  60. package/dist/lib/styles/dialog.styles.js +85 -85
  61. package/dist/lib/styles/elevation-styles.d.ts +9 -9
  62. package/dist/lib/styles/elevation-styles.js +43 -43
  63. package/dist/lib/styles/flex-layout-classes.d.ts +2 -2
  64. package/dist/lib/styles/flex-layout-classes.js +319 -319
  65. package/dist/lib/styles/form-builder-card.styles.d.ts +2 -2
  66. package/dist/lib/styles/form-builder-card.styles.js +49 -49
  67. package/dist/lib/styles/input-styles.d.ts +2 -2
  68. package/dist/lib/styles/input-styles.js +138 -138
  69. package/dist/lib/styles/page-layout-styles.d.ts +2 -2
  70. package/dist/lib/styles/page-layout-styles.js +201 -201
  71. package/dist/lib/styles/shared-styles.d.ts +2 -2
  72. package/dist/lib/styles/shared-styles.js +70 -70
  73. package/dist/lib/types/form-builder.interfaces.d.ts +83 -83
  74. package/dist/lib/types/form-builder.interfaces.js +0 -0
  75. package/dist/lib/types/form-builder.types.d.ts +59 -59
  76. package/dist/lib/types/form-builder.types.js +0 -0
  77. package/dist/lib/types/global.types.d.ts +4 -4
  78. package/dist/lib/types/global.types.js +0 -0
  79. package/dist/lib/utils/dialog.d.ts +10 -10
  80. package/dist/lib/utils/dialog.js +21 -21
  81. package/dist/lib/utils/fire-custom-event.d.ts +1 -1
  82. package/dist/lib/utils/fire-custom-event.js +7 -7
  83. package/dist/lib/utils/translate.d.ts +1 -0
  84. package/dist/lib/utils/translate.js +9 -0
  85. package/dist/lib/utils/validations.helper.d.ts +26 -26
  86. package/dist/lib/utils/validations.helper.js +42 -35
  87. package/package.json +56 -56
@@ -1,253 +1,254 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { html, property, customElement } from 'lit-element';
8
- import { clone } from 'ramda';
9
- import { fireEvent } from '../lib/utils/fire-custom-event';
10
- import { openDialog } from '../lib/utils/dialog';
11
- import { FormAbstractGroup, StructureTypes } from './form-abstract-group';
12
- import '../lib/additional-components/etools-fb-card';
13
- import '../lib/additional-components/confirmation-dialog';
14
- const PARTNER_KEY = 'partner';
15
- const OUTPUT_KEY = 'output';
16
- const INTERVENTION_KEY = 'intervention';
17
- let FormCollapsedCard = class FormCollapsedCard extends FormAbstractGroup {
18
- constructor() {
19
- super(...arguments);
20
- this.isEditMode = false;
21
- this._readonly = true;
22
- this._value = {};
23
- this.originalValue = {};
24
- }
25
- /**
26
- * Overrides readonly property
27
- * In collapsed card it must consider isEditMode property,
28
- * components inside card are readonly if isEditMode is off or if card is readonly
29
- */
30
- set readonly(state) {
31
- this._readonly = state;
32
- }
33
- get readonly() {
34
- return this._readonly || !this.isEditMode;
35
- }
36
- /**
37
- * Overrides errors setter
38
- * In collapsed card it must consider isEditMode property,
39
- * We must to enable isEditMode if errors comes from backend
40
- */
41
- set errors(errors) {
42
- if (Array.isArray(errors)) {
43
- fireEvent(this, 'toast', { text: errors[0] });
44
- fireEvent(this, 'error-changed', { error: null });
45
- }
46
- else if (errors) {
47
- this._errors = errors;
48
- }
49
- if (errors) {
50
- this.isEditMode = true;
51
- }
52
- }
53
- /**
54
- * Overrides value property
55
- * We need to save originalValue to have Cancel possibility in collapsed card.
56
- * Don't override current edited value if isEditMode enabled
57
- * (It can be happened if other sibling card or component updates their value during current card edition)
58
- */
59
- set value(value) {
60
- this.originalValue = value;
61
- if (!this.isEditMode) {
62
- this._value = clone(value);
63
- }
64
- }
65
- get value() {
66
- return this._value;
67
- }
68
- /**
69
- * Extends parent render method for handling additional types (StructureTypes.ATTACHMENTS_BUTTON in our case)
70
- * and adds etools-card as container wrapper
71
- */
72
- render() {
73
- return html `
74
- <section class="elevation page-content card-container" elevation="1">
75
- <etools-fb-card
76
- card-title="${this.retrieveTitle(this.parentGroupName) + this.groupStructure.title}"
77
- is-collapsible
78
- ?is-editable="${!this._readonly}"
79
- ?edit="${this.isEditMode}"
80
- @start-edit="${() => this.startEdit()}"
81
- @save="${() => this.saveChanges()}"
82
- @cancel="${() => this.cancelEdit()}"
83
- >
84
- <!-- Open Attachments popup button -->
85
- <div slot="actions" class="layout horizontal center">${this.getAdditionalButtons()}</div>
86
- <div slot="postfix" class="layout horizontal center" ?hidden="${!this.groupStructure.repeatable}">
87
- <paper-icon-button
88
- icon="close"
89
- class="attachments-warning"
90
- @click="${() => this.confirmRemove(this.groupStructure.title || 'this group')}"
91
- ></paper-icon-button>
92
- </div>
93
- <div slot="content">${this.renderGroupChildren()}</div>
94
- </etools-fb-card>
95
- </section>
96
- `;
97
- }
98
- /**
99
- * Filters StructureTypes.ATTACHMENTS_BUTTON type. It will be rendered as button,
100
- * allows parent renderChild method to render other types
101
- */
102
- renderGroupChildren() {
103
- return this.groupStructure.children
104
- .filter(({ styling }) => !styling.includes(StructureTypes.ATTACHMENTS_BUTTON))
105
- .map((child) => super.renderChild(child));
106
- }
107
- /**
108
- * Generate open Attachments popup button.
109
- * It is hidden if tab is readonly and no attachments uploaded
110
- */
111
- getAdditionalButtons() {
112
- var _a, _b, _c, _d, _e, _f;
113
- const hideAttachmentsButton = (this._readonly && !((_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.attachments) === null || _b === void 0 ? void 0 : _b.length)) ||
114
- !this.groupStructure.children.some(({ styling }) => styling.includes(StructureTypes.ATTACHMENTS_BUTTON));
115
- return hideAttachmentsButton
116
- ? html ``
117
- : html `
118
- <iron-icon icon="warning" class="attachments-warning" ?hidden="${!this._errors.attachments}"></iron-icon>
119
- <paper-button @click="${() => this.openAttachmentsPopup()}" class="attachments-button">
120
- <iron-icon icon="${((_d = (_c = this.value) === null || _c === void 0 ? void 0 : _c.attachments) === null || _d === void 0 ? void 0 : _d.length) ? 'file-download' : 'file-upload'}"></iron-icon>
121
- ${this.getAttachmentsBtnText((_f = (_e = this.value) === null || _e === void 0 ? void 0 : _e.attachments) === null || _f === void 0 ? void 0 : _f.length)}
122
- </paper-button>
123
- `;
124
- }
125
- retrieveTitle(target) {
126
- switch (target) {
127
- case PARTNER_KEY:
128
- return `Partner: `;
129
- case OUTPUT_KEY:
130
- return `Output: `;
131
- case INTERVENTION_KEY:
132
- return `PD/SSFA: `;
133
- default:
134
- return '';
135
- }
136
- }
137
- startEdit() {
138
- if (this._readonly) {
139
- return;
140
- }
141
- this.isEditMode = true;
142
- }
143
- /**
144
- * We need to rerender view to update all changes that was happen,
145
- * because only fields are updating during @value-change event.
146
- * Only then we can reset all changed values to their original
147
- */
148
- cancelEdit() {
149
- this.requestUpdate().then(() => {
150
- this._value = clone(this.originalValue);
151
- this.isEditMode = false;
152
- });
153
- }
154
- /**
155
- * Updates value property, stops event propagation.
156
- * We need to fire value-changed event only after save button click
157
- */
158
- valueChanged(event, name) {
159
- event.stopPropagation();
160
- if (!this._value) {
161
- this._value = {};
162
- }
163
- if (this._value[name] !== event.detail.value) {
164
- this._value[name] = event.detail.value;
165
- }
166
- }
167
- saveChanges() {
168
- if (Object.keys(this._errors).length) {
169
- fireEvent(this, 'toast', { text: 'Please check all fields and try again' });
170
- return;
171
- }
172
- this.isEditMode = false;
173
- fireEvent(this, 'value-changed', { value: this.value });
174
- }
175
- /**
176
- * Tries to save changed attachments on popup confirm
177
- * Generates value-changed event with originalValue clone if isEditMode enabled.
178
- * In this case it will take only attachments changes and ignore other changes that may happen during card edit
179
- */
180
- openAttachmentsPopup() {
181
- var _a;
182
- if (!customElements.get('form-attachments-popup')) {
183
- throw new Error('Please define "form-attachments-popup" custom element!');
184
- }
185
- openDialog({
186
- dialog: 'form-attachments-popup',
187
- dialogData: {
188
- attachments: (_a = this.value) === null || _a === void 0 ? void 0 : _a.attachments,
189
- metadata: this.metadata,
190
- title: `Attachments for ${this.retrieveTitle(this.parentGroupName) + ': ' + this.groupStructure.title}`,
191
- computedPath: this.computedPath.concat([this.groupStructure.name, 'attachments']),
192
- errors: this._errors.attachments
193
- },
194
- readonly: this._readonly
195
- }).then((response) => {
196
- if (!response.confirmed) {
197
- return;
198
- }
199
- if (!this._value) {
200
- this._value = {};
201
- }
202
- this._value.attachments = response.attachments;
203
- delete this._errors.attachments;
204
- fireEvent(this, 'error-changed', { error: Object.keys(this._errors).length ? this._errors : null });
205
- fireEvent(this, 'attachments-changed', { attachments: this._value.attachments });
206
- if (this.isEditMode) {
207
- const tmp = clone(this.originalValue) || {};
208
- tmp.attachments = response.attachments;
209
- fireEvent(this, 'value-changed', { value: tmp });
210
- }
211
- else {
212
- this.saveChanges();
213
- }
214
- this.requestUpdate();
215
- });
216
- }
217
- confirmRemove(groupName) {
218
- openDialog({
219
- dialog: 'confirmation-popup',
220
- dialogData: {
221
- text: `Are you sure you want to delete ${groupName}`
222
- }
223
- }).then((response) => {
224
- if (response.confirmed) {
225
- fireEvent(this, 'remove-group');
226
- }
227
- });
228
- }
229
- getAttachmentsBtnText(attachmentsCount = 0) {
230
- if (attachmentsCount === 1) {
231
- return `${attachmentsCount} File`;
232
- }
233
- else if (attachmentsCount > 1) {
234
- return `${attachmentsCount} Files`;
235
- }
236
- else {
237
- return 'Upload Files';
238
- }
239
- }
240
- };
241
- __decorate([
242
- property()
243
- ], FormCollapsedCard.prototype, "isEditMode", void 0);
244
- __decorate([
245
- property({ type: Boolean, attribute: 'readonly', reflect: true })
246
- ], FormCollapsedCard.prototype, "_readonly", void 0);
247
- __decorate([
248
- property()
249
- ], FormCollapsedCard.prototype, "_value", void 0);
250
- FormCollapsedCard = __decorate([
251
- customElement('form-collapsed-card')
252
- ], FormCollapsedCard);
253
- export { FormCollapsedCard };
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html, property, customElement } from 'lit-element';
8
+ import { clone } from 'ramda';
9
+ import { fireEvent } from '../lib/utils/fire-custom-event';
10
+ import { openDialog } from '../lib/utils/dialog';
11
+ import { FormAbstractGroup, StructureTypes } from './form-abstract-group';
12
+ import '../lib/additional-components/etools-fb-card';
13
+ import '../lib/additional-components/confirmation-dialog';
14
+ import { getTranslation } from '../lib/utils/translate';
15
+ const PARTNER_KEY = 'partner';
16
+ const OUTPUT_KEY = 'output';
17
+ const INTERVENTION_KEY = 'intervention';
18
+ let FormCollapsedCard = class FormCollapsedCard extends FormAbstractGroup {
19
+ constructor() {
20
+ super(...arguments);
21
+ this.isEditMode = false;
22
+ this._readonly = true;
23
+ this._value = {};
24
+ this.originalValue = {};
25
+ }
26
+ /**
27
+ * Overrides readonly property
28
+ * In collapsed card it must consider isEditMode property,
29
+ * components inside card are readonly if isEditMode is off or if card is readonly
30
+ */
31
+ set readonly(state) {
32
+ this._readonly = state;
33
+ }
34
+ get readonly() {
35
+ return this._readonly || !this.isEditMode;
36
+ }
37
+ /**
38
+ * Overrides errors setter
39
+ * In collapsed card it must consider isEditMode property,
40
+ * We must to enable isEditMode if errors comes from backend
41
+ */
42
+ set errors(errors) {
43
+ if (Array.isArray(errors)) {
44
+ fireEvent(this, 'toast', { text: errors[0] });
45
+ fireEvent(this, 'error-changed', { error: null });
46
+ }
47
+ else if (errors) {
48
+ this._errors = errors;
49
+ }
50
+ if (errors) {
51
+ this.isEditMode = true;
52
+ }
53
+ }
54
+ /**
55
+ * Overrides value property
56
+ * We need to save originalValue to have Cancel possibility in collapsed card.
57
+ * Don't override current edited value if isEditMode enabled
58
+ * (It can be happened if other sibling card or component updates their value during current card edition)
59
+ */
60
+ set value(value) {
61
+ this.originalValue = value;
62
+ if (!this.isEditMode) {
63
+ this._value = clone(value);
64
+ }
65
+ }
66
+ get value() {
67
+ return this._value;
68
+ }
69
+ /**
70
+ * Extends parent render method for handling additional types (StructureTypes.ATTACHMENTS_BUTTON in our case)
71
+ * and adds etools-card as container wrapper
72
+ */
73
+ render() {
74
+ return html `
75
+ <section class="elevation page-content card-container" elevation="1">
76
+ <etools-fb-card
77
+ card-title="${this.retrieveTitle(this.parentGroupName) + this.groupStructure.title}"
78
+ is-collapsible
79
+ ?is-editable="${!this._readonly}"
80
+ ?edit="${this.isEditMode}"
81
+ @start-edit="${() => this.startEdit()}"
82
+ @save="${() => this.saveChanges()}"
83
+ @cancel="${() => this.cancelEdit()}"
84
+ >
85
+ <!-- Open Attachments popup button -->
86
+ <div slot="actions" class="layout horizontal center">${this.getAdditionalButtons()}</div>
87
+ <div slot="postfix" class="layout horizontal center" ?hidden="${!this.groupStructure.repeatable}">
88
+ <paper-icon-button
89
+ icon="close"
90
+ class="attachments-warning"
91
+ @click="${() => this.confirmRemove(this.groupStructure.title || getTranslation(this.language, 'THIS_GROUP'))}"
92
+ ></paper-icon-button>
93
+ </div>
94
+ <div slot="content">${this.renderGroupChildren()}</div>
95
+ </etools-fb-card>
96
+ </section>
97
+ `;
98
+ }
99
+ /**
100
+ * Filters StructureTypes.ATTACHMENTS_BUTTON type. It will be rendered as button,
101
+ * allows parent renderChild method to render other types
102
+ */
103
+ renderGroupChildren() {
104
+ return this.groupStructure.children
105
+ .filter(({ styling }) => !styling.includes(StructureTypes.ATTACHMENTS_BUTTON))
106
+ .map((child) => super.renderChild(child));
107
+ }
108
+ /**
109
+ * Generate open Attachments popup button.
110
+ * It is hidden if tab is readonly and no attachments uploaded
111
+ */
112
+ getAdditionalButtons() {
113
+ var _a, _b, _c, _d, _e, _f;
114
+ const hideAttachmentsButton = (this._readonly && !((_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.attachments) === null || _b === void 0 ? void 0 : _b.length)) ||
115
+ !this.groupStructure.children.some(({ styling }) => styling.includes(StructureTypes.ATTACHMENTS_BUTTON));
116
+ return hideAttachmentsButton
117
+ ? html ``
118
+ : html `
119
+ <iron-icon icon="warning" class="attachments-warning" ?hidden="${!this._errors.attachments}"></iron-icon>
120
+ <paper-button @click="${() => this.openAttachmentsPopup()}" class="attachments-button">
121
+ <iron-icon icon="${((_d = (_c = this.value) === null || _c === void 0 ? void 0 : _c.attachments) === null || _d === void 0 ? void 0 : _d.length) ? 'file-download' : 'file-upload'}"></iron-icon>
122
+ ${this.getAttachmentsBtnText((_f = (_e = this.value) === null || _e === void 0 ? void 0 : _e.attachments) === null || _f === void 0 ? void 0 : _f.length)}
123
+ </paper-button>
124
+ `;
125
+ }
126
+ retrieveTitle(target) {
127
+ switch (target) {
128
+ case PARTNER_KEY:
129
+ return `${getTranslation(this.language, 'PARTNER')}: `;
130
+ case OUTPUT_KEY:
131
+ return `${getTranslation(this.language, 'CP_OUTPUT')}: `;
132
+ case INTERVENTION_KEY:
133
+ return `${getTranslation(this.language, 'PD_SSFA')}: `;
134
+ default:
135
+ return '';
136
+ }
137
+ }
138
+ startEdit() {
139
+ if (this._readonly) {
140
+ return;
141
+ }
142
+ this.isEditMode = true;
143
+ }
144
+ /**
145
+ * We need to rerender view to update all changes that was happen,
146
+ * because only fields are updating during @value-change event.
147
+ * Only then we can reset all changed values to their original
148
+ */
149
+ cancelEdit() {
150
+ this.requestUpdate().then(() => {
151
+ this._value = clone(this.originalValue);
152
+ this.isEditMode = false;
153
+ });
154
+ }
155
+ /**
156
+ * Updates value property, stops event propagation.
157
+ * We need to fire value-changed event only after save button click
158
+ */
159
+ valueChanged(event, name) {
160
+ event.stopPropagation();
161
+ if (!this._value) {
162
+ this._value = {};
163
+ }
164
+ if (this._value[name] !== event.detail.value) {
165
+ this._value[name] = event.detail.value;
166
+ }
167
+ }
168
+ saveChanges() {
169
+ if (Object.keys(this._errors).length) {
170
+ fireEvent(this, 'toast', { text: getTranslation(this.language, 'CHECK_FIELDS_TRY_AGAIN') });
171
+ return;
172
+ }
173
+ this.isEditMode = false;
174
+ fireEvent(this, 'value-changed', { value: this.value });
175
+ }
176
+ /**
177
+ * Tries to save changed attachments on popup confirm
178
+ * Generates value-changed event with originalValue clone if isEditMode enabled.
179
+ * In this case it will take only attachments changes and ignore other changes that may happen during card edit
180
+ */
181
+ openAttachmentsPopup() {
182
+ var _a;
183
+ if (!customElements.get('form-attachments-popup')) {
184
+ throw new Error('Please define "form-attachments-popup" custom element!');
185
+ }
186
+ openDialog({
187
+ dialog: 'form-attachments-popup',
188
+ dialogData: {
189
+ attachments: (_a = this.value) === null || _a === void 0 ? void 0 : _a.attachments,
190
+ metadata: this.metadata,
191
+ title: `${getTranslation(this.language, 'ATTACHMENTS_FOR')} ${this.retrieveTitle(this.parentGroupName) + ': ' + this.groupStructure.title}`,
192
+ computedPath: this.computedPath.concat([this.groupStructure.name, 'attachments']),
193
+ errors: this._errors.attachments
194
+ },
195
+ readonly: this._readonly
196
+ }).then((response) => {
197
+ if (!response.confirmed) {
198
+ return;
199
+ }
200
+ if (!this._value) {
201
+ this._value = {};
202
+ }
203
+ this._value.attachments = response.attachments;
204
+ delete this._errors.attachments;
205
+ fireEvent(this, 'error-changed', { error: Object.keys(this._errors).length ? this._errors : null });
206
+ fireEvent(this, 'attachments-changed', { attachments: this._value.attachments });
207
+ if (this.isEditMode) {
208
+ const tmp = clone(this.originalValue) || {};
209
+ tmp.attachments = response.attachments;
210
+ fireEvent(this, 'value-changed', { value: tmp });
211
+ }
212
+ else {
213
+ this.saveChanges();
214
+ }
215
+ this.requestUpdate();
216
+ });
217
+ }
218
+ confirmRemove(groupName) {
219
+ openDialog({
220
+ dialog: 'confirmation-popup',
221
+ dialogData: {
222
+ text: `${getTranslation(this.language, 'CONFIRM_DELETE')} ${groupName}`
223
+ }
224
+ }).then((response) => {
225
+ if (response.confirmed) {
226
+ fireEvent(this, 'remove-group');
227
+ }
228
+ });
229
+ }
230
+ getAttachmentsBtnText(attachmentsCount = 0) {
231
+ if (attachmentsCount === 1) {
232
+ return `${attachmentsCount} ${getTranslation(this.language, 'FILE')}`;
233
+ }
234
+ else if (attachmentsCount > 1) {
235
+ return `${attachmentsCount} ${getTranslation(this.language, 'FILES')}`;
236
+ }
237
+ else {
238
+ return getTranslation(this.language, 'UPLOAD_FILES');
239
+ }
240
+ }
241
+ };
242
+ __decorate([
243
+ property()
244
+ ], FormCollapsedCard.prototype, "isEditMode", void 0);
245
+ __decorate([
246
+ property({ type: Boolean, attribute: 'readonly', reflect: true })
247
+ ], FormCollapsedCard.prototype, "_readonly", void 0);
248
+ __decorate([
249
+ property()
250
+ ], FormCollapsedCard.prototype, "_value", void 0);
251
+ FormCollapsedCard = __decorate([
252
+ customElement('form-collapsed-card')
253
+ ], FormCollapsedCard);
254
+ export { FormCollapsedCard };
@@ -1,3 +1,3 @@
1
- export * from './form-abstract-group';
2
- export * from './form-card';
3
- export * from './form-collapsed-card';
1
+ export * from './form-abstract-group';
2
+ export * from './form-card';
3
+ export * from './form-collapsed-card';
@@ -1,3 +1,3 @@
1
- export * from './form-abstract-group';
2
- export * from './form-card';
3
- export * from './form-collapsed-card';
1
+ export * from './form-abstract-group';
2
+ export * from './form-card';
3
+ export * from './form-collapsed-card';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './form-fields';
2
- export * from './form-groups';
3
- export * from './form-attachments-popup';
1
+ export * from './form-fields';
2
+ export * from './form-groups';
3
+ export * from './form-attachments-popup';
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from './form-fields';
2
- export * from './form-groups';
3
- export * from './form-attachments-popup';
1
+ export * from './form-fields';
2
+ export * from './form-groups';
3
+ export * from './form-attachments-popup';
@@ -1,16 +1,18 @@
1
- import { LitElement, CSSResultArray } from 'lit-element';
2
- export declare class ConfirmationDialog extends LitElement {
3
- dialogOpened: boolean;
4
- text: string;
5
- dialogTitle: string;
6
- hideConfirmBtn: boolean;
7
- set dialogData({ text, dialogTitle, hideConfirmBtn }: {
8
- text: string;
9
- dialogTitle: string;
10
- hideConfirmBtn: boolean;
11
- });
12
- render(): unknown;
13
- onClose(): void;
14
- confirm(): void;
15
- static get styles(): CSSResultArray;
16
- }
1
+ import { LitElement, CSSResultArray } from 'lit-element';
2
+ export declare class ConfirmationDialog extends LitElement {
3
+ dialogOpened: boolean;
4
+ language: string;
5
+ text: string;
6
+ dialogTitle: string;
7
+ hideConfirmBtn: boolean;
8
+ set dialogData({ text, dialogTitle, hideConfirmBtn }: {
9
+ text: string;
10
+ dialogTitle: string;
11
+ hideConfirmBtn: boolean;
12
+ });
13
+ constructor();
14
+ render(): unknown;
15
+ onClose(): void;
16
+ confirm(): void;
17
+ static get styles(): CSSResultArray;
18
+ }