@unicef-polymer/etools-form-builder 2.1.7 → 2.1.9

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