@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,89 +1,91 @@
1
- import { html } from 'lit-html';
2
- import { InputStyles } from '../lib/styles/input-styles';
3
- import { DialogStyles } from '../lib/styles/dialog.styles';
4
- export function template() {
5
- var _a;
6
- return html `
7
- ${InputStyles} ${DialogStyles}
8
- <etools-dialog
9
- id="form-attachments-dialog"
10
- size="md"
11
- no-padding
12
- keep-dialog-open
13
- ?opened="${this.dialogOpened}"
14
- .okBtnText="Save"
15
- .hideConfirmBtn="${this.readonly}"
16
- dialog-title="${this.popupTitle}"
17
- @close="${this.onClose}"
18
- @confirm-btn-clicked="${() => this.saveChanges()}"
19
- >
20
- <!-- Link is used to download attachments -->
21
- <a id="link" target="_blank" hidden></a>
22
-
23
- <div class="popup-container">
24
- ${(_a = this.attachments) === null || _a === void 0 ? void 0 : _a.map((attachment, index) => {
25
- var _a, _b;
26
- return html `
27
- <div class="file-selector-container with-type-dropdown">
28
- <!-- Type select Dropdown -->
29
- <etools-dropdown
30
- class="type-dropdown file-selector__type-dropdown"
31
- .selected="${attachment.file_type}"
32
- @etools-selected-item-changed="${({ detail }) => { var _a; return this.changeFileType(attachment, (_a = detail.selectedItem) === null || _a === void 0 ? void 0 : _a.value, index); }}"
33
- trigger-value-change-event
34
- label="Document Type"
35
- placeholder="Select Document Type"
36
- required
37
- ?readonly="${this.readonly}"
38
- hide-search
39
- .options="${(_b = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.options.target_attachments_file_types) === null || _b === void 0 ? void 0 : _b.values}"
40
- option-label="label"
41
- option-value="value"
42
- ?invalid="${this.checkFileType(index)}"
43
- .errorMessage="${this.retrieveErrorMessage(index)}"
44
- allow-outside-scroll
45
- dynamic-align
46
- ></etools-dropdown>
47
-
48
- <!-- File name component -->
49
- <div class="filename-container file-selector__filename">
50
- <iron-icon class="file-icon" icon="attachment"></iron-icon>
51
- <span class="filename" title="${attachment.filename}">${attachment.filename}</span>
52
- </div>
53
-
54
- <!-- Download Button -->
55
- <paper-button
56
- ?hidden="${!attachment.url}"
57
- class="download-button file-selector__download"
58
- @tap="${() => this.downloadFile(attachment)}"
59
- >
60
- <iron-icon icon="cloud-download" class="dw-icon"></iron-icon>
61
- Download
62
- </paper-button>
63
-
64
- <!-- Delete Button -->
65
- <paper-button
66
- class="delete-button file-selector__delete"
67
- ?hidden="${this.readonly}"
68
- @tap="${() => this.deleteAttachment(index)}"
69
- >
70
- Delete
71
- </paper-button>
72
- </div>
73
- `;
74
- })}
75
-
76
- <!-- Upload button -->
77
- <etools-upload-multi
78
- class="with-padding"
79
- activate-offline
80
- ?hidden="${this.readonly}"
81
- @upload-finished="${({ detail }) => this.attachmentsUploaded(detail)}"
82
- .endpointInfo="${{ endpoint: this.uploadUrl, extraInfo: { composedPath: this.computedPath } }}"
83
- .jwtLocalStorageKey="${this.jwtLocalStorageKey}"
84
- >
85
- </etools-upload-multi>
86
- </div>
87
- </etools-dialog>
88
- `;
89
- }
1
+ import { html } from 'lit-html';
2
+ import { InputStyles } from '../lib/styles/input-styles';
3
+ import { DialogStyles } from '../lib/styles/dialog.styles';
4
+ import { getTranslation } from '../lib/utils/translate';
5
+ export function template() {
6
+ var _a;
7
+ return html `
8
+ ${InputStyles} ${DialogStyles}
9
+ <etools-dialog
10
+ id="form-attachments-dialog"
11
+ size="md"
12
+ no-padding
13
+ keep-dialog-open
14
+ ?opened="${this.dialogOpened}"
15
+ .okBtnText="${getTranslation(this.language, 'SAVE')}"
16
+ .cancelBtnText="${getTranslation(this.language, 'CANCEL')}"
17
+ .hideConfirmBtn="${this.readonly}"
18
+ dialog-title="${this.popupTitle}"
19
+ @close="${this.onClose}"
20
+ @confirm-btn-clicked="${() => this.saveChanges()}"
21
+ >
22
+ <!-- Link is used to download attachments -->
23
+ <a id="link" target="_blank" hidden></a>
24
+
25
+ <div class="popup-container">
26
+ ${(_a = this.attachments) === null || _a === void 0 ? void 0 : _a.map((attachment, index) => {
27
+ var _a, _b;
28
+ return html `
29
+ <div class="file-selector-container with-type-dropdown">
30
+ <!-- Type select Dropdown -->
31
+ <etools-dropdown
32
+ class="type-dropdown file-selector__type-dropdown"
33
+ .selected="${attachment.file_type}"
34
+ @etools-selected-item-changed="${({ detail }) => { var _a; return this.changeFileType(attachment, (_a = detail.selectedItem) === null || _a === void 0 ? void 0 : _a.value, index); }}"
35
+ trigger-value-change-event
36
+ label="${getTranslation(this.language, 'DOCUMENT_TYPE')}"
37
+ placeholder="${getTranslation(this.language, 'SELECT_DOCUMENT_TYPE')}"
38
+ required
39
+ ?readonly="${this.readonly}"
40
+ hide-search
41
+ .options="${(_b = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.options.target_attachments_file_types) === null || _b === void 0 ? void 0 : _b.values}"
42
+ option-label="label"
43
+ option-value="value"
44
+ ?invalid="${this.checkFileType(index)}"
45
+ .errorMessage="${this.retrieveErrorMessage(index)}"
46
+ allow-outside-scroll
47
+ dynamic-align
48
+ ></etools-dropdown>
49
+
50
+ <!-- File name component -->
51
+ <div class="filename-container file-selector__filename">
52
+ <iron-icon class="file-icon" icon="attachment"></iron-icon>
53
+ <span class="filename" title="${attachment.filename}">${attachment.filename}</span>
54
+ </div>
55
+
56
+ <!-- Download Button -->
57
+ <paper-button
58
+ ?hidden="${!attachment.url}"
59
+ class="download-button file-selector__download"
60
+ @tap="${() => this.downloadFile(attachment)}"
61
+ >
62
+ <iron-icon icon="cloud-download" class="dw-icon"></iron-icon>
63
+ ${getTranslation(this.language, 'DOWNLOAD')}
64
+ </paper-button>
65
+
66
+ <!-- Delete Button -->
67
+ <paper-button
68
+ class="delete-button file-selector__delete"
69
+ ?hidden="${this.readonly}"
70
+ @tap="${() => this.deleteAttachment(index)}"
71
+ >
72
+ ${getTranslation(this.language, 'DELETE')}
73
+ </paper-button>
74
+ </div>
75
+ `;
76
+ })}
77
+
78
+ <!-- Upload button -->
79
+ <etools-upload-multi
80
+ class="with-padding"
81
+ activate-offline
82
+ ?hidden="${this.readonly}"
83
+ @upload-finished="${({ detail }) => this.attachmentsUploaded(detail)}"
84
+ .endpointInfo="${{ endpoint: this.uploadUrl, extraInfo: { composedPath: this.computedPath } }}"
85
+ .jwtLocalStorageKey="${this.jwtLocalStorageKey}"
86
+ >
87
+ </etools-upload-multi>
88
+ </div>
89
+ </etools-dialog>
90
+ `;
91
+ }
@@ -1,2 +1,2 @@
1
- export * from './form-attachments-popup';
2
- export * from './form-attachments-popup.helper';
1
+ export * from './form-attachments-popup';
2
+ export * from './form-attachments-popup.helper';
@@ -1,2 +1,2 @@
1
- export * from './form-attachments-popup';
2
- export * from './form-attachments-popup.helper';
1
+ export * from './form-attachments-popup';
2
+ export * from './form-attachments-popup.helper';
@@ -1,28 +1,33 @@
1
- import { CSSResultArray, LitElement, TemplateResult } from 'lit-element';
2
- import { FieldValidator } from '../lib/utils/validations.helper';
3
- /**
4
- * Class that contains common properties and methods for single and repeatable fields
5
- */
6
- export declare abstract class AbstractFieldBaseClass<T> extends LitElement {
7
- questionText: string;
8
- set isReadonly(readonly: boolean);
9
- get isReadonly(): boolean;
10
- required: boolean;
11
- placeholder: string;
12
- value: T | null;
13
- validators: FieldValidator[];
14
- touched: boolean;
15
- set defaultValue(value: any);
16
- private _defaultValue;
17
- private _readonly;
18
- protected render(): TemplateResult;
19
- protected questionTemplate(): TemplateResult;
20
- protected metaValidation(value: unknown): string | null;
21
- private setDefaultValue;
22
- protected abstract valueChanged(...args: any): void;
23
- protected abstract customValidation(value: unknown): string | null;
24
- protected abstract controlTemplate(...args: any): TemplateResult;
25
- protected abstract setValue(value: T): void;
26
- protected abstract validateField(value: T): void;
27
- static get styles(): CSSResultArray;
28
- }
1
+ import { CSSResultArray, LitElement, TemplateResult } from 'lit-element';
2
+ import { FieldValidator } from '../lib/utils/validations.helper';
3
+ /**
4
+ * Class that contains common properties and methods for single and repeatable fields
5
+ */
6
+ export declare abstract class AbstractFieldBaseClass<T> extends LitElement {
7
+ questionText: string;
8
+ language: string;
9
+ set isReadonly(readonly: boolean);
10
+ get isReadonly(): boolean;
11
+ required: boolean;
12
+ placeholder: string;
13
+ value: T | null;
14
+ validators: FieldValidator[];
15
+ touched: boolean;
16
+ set defaultValue(value: any);
17
+ private _defaultValue;
18
+ private _readonly;
19
+ constructor();
20
+ connectedCallback(): void;
21
+ disconnectedCallback(): void;
22
+ handleLanguageChange(e: CustomEvent): void;
23
+ protected render(): TemplateResult;
24
+ protected questionTemplate(): TemplateResult;
25
+ protected metaValidation(value: unknown): string | null;
26
+ private setDefaultValue;
27
+ protected abstract valueChanged(...args: any): void;
28
+ protected abstract customValidation(value: unknown): string | null;
29
+ protected abstract controlTemplate(...args: any): TemplateResult;
30
+ protected abstract setValue(value: T): void;
31
+ protected abstract validateField(value: T): void;
32
+ static get styles(): CSSResultArray;
33
+ }
@@ -1,176 +1,194 @@
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, css, html } from 'lit-element';
8
- import { validate } from '../lib/utils/validations.helper';
9
- import { FlexLayoutClasses } from '../lib/styles/flex-layout-classes';
10
- /**
11
- * Class that contains common properties and methods for single and repeatable fields
12
- */
13
- export class AbstractFieldBaseClass extends LitElement {
14
- constructor() {
15
- super(...arguments);
16
- this.questionText = '';
17
- this.required = false;
18
- this.placeholder = '';
19
- this.value = null;
20
- this.validators = [];
21
- this.touched = false;
22
- this._readonly = false;
23
- }
24
- set isReadonly(readonly) {
25
- this._readonly = readonly;
26
- this.setDefaultValue(readonly, this._defaultValue);
27
- this.requestUpdate();
28
- }
29
- get isReadonly() {
30
- return this._readonly;
31
- }
32
- set defaultValue(value) {
33
- this._defaultValue = value;
34
- this.setDefaultValue(this._readonly, value);
35
- this.requestUpdate();
36
- }
37
- render() {
38
- return html `
39
- <div class="finding-container">
40
- <div class="question"><slot>${this.questionTemplate()}</slot></div>
41
- <div class="question-control">${this.controlTemplate()}</div>
42
- </div>
43
- `;
44
- }
45
- questionTemplate() {
46
- return html `<span class="question-text">${this.questionText}</span>`;
47
- }
48
- metaValidation(value) {
49
- const message = validate(this.validators, value);
50
- return message ? message : this.customValidation(value);
51
- }
52
- setDefaultValue(readonly, defaultValue) {
53
- if (readonly || (!defaultValue && defaultValue !== 0) || this.value !== undefined) {
54
- return;
55
- }
56
- this.getUpdateComplete().then(() => {
57
- if (defaultValue === this._defaultValue && readonly === this._readonly && this.value === undefined) {
58
- this.setValue(defaultValue);
59
- this.validateField(defaultValue);
60
- }
61
- });
62
- }
63
- static get styles() {
64
- // language=CSS
65
- return [
66
- FlexLayoutClasses,
67
- css `
68
- :host {
69
- display: block;
70
- width: 100%;
71
- padding: 0 25px 0 45px;
72
- box-sizing: border-box;
73
- }
74
-
75
- .finding-container {
76
- width: 100%;
77
- display: flex;
78
- }
79
- .flex-wrapping {
80
- flex-wrap: wrap;
81
- }
82
-
83
- :host(.wide) .finding-container {
84
- flex-direction: column;
85
- }
86
-
87
- :host(.wide) .question {
88
- margin-bottom: -8px;
89
- min-height: 0;
90
- }
91
-
92
- .question-control,
93
- .question {
94
- min-width: 0;
95
- min-height: 57px;
96
- display: flex;
97
- align-items: center;
98
- }
99
- .question {
100
- flex: 2;
101
- }
102
- .question-control {
103
- flex: 3;
104
- }
105
- .add-button {
106
- padding: 3px;
107
- margin: 10px;
108
- background: transparent;
109
- color: var(--primary-color);
110
- border: 1px solid;
111
- }
112
-
113
- .full-width,
114
- paper-input,
115
- paper-textarea {
116
- width: 100%;
117
- }
118
-
119
- .question-text {
120
- font-weight: 500;
121
- font-size: 13px;
122
- color: var(--primary-text-color);
123
- }
124
-
125
- paper-input,
126
- paper-textarea {
127
- outline: none !important;
128
- }
129
- paper-input[required],
130
- paper-textarea[required] {
131
- --paper-input-container-label_-_background: url('data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%221235%22%20height%3D%221175%22%3E%3Cpath%20fill%3D%22%23de0000%22%20d%3D%22M0%2C449h1235l-999%2C726%20382-1175%20382%2C1175z%22%2F%3E%3C%2Fsvg%3E')
132
- no-repeat 98% 14%/7px;
133
- --paper-input-container-label_-_max-width: max-content;
134
- --paper-input-container-label_-_padding-right: 15px;
135
- }
136
-
137
- iron-icon[icon='close'] {
138
- cursor: pointer;
139
- }
140
-
141
- .error-text {
142
- color: var(--error-color);
143
- font-size: 12px;
144
- }
145
-
146
- @media (max-width: 1080px) {
147
- :host {
148
- padding: 0 15px;
149
- }
150
- .finding-container {
151
- flex-direction: column;
152
- }
153
- .question,
154
- .question-control {
155
- flex: 0 1 auto;
156
- }
157
- }
158
- `
159
- ];
160
- }
161
- }
162
- __decorate([
163
- property({ type: String })
164
- ], AbstractFieldBaseClass.prototype, "questionText", void 0);
165
- __decorate([
166
- property({ type: Boolean, attribute: 'is-readonly' })
167
- ], AbstractFieldBaseClass.prototype, "isReadonly", null);
168
- __decorate([
169
- property({ type: Boolean, attribute: 'required' })
170
- ], AbstractFieldBaseClass.prototype, "required", void 0);
171
- __decorate([
172
- property()
173
- ], AbstractFieldBaseClass.prototype, "placeholder", void 0);
174
- __decorate([
175
- property()
176
- ], AbstractFieldBaseClass.prototype, "value", void 0);
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, css, html } from 'lit-element';
8
+ import { validate } from '../lib/utils/validations.helper';
9
+ import { FlexLayoutClasses } from '../lib/styles/flex-layout-classes';
10
+ /**
11
+ * Class that contains common properties and methods for single and repeatable fields
12
+ */
13
+ export class AbstractFieldBaseClass extends LitElement {
14
+ constructor() {
15
+ super();
16
+ this.questionText = '';
17
+ this.required = false;
18
+ this.placeholder = '';
19
+ this.value = null;
20
+ this.validators = [];
21
+ this.touched = false;
22
+ this._readonly = false;
23
+ if (!this.language) {
24
+ this.language = window.localStorage.defaultLanguage || 'en';
25
+ }
26
+ this.handleLanguageChange = this.handleLanguageChange.bind(this);
27
+ }
28
+ set isReadonly(readonly) {
29
+ this._readonly = readonly;
30
+ this.setDefaultValue(readonly, this._defaultValue);
31
+ this.requestUpdate();
32
+ }
33
+ get isReadonly() {
34
+ return this._readonly;
35
+ }
36
+ set defaultValue(value) {
37
+ this._defaultValue = value;
38
+ this.setDefaultValue(this._readonly, value);
39
+ this.requestUpdate();
40
+ }
41
+ connectedCallback() {
42
+ super.connectedCallback();
43
+ document.addEventListener('language-changed', this.handleLanguageChange.bind(this));
44
+ }
45
+ disconnectedCallback() {
46
+ super.disconnectedCallback();
47
+ document.removeEventListener('language-changed', this.handleLanguageChange.bind(this));
48
+ }
49
+ handleLanguageChange(e) {
50
+ this.language = e.detail.language;
51
+ }
52
+ render() {
53
+ return html `
54
+ <div class="finding-container">
55
+ <div class="question"><slot>${this.questionTemplate()}</slot></div>
56
+ <div class="question-control">${this.controlTemplate()}</div>
57
+ </div>
58
+ `;
59
+ }
60
+ questionTemplate() {
61
+ return html `<span class="question-text">${this.questionText}</span>`;
62
+ }
63
+ metaValidation(value) {
64
+ const message = validate(this.validators, value, this.language);
65
+ return message ? message : this.customValidation(value);
66
+ }
67
+ setDefaultValue(readonly, defaultValue) {
68
+ if (readonly || (!defaultValue && defaultValue !== 0) || this.value !== undefined) {
69
+ return;
70
+ }
71
+ this.getUpdateComplete().then(() => {
72
+ if (defaultValue === this._defaultValue && readonly === this._readonly && this.value === undefined) {
73
+ this.setValue(defaultValue);
74
+ this.validateField(defaultValue);
75
+ }
76
+ });
77
+ }
78
+ static get styles() {
79
+ // language=CSS
80
+ return [
81
+ FlexLayoutClasses,
82
+ css `
83
+ :host {
84
+ display: block;
85
+ width: 100%;
86
+ padding: 0 25px 0 45px;
87
+ box-sizing: border-box;
88
+ }
89
+
90
+ .finding-container {
91
+ width: 100%;
92
+ display: flex;
93
+ }
94
+ .flex-wrapping {
95
+ flex-wrap: wrap;
96
+ }
97
+
98
+ :host(.wide) .finding-container {
99
+ flex-direction: column;
100
+ }
101
+
102
+ :host(.wide) .question {
103
+ margin-bottom: -8px;
104
+ min-height: 0;
105
+ }
106
+
107
+ .question-control,
108
+ .question {
109
+ min-width: 0;
110
+ min-height: 57px;
111
+ display: flex;
112
+ align-items: center;
113
+ }
114
+ .question {
115
+ flex: 2;
116
+ }
117
+ .question-control {
118
+ flex: 3;
119
+ }
120
+ .add-button {
121
+ padding: 3px;
122
+ margin: 10px;
123
+ background: transparent;
124
+ color: var(--primary-color);
125
+ border: 1px solid;
126
+ }
127
+
128
+ .full-width,
129
+ paper-input,
130
+ paper-textarea {
131
+ width: 100%;
132
+ }
133
+
134
+ .question-text {
135
+ font-weight: 500;
136
+ font-size: 13px;
137
+ color: var(--primary-text-color);
138
+ }
139
+
140
+ paper-input,
141
+ paper-textarea {
142
+ outline: none !important;
143
+ }
144
+ paper-input[required],
145
+ paper-textarea[required] {
146
+ --paper-input-container-label_-_background: url('data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%221235%22%20height%3D%221175%22%3E%3Cpath%20fill%3D%22%23de0000%22%20d%3D%22M0%2C449h1235l-999%2C726%20382-1175%20382%2C1175z%22%2F%3E%3C%2Fsvg%3E')
147
+ no-repeat 98% 14%/7px;
148
+ --paper-input-container-label_-_max-width: max-content;
149
+ --paper-input-container-label_-_padding-right: 15px;
150
+ }
151
+
152
+ iron-icon[icon='close'] {
153
+ cursor: pointer;
154
+ }
155
+
156
+ .error-text {
157
+ color: var(--error-color);
158
+ font-size: 12px;
159
+ }
160
+
161
+ @media (max-width: 1080px) {
162
+ :host {
163
+ padding: 0 15px;
164
+ }
165
+ .finding-container {
166
+ flex-direction: column;
167
+ }
168
+ .question,
169
+ .question-control {
170
+ flex: 0 1 auto;
171
+ }
172
+ }
173
+ `
174
+ ];
175
+ }
176
+ }
177
+ __decorate([
178
+ property({ type: String })
179
+ ], AbstractFieldBaseClass.prototype, "questionText", void 0);
180
+ __decorate([
181
+ property()
182
+ ], AbstractFieldBaseClass.prototype, "language", void 0);
183
+ __decorate([
184
+ property({ type: Boolean, attribute: 'is-readonly' })
185
+ ], AbstractFieldBaseClass.prototype, "isReadonly", null);
186
+ __decorate([
187
+ property({ type: Boolean, attribute: 'required' })
188
+ ], AbstractFieldBaseClass.prototype, "required", void 0);
189
+ __decorate([
190
+ property()
191
+ ], AbstractFieldBaseClass.prototype, "placeholder", void 0);
192
+ __decorate([
193
+ property()
194
+ ], AbstractFieldBaseClass.prototype, "value", void 0);