@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.
- package/LICENSE +674 -674
- package/README.md +1 -1
- package/dist/assets/translations.d.ts +6 -0
- package/dist/assets/translations.js +67 -0
- package/dist/form-attachments-popup/form-attachments-popup.d.ts +86 -85
- package/dist/form-attachments-popup/form-attachments-popup.helper.d.ts +8 -8
- package/dist/form-attachments-popup/form-attachments-popup.helper.js +14 -14
- package/dist/form-attachments-popup/form-attachments-popup.js +255 -248
- package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +3 -3
- package/dist/form-attachments-popup/form-attachments-popup.tpl.js +91 -89
- package/dist/form-attachments-popup/index.d.ts +2 -2
- package/dist/form-attachments-popup/index.js +2 -2
- package/dist/form-fields/abstract-field-base.class.d.ts +33 -28
- package/dist/form-fields/abstract-field-base.class.js +194 -176
- package/dist/form-fields/field-renderer-component.d.ts +20 -20
- package/dist/form-fields/field-renderer-component.js +249 -249
- package/dist/form-fields/index.d.ts +12 -12
- package/dist/form-fields/index.js +12 -12
- package/dist/form-fields/repeatable-fields/repeatable-attachment-field.d.ts +17 -17
- package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +209 -208
- package/dist/form-fields/repeatable-fields/repeatable-base-field.d.ts +20 -20
- package/dist/form-fields/repeatable-fields/repeatable-base-field.js +124 -123
- package/dist/form-fields/repeatable-fields/repeatable-number-field.d.ts +10 -10
- package/dist/form-fields/repeatable-fields/repeatable-number-field.js +67 -66
- package/dist/form-fields/repeatable-fields/repeatable-scale-field.d.ts +15 -15
- package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +108 -108
- package/dist/form-fields/repeatable-fields/repeatable-text-field.d.ts +8 -8
- package/dist/form-fields/repeatable-fields/repeatable-text-field.js +53 -53
- package/dist/form-fields/single-fields/attachment-field.d.ts +16 -16
- package/dist/form-fields/single-fields/attachment-field.js +98 -97
- package/dist/form-fields/single-fields/base-field.d.ts +11 -11
- package/dist/form-fields/single-fields/base-field.js +58 -57
- package/dist/form-fields/single-fields/boolean-field.d.ts +8 -8
- package/dist/form-fields/single-fields/boolean-field.js +49 -49
- package/dist/form-fields/single-fields/number-field.d.ts +10 -10
- package/dist/form-fields/single-fields/number-field.js +67 -66
- package/dist/form-fields/single-fields/scale-field.d.ts +18 -18
- package/dist/form-fields/single-fields/scale-field.js +108 -107
- package/dist/form-fields/single-fields/text-field.d.ts +8 -8
- package/dist/form-fields/single-fields/text-field.js +54 -54
- package/dist/form-groups/form-abstract-group.d.ts +65 -60
- package/dist/form-groups/form-abstract-group.js +375 -353
- package/dist/form-groups/form-card.d.ts +32 -32
- package/dist/form-groups/form-card.js +113 -108
- package/dist/form-groups/form-collapsed-card.d.ts +70 -70
- package/dist/form-groups/form-collapsed-card.js +254 -253
- package/dist/form-groups/index.d.ts +3 -3
- package/dist/form-groups/index.js +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/lib/additional-components/confirmation-dialog.d.ts +18 -16
- package/dist/lib/additional-components/confirmation-dialog.js +72 -65
- package/dist/lib/additional-components/etools-fb-card.d.ts +21 -16
- package/dist/lib/additional-components/etools-fb-card.js +238 -215
- package/dist/lib/styles/attachments.styles.d.ts +2 -2
- package/dist/lib/styles/attachments.styles.js +72 -72
- package/dist/lib/styles/card-styles.d.ts +2 -2
- package/dist/lib/styles/card-styles.js +154 -154
- package/dist/lib/styles/dialog.styles.d.ts +2 -2
- package/dist/lib/styles/dialog.styles.js +85 -85
- package/dist/lib/styles/elevation-styles.d.ts +9 -9
- package/dist/lib/styles/elevation-styles.js +43 -43
- package/dist/lib/styles/flex-layout-classes.d.ts +2 -2
- package/dist/lib/styles/flex-layout-classes.js +319 -319
- package/dist/lib/styles/form-builder-card.styles.d.ts +2 -2
- package/dist/lib/styles/form-builder-card.styles.js +49 -49
- package/dist/lib/styles/input-styles.d.ts +2 -2
- package/dist/lib/styles/input-styles.js +138 -138
- package/dist/lib/styles/page-layout-styles.d.ts +2 -2
- package/dist/lib/styles/page-layout-styles.js +201 -201
- package/dist/lib/styles/shared-styles.d.ts +2 -2
- package/dist/lib/styles/shared-styles.js +70 -70
- package/dist/lib/types/form-builder.interfaces.d.ts +83 -83
- package/dist/lib/types/form-builder.interfaces.js +0 -0
- package/dist/lib/types/form-builder.types.d.ts +59 -59
- package/dist/lib/types/form-builder.types.js +0 -0
- package/dist/lib/types/global.types.d.ts +4 -4
- package/dist/lib/types/global.types.js +0 -0
- package/dist/lib/utils/dialog.d.ts +10 -10
- package/dist/lib/utils/dialog.js +21 -21
- package/dist/lib/utils/fire-custom-event.d.ts +1 -1
- package/dist/lib/utils/fire-custom-event.js +7 -7
- package/dist/lib/utils/translate.d.ts +1 -0
- package/dist/lib/utils/translate.js +9 -0
- package/dist/lib/utils/validations.helper.d.ts +26 -26
- package/dist/lib/utils/validations.helper.js +42 -35
- package/package.json +56 -56
|
@@ -1,353 +1,375 @@
|
|
|
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 { LitElement, property, html, css, customElement } from 'lit-element';
|
|
8
|
-
import '../form-fields/single-fields/text-field';
|
|
9
|
-
import '../form-fields/single-fields/number-field';
|
|
10
|
-
import '../form-fields/single-fields/scale-field';
|
|
11
|
-
import '@polymer/paper-input/paper-textarea';
|
|
12
|
-
import { SharedStyles } from '../lib/styles/shared-styles';
|
|
13
|
-
import { pageLayoutStyles } from '../lib/styles/page-layout-styles';
|
|
14
|
-
import { elevationStyles } from '../lib/styles/elevation-styles';
|
|
15
|
-
import { CardStyles } from '../lib/styles/card-styles';
|
|
16
|
-
import { FlexLayoutClasses } from '../lib/styles/flex-layout-classes';
|
|
17
|
-
import { fireEvent } from '../lib/utils/fire-custom-event';
|
|
18
|
-
import { clone } from 'ramda';
|
|
19
|
-
import { live } from 'lit-html/directives/live';
|
|
20
|
-
import { openDialog } from '../lib/utils/dialog';
|
|
21
|
-
import { FormBuilderCardStyles } from '../lib/styles/form-builder-card.styles';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
FieldTypes["
|
|
26
|
-
FieldTypes["
|
|
27
|
-
FieldTypes["
|
|
28
|
-
FieldTypes["
|
|
29
|
-
FieldTypes["
|
|
30
|
-
FieldTypes["
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
StructureTypes["
|
|
36
|
-
StructureTypes["
|
|
37
|
-
StructureTypes["
|
|
38
|
-
StructureTypes["
|
|
39
|
-
StructureTypes["
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
.
|
|
164
|
-
.
|
|
165
|
-
.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
.
|
|
179
|
-
.
|
|
180
|
-
.
|
|
181
|
-
.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
this.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
fireEvent(this, '
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
value.
|
|
251
|
-
this.valueChanged({ detail: { value } },
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
.
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
302
|
-
.
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
.
|
|
322
|
-
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
]
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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 { LitElement, property, html, css, customElement } from 'lit-element';
|
|
8
|
+
import '../form-fields/single-fields/text-field';
|
|
9
|
+
import '../form-fields/single-fields/number-field';
|
|
10
|
+
import '../form-fields/single-fields/scale-field';
|
|
11
|
+
import '@polymer/paper-input/paper-textarea';
|
|
12
|
+
import { SharedStyles } from '../lib/styles/shared-styles';
|
|
13
|
+
import { pageLayoutStyles } from '../lib/styles/page-layout-styles';
|
|
14
|
+
import { elevationStyles } from '../lib/styles/elevation-styles';
|
|
15
|
+
import { CardStyles } from '../lib/styles/card-styles';
|
|
16
|
+
import { FlexLayoutClasses } from '../lib/styles/flex-layout-classes';
|
|
17
|
+
import { fireEvent } from '../lib/utils/fire-custom-event';
|
|
18
|
+
import { clone } from 'ramda';
|
|
19
|
+
import { live } from 'lit-html/directives/live';
|
|
20
|
+
import { openDialog } from '../lib/utils/dialog';
|
|
21
|
+
import { FormBuilderCardStyles } from '../lib/styles/form-builder-card.styles';
|
|
22
|
+
import { getTranslation } from '../lib/utils/translate';
|
|
23
|
+
export var FieldTypes;
|
|
24
|
+
(function (FieldTypes) {
|
|
25
|
+
FieldTypes["FILE_TYPE"] = "file";
|
|
26
|
+
FieldTypes["TEXT_TYPE"] = "text";
|
|
27
|
+
FieldTypes["NUMBER_TYPE"] = "number";
|
|
28
|
+
FieldTypes["BOOL_TYPE"] = "bool";
|
|
29
|
+
FieldTypes["SCALE_TYPE"] = "likert_scale";
|
|
30
|
+
FieldTypes["NUMBER_INTEGER_TYPE"] = "number-integer";
|
|
31
|
+
FieldTypes["NUMBER_FLOAT_TYPE"] = "number-float";
|
|
32
|
+
})(FieldTypes || (FieldTypes = {}));
|
|
33
|
+
export var StructureTypes;
|
|
34
|
+
(function (StructureTypes) {
|
|
35
|
+
StructureTypes["WIDE"] = "wide";
|
|
36
|
+
StructureTypes["ADDITIONAL"] = "additional";
|
|
37
|
+
StructureTypes["CARD"] = "card";
|
|
38
|
+
StructureTypes["ABSTRACT"] = "abstract";
|
|
39
|
+
StructureTypes["COLLAPSED"] = "collapse";
|
|
40
|
+
StructureTypes["ATTACHMENTS_BUTTON"] = "floating_attachments";
|
|
41
|
+
})(StructureTypes || (StructureTypes = {}));
|
|
42
|
+
let FormAbstractGroup = class FormAbstractGroup extends LitElement {
|
|
43
|
+
constructor() {
|
|
44
|
+
super();
|
|
45
|
+
this.parentGroupName = '';
|
|
46
|
+
this.readonly = false;
|
|
47
|
+
this._errors = {};
|
|
48
|
+
this._value = {};
|
|
49
|
+
this.computedPath = [];
|
|
50
|
+
if (!this.language) {
|
|
51
|
+
this.language = window.localStorage.defaultLanguage || 'en';
|
|
52
|
+
}
|
|
53
|
+
this.handleLanguageChange = this.handleLanguageChange.bind(this);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Make value property immutable
|
|
57
|
+
* @param value
|
|
58
|
+
*/
|
|
59
|
+
set value(value) {
|
|
60
|
+
this._value = this.groupStructure.name === 'root' ? clone(value) : value;
|
|
61
|
+
}
|
|
62
|
+
get value() {
|
|
63
|
+
return this._value;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Setter for handling error.
|
|
67
|
+
* Normally we wouldn't have errors as string or string[] for FormGroups.
|
|
68
|
+
* In cases they appear - show toast with error text and reset it.
|
|
69
|
+
* Otherwise it will be impossible to clear that error from field elements
|
|
70
|
+
* @param errors
|
|
71
|
+
*/
|
|
72
|
+
set errors(errors) {
|
|
73
|
+
if (Array.isArray(errors)) {
|
|
74
|
+
fireEvent(this, 'toast', { text: errors[0] });
|
|
75
|
+
fireEvent(this, 'error-changed', { error: null });
|
|
76
|
+
}
|
|
77
|
+
else if (errors) {
|
|
78
|
+
this._errors = errors;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
connectedCallback() {
|
|
82
|
+
super.connectedCallback();
|
|
83
|
+
document.addEventListener('language-changed', this.handleLanguageChange.bind(this));
|
|
84
|
+
}
|
|
85
|
+
disconnectedCallback() {
|
|
86
|
+
super.disconnectedCallback();
|
|
87
|
+
document.removeEventListener('language-changed', this.handleLanguageChange.bind(this));
|
|
88
|
+
}
|
|
89
|
+
handleLanguageChange(e) {
|
|
90
|
+
this.language = e.detail.language;
|
|
91
|
+
}
|
|
92
|
+
render() {
|
|
93
|
+
if (!this.groupStructure || !this.metadata) {
|
|
94
|
+
return html ``;
|
|
95
|
+
}
|
|
96
|
+
return html `
|
|
97
|
+
${this.groupStructure.children.map((child) => this.renderChild(child))}
|
|
98
|
+
`;
|
|
99
|
+
}
|
|
100
|
+
renderChild(child) {
|
|
101
|
+
const type = child.type;
|
|
102
|
+
switch (child.type) {
|
|
103
|
+
case 'field':
|
|
104
|
+
return this.renderField(child);
|
|
105
|
+
case 'group':
|
|
106
|
+
return this.renderGroup(child);
|
|
107
|
+
case 'information':
|
|
108
|
+
return this.renderInformation(child);
|
|
109
|
+
default:
|
|
110
|
+
console.warn(`FormBuilderGroup: Unknown group type ${type}. Please, specify rendering method`);
|
|
111
|
+
return html ``;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
renderField(blueprintField) {
|
|
115
|
+
var _a;
|
|
116
|
+
return html `
|
|
117
|
+
<field-renderer
|
|
118
|
+
.field="${blueprintField}"
|
|
119
|
+
?readonly="${live(this.readonly)}"
|
|
120
|
+
.value="${this.value && this.value[blueprintField.name]}"
|
|
121
|
+
.validations="${blueprintField.validations.map((validation) => this.metadata.validations[validation])}"
|
|
122
|
+
.errorMessage="${this.getErrorMessage(blueprintField.name)}"
|
|
123
|
+
.options="${((_a = this.metadata.options[blueprintField.options_key || '']) === null || _a === void 0 ? void 0 : _a.values) || []}"
|
|
124
|
+
.computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [blueprintField.name] : [this.groupStructure.name, blueprintField.name])}"
|
|
125
|
+
@value-changed="${(event) => this.valueChanged(event, blueprintField.name)}"
|
|
126
|
+
@error-changed="${(event) => this.errorChanged(event, blueprintField.name)}"
|
|
127
|
+
></field-renderer>
|
|
128
|
+
`;
|
|
129
|
+
}
|
|
130
|
+
renderInformation(information) {
|
|
131
|
+
return html `<section class="elevation page-content" elevation="1">${information.text}</section>`;
|
|
132
|
+
}
|
|
133
|
+
renderGroup(groupStructure) {
|
|
134
|
+
if (!groupStructure.repeatable) {
|
|
135
|
+
return this.getGroupTemplate(groupStructure);
|
|
136
|
+
}
|
|
137
|
+
const value = (this.value && this.value[groupStructure.name]) || [{}];
|
|
138
|
+
return html `
|
|
139
|
+
${value.map((_, index) => this.getGroupTemplate(groupStructure, index))}
|
|
140
|
+
<paper-button class="add-group save-button" @click="${() => this.addGroup(groupStructure.name)}">
|
|
141
|
+
${getTranslation(this.language, 'ADD')}
|
|
142
|
+
${!groupStructure.title || groupStructure.title.length > 15
|
|
143
|
+
? getTranslation(this.language, 'GROUP')
|
|
144
|
+
: groupStructure.title}
|
|
145
|
+
</paper-button>
|
|
146
|
+
`;
|
|
147
|
+
}
|
|
148
|
+
getGroupTemplate(groupStructure, index) {
|
|
149
|
+
const isAbstract = groupStructure.styling.includes(StructureTypes.ABSTRACT);
|
|
150
|
+
const isCard = groupStructure.styling.includes(StructureTypes.CARD);
|
|
151
|
+
const isCollapsed = groupStructure.styling.includes(StructureTypes.COLLAPSED);
|
|
152
|
+
let value = this.value && this.value[groupStructure.name];
|
|
153
|
+
if (typeof index === 'number') {
|
|
154
|
+
value = value && value[index];
|
|
155
|
+
}
|
|
156
|
+
let errors = this._errors[groupStructure.name];
|
|
157
|
+
if (typeof index === 'number') {
|
|
158
|
+
errors = errors && errors[index];
|
|
159
|
+
}
|
|
160
|
+
if (isAbstract) {
|
|
161
|
+
return html `
|
|
162
|
+
<form-abstract-group
|
|
163
|
+
.groupStructure="${groupStructure}"
|
|
164
|
+
.value="${value}"
|
|
165
|
+
.metadata="${this.metadata}"
|
|
166
|
+
.parentGroupName="${this.groupStructure.name}"
|
|
167
|
+
.computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
|
|
168
|
+
.readonly="${this.readonly}"
|
|
169
|
+
.errors="${errors || null}"
|
|
170
|
+
@value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
|
|
171
|
+
@error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
|
|
172
|
+
></form-abstract-group>
|
|
173
|
+
`;
|
|
174
|
+
}
|
|
175
|
+
else if (isCard && isCollapsed) {
|
|
176
|
+
return html `
|
|
177
|
+
<form-collapsed-card
|
|
178
|
+
.groupStructure="${groupStructure}"
|
|
179
|
+
.value="${value}"
|
|
180
|
+
.metadata="${this.metadata}"
|
|
181
|
+
.parentGroupName="${this.groupStructure.name}"
|
|
182
|
+
.computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
|
|
183
|
+
.readonly="${this.readonly}"
|
|
184
|
+
.errors="${errors || null}"
|
|
185
|
+
@remove-group="${() => this.removeGroup(groupStructure, index)}"
|
|
186
|
+
@value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
|
|
187
|
+
@error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
|
|
188
|
+
></form-collapsed-card>
|
|
189
|
+
`;
|
|
190
|
+
}
|
|
191
|
+
else if (isCard) {
|
|
192
|
+
return html `
|
|
193
|
+
<form-card
|
|
194
|
+
.groupStructure="${groupStructure}"
|
|
195
|
+
.value="${value}"
|
|
196
|
+
.metadata="${this.metadata}"
|
|
197
|
+
.parentGroupName="${this.groupStructure.name}"
|
|
198
|
+
.computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
|
|
199
|
+
.readonly="${this.readonly}"
|
|
200
|
+
.errors="${errors || null}"
|
|
201
|
+
@remove-group="${() => this.removeGroup(groupStructure, index)}"
|
|
202
|
+
@value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
|
|
203
|
+
@error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
|
|
204
|
+
></form-card>
|
|
205
|
+
`;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
console.warn(`FormBuilderGroup: Unknown group type: ${groupStructure.styling}`);
|
|
209
|
+
return html ``;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
valueChanged(event, name, index) {
|
|
213
|
+
if (!this.value) {
|
|
214
|
+
this.value = {};
|
|
215
|
+
}
|
|
216
|
+
if (typeof index === 'number') {
|
|
217
|
+
const value = this.value[name] || [];
|
|
218
|
+
value[index] = event.detail.value;
|
|
219
|
+
this.value[name] = value;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
this.value[name] = event.detail.value;
|
|
223
|
+
}
|
|
224
|
+
if (event.stopPropagation) {
|
|
225
|
+
event.stopPropagation();
|
|
226
|
+
}
|
|
227
|
+
fireEvent(this, 'value-changed', { value: this.value });
|
|
228
|
+
this.requestUpdate();
|
|
229
|
+
}
|
|
230
|
+
errorChanged(event, name, index) {
|
|
231
|
+
const errorMessage = event.detail.error;
|
|
232
|
+
if (typeof index === 'number') {
|
|
233
|
+
const errors = this._errors[name] || (this.value && new Array(this.value[name].length).fill(null)) || [];
|
|
234
|
+
errors.splice(index, 1, errorMessage);
|
|
235
|
+
const hasErrors = errors.some((error) => error !== null);
|
|
236
|
+
this._errors[name] = hasErrors ? errors : null;
|
|
237
|
+
}
|
|
238
|
+
else if (errorMessage) {
|
|
239
|
+
this._errors[name] = errorMessage;
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
delete this._errors[name];
|
|
243
|
+
}
|
|
244
|
+
event.stopPropagation();
|
|
245
|
+
const errors = Object.keys(this._errors).length ? this._errors : null;
|
|
246
|
+
fireEvent(this, 'error-changed', { error: errors });
|
|
247
|
+
}
|
|
248
|
+
addGroup(name) {
|
|
249
|
+
const value = this.value[name] || [];
|
|
250
|
+
value.push({});
|
|
251
|
+
this.valueChanged({ detail: { value } }, name);
|
|
252
|
+
}
|
|
253
|
+
removeGroup(group, index) {
|
|
254
|
+
if (typeof index !== 'number') {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const value = (this.value && this.value[group.name]) || [];
|
|
258
|
+
if (group.required && value.length < 2) {
|
|
259
|
+
openDialog({
|
|
260
|
+
dialog: 'confirmation-popup',
|
|
261
|
+
dialogData: {
|
|
262
|
+
text: getTranslation(this.language, 'GROUP_REQUIRED'),
|
|
263
|
+
hideConfirmBtn: true,
|
|
264
|
+
dialogTitle: ''
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
value.splice(index, 1);
|
|
270
|
+
this.valueChanged({ detail: { value } }, group.name);
|
|
271
|
+
}
|
|
272
|
+
getErrorMessage(fieldName) {
|
|
273
|
+
const error = this._errors && this._errors[fieldName];
|
|
274
|
+
return Array.isArray(error) ? error[0] : error || null;
|
|
275
|
+
}
|
|
276
|
+
static get styles() {
|
|
277
|
+
// language=CSS
|
|
278
|
+
return [
|
|
279
|
+
SharedStyles,
|
|
280
|
+
pageLayoutStyles,
|
|
281
|
+
elevationStyles,
|
|
282
|
+
CardStyles,
|
|
283
|
+
FlexLayoutClasses,
|
|
284
|
+
FormBuilderCardStyles,
|
|
285
|
+
css `
|
|
286
|
+
:host {
|
|
287
|
+
display: flex;
|
|
288
|
+
flex-direction: column;
|
|
289
|
+
}
|
|
290
|
+
.add-group {
|
|
291
|
+
align-self: flex-end;
|
|
292
|
+
margin-right: 23px;
|
|
293
|
+
margin-top: 20px;
|
|
294
|
+
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12),
|
|
295
|
+
0 2px 4px -1px rgba(0, 0, 0, 0.4);
|
|
296
|
+
}
|
|
297
|
+
.card-header {
|
|
298
|
+
display: flex;
|
|
299
|
+
align-items: center;
|
|
300
|
+
justify-content: space-between;
|
|
301
|
+
}
|
|
302
|
+
.card-header .remove-group {
|
|
303
|
+
display: flex;
|
|
304
|
+
align-items: center;
|
|
305
|
+
justify-content: flex-end;
|
|
306
|
+
padding: 0 10px 8px;
|
|
307
|
+
cursor: pointer;
|
|
308
|
+
width: min-content;
|
|
309
|
+
white-space: nowrap;
|
|
310
|
+
}
|
|
311
|
+
.card-header .title {
|
|
312
|
+
padding: 0 24px 8px;
|
|
313
|
+
font-size: 18px;
|
|
314
|
+
font-weight: bold;
|
|
315
|
+
}
|
|
316
|
+
.save-button {
|
|
317
|
+
margin-top: 8px;
|
|
318
|
+
color: var(--primary-background-color);
|
|
319
|
+
background-color: var(--primary-color);
|
|
320
|
+
}
|
|
321
|
+
.information-source {
|
|
322
|
+
padding: 0.5% 2% 0.5% 1%;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.additional-field {
|
|
326
|
+
padding-top: 15px;
|
|
327
|
+
padding-bottom: 20px;
|
|
328
|
+
background-color: var(--secondary-background-color);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.actions-container {
|
|
332
|
+
padding: 0 25px 5px 45px;
|
|
333
|
+
box-sizing: border-box;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
.card-container.form-card {
|
|
337
|
+
padding: 12px 0 15px;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.attachments-warning {
|
|
341
|
+
color: red;
|
|
342
|
+
}
|
|
343
|
+
paper-icon-button[icon='close'] {
|
|
344
|
+
cursor: pointer;
|
|
345
|
+
color: var(--primary-text-color);
|
|
346
|
+
}
|
|
347
|
+
`
|
|
348
|
+
];
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
__decorate([
|
|
352
|
+
property({ type: Object })
|
|
353
|
+
], FormAbstractGroup.prototype, "groupStructure", void 0);
|
|
354
|
+
__decorate([
|
|
355
|
+
property({ type: Object })
|
|
356
|
+
], FormAbstractGroup.prototype, "metadata", void 0);
|
|
357
|
+
__decorate([
|
|
358
|
+
property({ type: String })
|
|
359
|
+
], FormAbstractGroup.prototype, "parentGroupName", void 0);
|
|
360
|
+
__decorate([
|
|
361
|
+
property()
|
|
362
|
+
], FormAbstractGroup.prototype, "language", void 0);
|
|
363
|
+
__decorate([
|
|
364
|
+
property({ type: Boolean, attribute: 'readonly' })
|
|
365
|
+
], FormAbstractGroup.prototype, "readonly", void 0);
|
|
366
|
+
__decorate([
|
|
367
|
+
property()
|
|
368
|
+
], FormAbstractGroup.prototype, "_errors", void 0);
|
|
369
|
+
__decorate([
|
|
370
|
+
property()
|
|
371
|
+
], FormAbstractGroup.prototype, "_value", void 0);
|
|
372
|
+
FormAbstractGroup = __decorate([
|
|
373
|
+
customElement('form-abstract-group')
|
|
374
|
+
], FormAbstractGroup);
|
|
375
|
+
export { FormAbstractGroup };
|