@unicef-polymer/etools-form-builder 1.0.2 → 2.0.0-rc.3
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/dist/form-attachments-popup/form-attachments-popup.d.ts +10 -2
- package/dist/form-attachments-popup/form-attachments-popup.js +5 -0
- package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +0 -5
- package/dist/form-attachments-popup/form-attachments-popup.tpl.js +0 -5
- package/dist/form-fields/abstract-field-base.class.d.ts +28 -0
- package/dist/form-fields/{base-field.js → abstract-field-base.class.js} +64 -38
- package/dist/form-fields/custom-elements.define.js +17 -5
- package/dist/form-fields/field-renderer-component.d.ts +20 -0
- package/dist/form-fields/field-renderer-component.js +245 -0
- package/dist/form-fields/index.d.ts +9 -5
- package/dist/form-fields/index.js +9 -5
- package/dist/form-fields/repeatable-fields/repeatable-attachment-field.d.ts +17 -0
- package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +198 -0
- package/dist/form-fields/repeatable-fields/repeatable-base-field.d.ts +20 -0
- package/dist/form-fields/repeatable-fields/repeatable-base-field.js +123 -0
- package/dist/form-fields/repeatable-fields/repeatable-number-field.d.ts +10 -0
- package/dist/form-fields/repeatable-fields/repeatable-number-field.js +56 -0
- package/dist/form-fields/repeatable-fields/repeatable-scale-field.d.ts +15 -0
- package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +104 -0
- package/dist/form-fields/repeatable-fields/repeatable-text-field.d.ts +8 -0
- package/dist/form-fields/repeatable-fields/repeatable-text-field.js +43 -0
- package/dist/form-fields/single-fields/attachment-field.d.ts +16 -0
- package/dist/form-fields/single-fields/attachment-field.js +87 -0
- package/dist/form-fields/single-fields/base-field.d.ts +11 -0
- package/dist/form-fields/single-fields/base-field.js +57 -0
- package/dist/form-fields/single-fields/boolean-field.d.ts +8 -0
- package/dist/form-fields/single-fields/boolean-field.js +39 -0
- package/dist/form-fields/{number-field.d.ts → single-fields/number-field.d.ts} +1 -0
- package/dist/form-fields/{number-field.js → single-fields/number-field.js} +15 -2
- package/dist/form-fields/{scale-field.d.ts → single-fields/scale-field.d.ts} +4 -2
- package/dist/form-fields/{scale-field.js → single-fields/scale-field.js} +14 -2
- package/dist/form-fields/{text-field.d.ts → single-fields/text-field.d.ts} +0 -0
- package/dist/form-fields/{text-field.js → single-fields/text-field.js} +6 -1
- package/dist/form-groups/form-abstract-group.d.ts +12 -12
- package/dist/form-groups/form-abstract-group.js +133 -110
- package/dist/form-groups/form-card.d.ts +1 -0
- package/dist/form-groups/form-card.js +25 -0
- package/dist/form-groups/form-collapsed-card.d.ts +3 -1
- package/dist/form-groups/form-collapsed-card.js +24 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -1
- package/dist/lib/additional-components/confirmation-dialog.d.ts +16 -0
- package/dist/lib/additional-components/confirmation-dialog.js +61 -0
- package/dist/lib/additional-components/etools-fb-card.js +8 -1
- package/dist/lib/styles/attachments.styles.js +5 -2
- package/dist/lib/styles/form-builder-card.styles.js +8 -3
- package/dist/lib/styles/page-layout-styles.js +1 -1
- package/dist/lib/types/form-builder.interfaces.d.ts +2 -2
- package/dist/lib/types/form-builder.types.d.ts +8 -2
- package/dist/lib/utils/validations.helper.d.ts +3 -3
- package/dist/lib/utils/validations.helper.js +7 -7
- package/package.json +3 -2
- package/dist/form-fields/base-field.d.ts +0 -20
- package/dist/form-fields/wide-field.d.ts +0 -11
- package/dist/form-fields/wide-field.js +0 -51
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import '@unicef-polymer/etools-dialog/etools-dialog';
|
|
2
|
+
import '@unicef-polymer/etools-upload/etools-upload-multi';
|
|
3
|
+
import '@unicef-polymer/etools-dropdown/etools-dropdown';
|
|
4
|
+
import '@polymer/paper-button/paper-button';
|
|
5
|
+
import '@polymer/iron-icons/iron-icons';
|
|
1
6
|
import { CSSResultArray, LitElement, TemplateResult } from 'lit-element';
|
|
2
7
|
import { GenericObject } from '../lib/types/global.types';
|
|
3
8
|
import { BlueprintMetadata } from '../lib/types/form-builder.types';
|
|
@@ -33,10 +38,14 @@ export declare type OfflineSavedAttachment = {
|
|
|
33
38
|
extraInfo: string[];
|
|
34
39
|
unsynced: boolean;
|
|
35
40
|
};
|
|
36
|
-
declare type UploadFinishedDetails = {
|
|
41
|
+
export declare type UploadFinishedDetails = {
|
|
37
42
|
success: (UploadedAttachment | OfflineSavedAttachment)[];
|
|
38
43
|
error: any[];
|
|
39
44
|
};
|
|
45
|
+
export declare type SingleUploadFinishedDetails = {
|
|
46
|
+
success: UploadedAttachment | OfflineSavedAttachment;
|
|
47
|
+
error: any[];
|
|
48
|
+
};
|
|
40
49
|
export declare class FormAttachmentsPopup extends LitElement {
|
|
41
50
|
dialogOpened: boolean;
|
|
42
51
|
saveBtnClicked: boolean;
|
|
@@ -74,4 +83,3 @@ export declare class FormAttachmentsPopup extends LitElement {
|
|
|
74
83
|
private isOfflineSavedAttachment;
|
|
75
84
|
static get styles(): CSSResultArray;
|
|
76
85
|
}
|
|
77
|
-
export {};
|
|
@@ -4,6 +4,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
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
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
+
import '@unicef-polymer/etools-dialog/etools-dialog';
|
|
8
|
+
import '@unicef-polymer/etools-upload/etools-upload-multi';
|
|
9
|
+
import '@unicef-polymer/etools-dropdown/etools-dropdown';
|
|
10
|
+
import '@polymer/paper-button/paper-button';
|
|
11
|
+
import '@polymer/iron-icons/iron-icons';
|
|
7
12
|
import { css, LitElement, property, query } from 'lit-element';
|
|
8
13
|
import { clone, equals } from 'ramda';
|
|
9
14
|
import { template } from './form-attachments-popup.tpl';
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import { FormAttachmentsPopup } from './form-attachments-popup';
|
|
2
2
|
import { TemplateResult } from 'lit-html';
|
|
3
|
-
import '@unicef-polymer/etools-upload/etools-upload-multi';
|
|
4
|
-
import '@unicef-polymer/etools-dialog/etools-dialog';
|
|
5
|
-
import '@unicef-polymer/etools-dropdown/etools-dropdown';
|
|
6
|
-
import '@polymer/paper-button/paper-button';
|
|
7
|
-
import '@polymer/iron-icons/iron-icons';
|
|
8
3
|
export declare function template(this: FormAttachmentsPopup): TemplateResult;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { html } from 'lit-html';
|
|
2
|
-
import '@unicef-polymer/etools-upload/etools-upload-multi';
|
|
3
|
-
import '@unicef-polymer/etools-dialog/etools-dialog';
|
|
4
|
-
import '@unicef-polymer/etools-dropdown/etools-dropdown';
|
|
5
|
-
import '@polymer/paper-button/paper-button';
|
|
6
|
-
import '@polymer/iron-icons/iron-icons';
|
|
7
2
|
import { InputStyles } from '../lib/styles/input-styles';
|
|
8
3
|
import { DialogStyles } from '../lib/styles/dialog.styles';
|
|
9
4
|
export function template() {
|
|
@@ -0,0 +1,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
|
+
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
|
+
}
|
|
@@ -4,25 +4,34 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
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
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import {
|
|
8
|
-
import { fireEvent } from '../lib/utils/fire-custom-event';
|
|
9
|
-
import { FlexLayoutClasses } from '../lib/styles/flex-layout-classes';
|
|
7
|
+
import { LitElement, property, css, html } from 'lit-element';
|
|
10
8
|
import { validate } from '../lib/utils/validations.helper';
|
|
11
|
-
|
|
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 {
|
|
12
14
|
constructor() {
|
|
13
15
|
super(...arguments);
|
|
14
16
|
this.questionText = '';
|
|
15
|
-
this.isReadonly = false;
|
|
16
17
|
this.required = false;
|
|
18
|
+
this.placeholder = '';
|
|
17
19
|
this.value = null;
|
|
18
|
-
this._errorMessage = null;
|
|
19
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);
|
|
20
27
|
}
|
|
21
|
-
|
|
22
|
-
this.
|
|
28
|
+
get isReadonly() {
|
|
29
|
+
return this._readonly;
|
|
23
30
|
}
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
set defaultValue(value) {
|
|
32
|
+
this._defaultValue = value;
|
|
33
|
+
this.setDefaultValue(this._readonly, value);
|
|
34
|
+
this.requestUpdate();
|
|
26
35
|
}
|
|
27
36
|
render() {
|
|
28
37
|
return html `
|
|
@@ -33,33 +42,23 @@ export class BaseField extends LitElement {
|
|
|
33
42
|
`;
|
|
34
43
|
}
|
|
35
44
|
questionTemplate() {
|
|
36
|
-
return html
|
|
37
|
-
}
|
|
38
|
-
valueChanged(newValue) {
|
|
39
|
-
this.validateField(newValue);
|
|
40
|
-
if (newValue !== this.value) {
|
|
41
|
-
this.value = newValue;
|
|
42
|
-
fireEvent(this, 'value-changed', { value: newValue });
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
validateField(value) {
|
|
46
|
-
let errorMessage;
|
|
47
|
-
if (this.required && !value) {
|
|
48
|
-
errorMessage = 'This field is required!';
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
errorMessage = this.metaValidation(value);
|
|
52
|
-
}
|
|
53
|
-
if (this._errorMessage !== errorMessage) {
|
|
54
|
-
fireEvent(this, 'error-changed', { error: errorMessage });
|
|
55
|
-
this._errorMessage = errorMessage;
|
|
56
|
-
this.requestUpdate();
|
|
57
|
-
}
|
|
45
|
+
return html `<span class="question-text">${this.questionText}</span>`;
|
|
58
46
|
}
|
|
59
47
|
metaValidation(value) {
|
|
60
48
|
const message = validate(this.validators, value);
|
|
61
49
|
return message ? message : this.customValidation(value);
|
|
62
50
|
}
|
|
51
|
+
setDefaultValue(readonly, defaultValue) {
|
|
52
|
+
if (readonly || (!defaultValue && defaultValue !== 0) || this.value !== undefined) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this.getUpdateComplete().then(() => {
|
|
56
|
+
if (defaultValue === this._defaultValue && readonly === this._readonly && this.value === undefined) {
|
|
57
|
+
this.setValue(defaultValue);
|
|
58
|
+
this.validateField(defaultValue);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
63
62
|
static get styles() {
|
|
64
63
|
// language=CSS
|
|
65
64
|
return [
|
|
@@ -80,8 +79,18 @@ export class BaseField extends LitElement {
|
|
|
80
79
|
flex-wrap: wrap;
|
|
81
80
|
}
|
|
82
81
|
|
|
82
|
+
:host(.wide) .finding-container {
|
|
83
|
+
flex-direction: column;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
:host(.wide) .question {
|
|
87
|
+
margin-bottom: -8px;
|
|
88
|
+
min-height: 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
83
91
|
.question-control,
|
|
84
92
|
.question {
|
|
93
|
+
min-width: 0;
|
|
85
94
|
min-height: 57px;
|
|
86
95
|
display: flex;
|
|
87
96
|
align-items: center;
|
|
@@ -92,7 +101,15 @@ export class BaseField extends LitElement {
|
|
|
92
101
|
.question-control {
|
|
93
102
|
flex: 3;
|
|
94
103
|
}
|
|
104
|
+
.add-button {
|
|
105
|
+
padding: 3px;
|
|
106
|
+
margin: 10px;
|
|
107
|
+
background: transparent;
|
|
108
|
+
color: var(--primary-color);
|
|
109
|
+
border: 1px solid;
|
|
110
|
+
}
|
|
95
111
|
|
|
112
|
+
.full-width,
|
|
96
113
|
paper-input,
|
|
97
114
|
paper-textarea {
|
|
98
115
|
width: 100%;
|
|
@@ -121,6 +138,15 @@ export class BaseField extends LitElement {
|
|
|
121
138
|
--paper-input-container-underline_-_border-color: rgba(0, 0, 0, 0.2) !important;
|
|
122
139
|
}
|
|
123
140
|
|
|
141
|
+
iron-icon[icon='close'] {
|
|
142
|
+
cursor: pointer;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.error-text {
|
|
146
|
+
color: var(--error-color);
|
|
147
|
+
font-size: 12px;
|
|
148
|
+
}
|
|
149
|
+
|
|
124
150
|
@media (max-width: 1080px) {
|
|
125
151
|
:host {
|
|
126
152
|
padding: 0 15px;
|
|
@@ -139,16 +165,16 @@ export class BaseField extends LitElement {
|
|
|
139
165
|
}
|
|
140
166
|
__decorate([
|
|
141
167
|
property({ type: String })
|
|
142
|
-
],
|
|
168
|
+
], AbstractFieldBaseClass.prototype, "questionText", void 0);
|
|
143
169
|
__decorate([
|
|
144
170
|
property({ type: Boolean, attribute: 'is-readonly' })
|
|
145
|
-
],
|
|
171
|
+
], AbstractFieldBaseClass.prototype, "isReadonly", null);
|
|
146
172
|
__decorate([
|
|
147
|
-
property({ type: Boolean, attribute: 'required'
|
|
148
|
-
],
|
|
173
|
+
property({ type: Boolean, attribute: 'required' })
|
|
174
|
+
], AbstractFieldBaseClass.prototype, "required", void 0);
|
|
149
175
|
__decorate([
|
|
150
176
|
property()
|
|
151
|
-
],
|
|
177
|
+
], AbstractFieldBaseClass.prototype, "placeholder", void 0);
|
|
152
178
|
__decorate([
|
|
153
179
|
property()
|
|
154
|
-
],
|
|
180
|
+
], AbstractFieldBaseClass.prototype, "value", void 0);
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Form field elements
|
|
3
3
|
*/
|
|
4
|
-
import { TextField } from './text-field';
|
|
5
|
-
import { NumberField } from './number-field';
|
|
6
|
-
import { ScaleField } from './scale-field';
|
|
7
|
-
import {
|
|
4
|
+
import { TextField } from './single-fields/text-field';
|
|
5
|
+
import { NumberField } from './single-fields/number-field';
|
|
6
|
+
import { ScaleField } from './single-fields/scale-field';
|
|
7
|
+
import { BooleanField } from './single-fields/boolean-field';
|
|
8
|
+
import { FieldRendererComponent } from './field-renderer-component';
|
|
9
|
+
import { RepeatableTextField } from './repeatable-fields/repeatable-text-field';
|
|
10
|
+
import { RepeatableNumberField } from './repeatable-fields/repeatable-number-field';
|
|
11
|
+
import { RepeatableScaleField } from './repeatable-fields/repeatable-scale-field';
|
|
12
|
+
import { AttachmentField } from './single-fields/attachment-field';
|
|
13
|
+
import { RepeatableAttachmentField } from './repeatable-fields/repeatable-attachment-field';
|
|
8
14
|
window.customElements.define('number-field', NumberField);
|
|
9
15
|
window.customElements.define('text-field', TextField);
|
|
10
16
|
window.customElements.define('scale-field', ScaleField);
|
|
11
|
-
window.customElements.define('
|
|
17
|
+
window.customElements.define('boolean-field', BooleanField);
|
|
18
|
+
window.customElements.define('attachments-field', AttachmentField);
|
|
19
|
+
window.customElements.define('field-renderer', FieldRendererComponent);
|
|
20
|
+
window.customElements.define('repeatable-text-field', RepeatableTextField);
|
|
21
|
+
window.customElements.define('repeatable-number-field', RepeatableNumberField);
|
|
22
|
+
window.customElements.define('repeatable-scale-field', RepeatableScaleField);
|
|
23
|
+
window.customElements.define('repeatable-attachments-field', RepeatableAttachmentField);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CSSResultArray, LitElement, TemplateResult } from 'lit-element';
|
|
2
|
+
import { BlueprintField } from '../lib/types/form-builder.types';
|
|
3
|
+
import { FieldValidator } from '../lib/utils/validations.helper';
|
|
4
|
+
import { FieldOption } from './single-fields/scale-field';
|
|
5
|
+
export declare class FieldRendererComponent extends LitElement {
|
|
6
|
+
field: BlueprintField;
|
|
7
|
+
value: any;
|
|
8
|
+
errorMessage: string | null;
|
|
9
|
+
validations: FieldValidator[];
|
|
10
|
+
readonly: boolean;
|
|
11
|
+
options: (FieldOption | string | number)[];
|
|
12
|
+
computedPath: string[];
|
|
13
|
+
defaultValue: any;
|
|
14
|
+
render(): TemplateResult;
|
|
15
|
+
renderField(blueprintField: BlueprintField): TemplateResult;
|
|
16
|
+
renderStandardField({ input_type, label, help_text, required, placeholder, styling }: BlueprintField): TemplateResult;
|
|
17
|
+
renderRepeatableField({ input_type, label, help_text, required, placeholder, styling }: BlueprintField): TemplateResult;
|
|
18
|
+
renderFieldLabel(label: string, helperText: string): TemplateResult;
|
|
19
|
+
static get styles(): CSSResultArray;
|
|
20
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
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 { css, html, LitElement, property } from 'lit-element';
|
|
8
|
+
import { FieldTypes, StructureTypes } from '../form-groups';
|
|
9
|
+
import { FlexLayoutClasses } from '../lib/styles/flex-layout-classes';
|
|
10
|
+
import { FormBuilderCardStyles } from '..';
|
|
11
|
+
export class FieldRendererComponent extends LitElement {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.errorMessage = null;
|
|
15
|
+
this.validations = [];
|
|
16
|
+
this.readonly = false;
|
|
17
|
+
this.options = [];
|
|
18
|
+
this.computedPath = [];
|
|
19
|
+
}
|
|
20
|
+
render() {
|
|
21
|
+
if (!this.field) {
|
|
22
|
+
return html ``;
|
|
23
|
+
}
|
|
24
|
+
return this.renderField(this.field);
|
|
25
|
+
}
|
|
26
|
+
renderField(blueprintField) {
|
|
27
|
+
const additionalClass = blueprintField.styling.includes(StructureTypes.ADDITIONAL)
|
|
28
|
+
? 'additional-field '
|
|
29
|
+
: '';
|
|
30
|
+
const wideClass = blueprintField.styling.includes(StructureTypes.WIDE) ? 'wide-field-container ' : '';
|
|
31
|
+
return html `
|
|
32
|
+
<div class="${`${additionalClass}${wideClass}finding-container`}">
|
|
33
|
+
${blueprintField.repeatable
|
|
34
|
+
? this.renderRepeatableField(blueprintField)
|
|
35
|
+
: this.renderStandardField(blueprintField)}
|
|
36
|
+
</div>
|
|
37
|
+
`;
|
|
38
|
+
}
|
|
39
|
+
renderStandardField({ input_type, label, help_text, required, placeholder, styling }) {
|
|
40
|
+
var _a, _b, _c, _d;
|
|
41
|
+
const isWide = styling.includes(StructureTypes.WIDE);
|
|
42
|
+
switch (input_type) {
|
|
43
|
+
case FieldTypes.TEXT_TYPE:
|
|
44
|
+
return html `
|
|
45
|
+
<text-field
|
|
46
|
+
class="${isWide ? 'wide' : ''}"
|
|
47
|
+
?is-readonly="${this.readonly}"
|
|
48
|
+
?required="${required}"
|
|
49
|
+
.placeholder="${placeholder}"
|
|
50
|
+
.value="${this.value}"
|
|
51
|
+
.validators="${this.validations}"
|
|
52
|
+
.errorMessage="${this.errorMessage}"
|
|
53
|
+
.defaultValue="${(_a = this.field) === null || _a === void 0 ? void 0 : _a.default_value}"
|
|
54
|
+
>
|
|
55
|
+
${this.renderFieldLabel(label, help_text)}
|
|
56
|
+
</text-field>
|
|
57
|
+
`;
|
|
58
|
+
case FieldTypes.NUMBER_TYPE:
|
|
59
|
+
case FieldTypes.NUMBER_FLOAT_TYPE:
|
|
60
|
+
case FieldTypes.NUMBER_INTEGER_TYPE:
|
|
61
|
+
return html `
|
|
62
|
+
<number-field
|
|
63
|
+
?is-readonly="${this.readonly}"
|
|
64
|
+
?required="${required}"
|
|
65
|
+
.placeholder="${placeholder}"
|
|
66
|
+
.value="${this.value}"
|
|
67
|
+
.validators="${this.validations}"
|
|
68
|
+
.errorMessage="${this.errorMessage}"
|
|
69
|
+
.isInteger="${Boolean(input_type === FieldTypes.NUMBER_INTEGER_TYPE)}"
|
|
70
|
+
.defaultValue="${(_b = this.field) === null || _b === void 0 ? void 0 : _b.default_value}"
|
|
71
|
+
>
|
|
72
|
+
${this.renderFieldLabel(label, help_text)}
|
|
73
|
+
</number-field>
|
|
74
|
+
`;
|
|
75
|
+
case FieldTypes.BOOL_TYPE:
|
|
76
|
+
return html `
|
|
77
|
+
<boolean-field
|
|
78
|
+
?is-readonly="${this.readonly}"
|
|
79
|
+
?required="${required}"
|
|
80
|
+
.value="${this.value}"
|
|
81
|
+
.validators="${this.validations}"
|
|
82
|
+
.errorMessage="${this.errorMessage}"
|
|
83
|
+
.defaultValue="${(_c = this.field) === null || _c === void 0 ? void 0 : _c.default_value}"
|
|
84
|
+
>
|
|
85
|
+
${this.renderFieldLabel(label, help_text)}
|
|
86
|
+
</boolean-field>
|
|
87
|
+
`;
|
|
88
|
+
case FieldTypes.SCALE_TYPE:
|
|
89
|
+
return html `
|
|
90
|
+
<scale-field
|
|
91
|
+
.options="${this.options}"
|
|
92
|
+
?is-readonly="${this.readonly}"
|
|
93
|
+
?required="${required}"
|
|
94
|
+
.placeholder="${placeholder}"
|
|
95
|
+
.value="${this.value}"
|
|
96
|
+
.validators="${this.validations}"
|
|
97
|
+
.errorMessage="${this.errorMessage}"
|
|
98
|
+
.defaultValue="${(_d = this.field) === null || _d === void 0 ? void 0 : _d.default_value}"
|
|
99
|
+
>
|
|
100
|
+
${this.renderFieldLabel(label, help_text)}
|
|
101
|
+
</scale-field>
|
|
102
|
+
`;
|
|
103
|
+
case FieldTypes.FILE_TYPE:
|
|
104
|
+
return html `
|
|
105
|
+
<attachments-field
|
|
106
|
+
?is-readonly="${this.readonly}"
|
|
107
|
+
?required="${required}"
|
|
108
|
+
.placeholder="${placeholder}"
|
|
109
|
+
.value="${this.value}"
|
|
110
|
+
.validators="${this.validations}"
|
|
111
|
+
.errorMessage="${this.errorMessage}"
|
|
112
|
+
.computedPath="${this.computedPath}"
|
|
113
|
+
>
|
|
114
|
+
${this.renderFieldLabel(label, help_text)}
|
|
115
|
+
</attachments-field>
|
|
116
|
+
`;
|
|
117
|
+
default:
|
|
118
|
+
console.warn(`FormBuilderGroup: Unknown field type: ${input_type}`);
|
|
119
|
+
return html ``;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
renderRepeatableField({ input_type, label, help_text, required, placeholder, styling }) {
|
|
123
|
+
var _a, _b, _c;
|
|
124
|
+
const isWide = styling.includes(StructureTypes.WIDE);
|
|
125
|
+
switch (input_type) {
|
|
126
|
+
case FieldTypes.TEXT_TYPE:
|
|
127
|
+
return html `
|
|
128
|
+
<repeatable-text-field
|
|
129
|
+
class="${isWide ? 'wide' : ''}"
|
|
130
|
+
?is-readonly="${this.readonly}"
|
|
131
|
+
?required="${required}"
|
|
132
|
+
.placeholder="${placeholder}"
|
|
133
|
+
.value="${this.value}"
|
|
134
|
+
.validators="${this.validations}"
|
|
135
|
+
.errorMessage="${this.errorMessage}"
|
|
136
|
+
.defaultValue="${(_a = this.field) === null || _a === void 0 ? void 0 : _a.default_value}"
|
|
137
|
+
>
|
|
138
|
+
${this.renderFieldLabel(label, help_text)}
|
|
139
|
+
</repeatable-text-field>
|
|
140
|
+
`;
|
|
141
|
+
case FieldTypes.NUMBER_TYPE:
|
|
142
|
+
case FieldTypes.NUMBER_FLOAT_TYPE:
|
|
143
|
+
case FieldTypes.NUMBER_INTEGER_TYPE:
|
|
144
|
+
return html `
|
|
145
|
+
<repeatable-number-field
|
|
146
|
+
class="${isWide ? 'wide' : ''}"
|
|
147
|
+
?is-readonly="${this.readonly}"
|
|
148
|
+
?required="${required}"
|
|
149
|
+
.placeholder="${placeholder}"
|
|
150
|
+
.value="${this.value}"
|
|
151
|
+
.validators="${this.validations}"
|
|
152
|
+
.errorMessage="${this.errorMessage}"
|
|
153
|
+
.isInteger="${Boolean(input_type === FieldTypes.NUMBER_INTEGER_TYPE)}"
|
|
154
|
+
.defaultValue="${(_b = this.field) === null || _b === void 0 ? void 0 : _b.default_value}"
|
|
155
|
+
>
|
|
156
|
+
${this.renderFieldLabel(label, help_text)}
|
|
157
|
+
</repeatable-number-field>
|
|
158
|
+
`;
|
|
159
|
+
case FieldTypes.SCALE_TYPE:
|
|
160
|
+
return html `
|
|
161
|
+
<repeatable-scale-field
|
|
162
|
+
class="${isWide ? 'wide' : ''}"
|
|
163
|
+
.options="${this.options}"
|
|
164
|
+
?is-readonly="${this.readonly}"
|
|
165
|
+
?required="${required}"
|
|
166
|
+
.placeholder="${placeholder}"
|
|
167
|
+
.value="${this.value}"
|
|
168
|
+
.validators="${this.validations}"
|
|
169
|
+
.errorMessage="${this.errorMessage}"
|
|
170
|
+
.defaultValue="${(_c = this.field) === null || _c === void 0 ? void 0 : _c.default_value}"
|
|
171
|
+
>
|
|
172
|
+
${this.renderFieldLabel(label, help_text)}
|
|
173
|
+
</repeatable-scale-field>
|
|
174
|
+
`;
|
|
175
|
+
case FieldTypes.FILE_TYPE:
|
|
176
|
+
return html `
|
|
177
|
+
<repeatable-attachments-field
|
|
178
|
+
?is-readonly="${this.readonly}"
|
|
179
|
+
?required="${required}"
|
|
180
|
+
.placeholder="${placeholder}"
|
|
181
|
+
.value="${this.value}"
|
|
182
|
+
.validators="${this.validations}"
|
|
183
|
+
.errorMessage="${this.errorMessage}"
|
|
184
|
+
.computedPath="${this.computedPath}"
|
|
185
|
+
>
|
|
186
|
+
${this.renderFieldLabel(label, help_text)}
|
|
187
|
+
</repeatable-attachments-field>
|
|
188
|
+
`;
|
|
189
|
+
default:
|
|
190
|
+
console.warn(`FormBuilderGroup: Unknown field type: ${input_type}`);
|
|
191
|
+
return html ``;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
renderFieldLabel(label, helperText) {
|
|
195
|
+
return html `
|
|
196
|
+
<div class="layout vertical question-container">
|
|
197
|
+
<div class="question-text">${label}</div>
|
|
198
|
+
<div class="question-details">${helperText}</div>
|
|
199
|
+
</div>
|
|
200
|
+
`;
|
|
201
|
+
}
|
|
202
|
+
static get styles() {
|
|
203
|
+
// language=CSS
|
|
204
|
+
return [
|
|
205
|
+
FlexLayoutClasses,
|
|
206
|
+
FormBuilderCardStyles,
|
|
207
|
+
css `
|
|
208
|
+
.additional-field {
|
|
209
|
+
padding-top: 15px;
|
|
210
|
+
padding-bottom: 20px;
|
|
211
|
+
background-color: var(--secondary-background-color);
|
|
212
|
+
}
|
|
213
|
+
.wide-field-container {
|
|
214
|
+
padding-bottom: 10px;
|
|
215
|
+
}
|
|
216
|
+
.wide-field-container .question-container {
|
|
217
|
+
min-height: 0;
|
|
218
|
+
padding: 7px 0 0;
|
|
219
|
+
}
|
|
220
|
+
.wide-field-container .question-text {
|
|
221
|
+
color: var(--secondary-text-color);
|
|
222
|
+
font-weight: 400;
|
|
223
|
+
}
|
|
224
|
+
`
|
|
225
|
+
];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
__decorate([
|
|
229
|
+
property()
|
|
230
|
+
], FieldRendererComponent.prototype, "field", void 0);
|
|
231
|
+
__decorate([
|
|
232
|
+
property()
|
|
233
|
+
], FieldRendererComponent.prototype, "value", void 0);
|
|
234
|
+
__decorate([
|
|
235
|
+
property()
|
|
236
|
+
], FieldRendererComponent.prototype, "errorMessage", void 0);
|
|
237
|
+
__decorate([
|
|
238
|
+
property()
|
|
239
|
+
], FieldRendererComponent.prototype, "validations", void 0);
|
|
240
|
+
__decorate([
|
|
241
|
+
property({ type: Boolean, attribute: 'readonly' })
|
|
242
|
+
], FieldRendererComponent.prototype, "readonly", void 0);
|
|
243
|
+
__decorate([
|
|
244
|
+
property({ type: Array })
|
|
245
|
+
], FieldRendererComponent.prototype, "options", void 0);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export * from './base-field';
|
|
2
|
-
export * from './number-field';
|
|
3
|
-
export * from './text-field';
|
|
4
|
-
export * from './scale-field';
|
|
5
|
-
export * from './
|
|
1
|
+
export * from './single-fields/base-field';
|
|
2
|
+
export * from './single-fields/number-field';
|
|
3
|
+
export * from './single-fields/text-field';
|
|
4
|
+
export * from './single-fields/scale-field';
|
|
5
|
+
export * from './repeatable-fields/repeatable-base-field';
|
|
6
|
+
export * from './repeatable-fields/repeatable-text-field';
|
|
7
|
+
export * from './repeatable-fields/repeatable-number-field';
|
|
8
|
+
export * from './repeatable-fields/repeatable-scale-field';
|
|
9
|
+
export * from './field-renderer-component';
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export * from './base-field';
|
|
2
|
-
export * from './number-field';
|
|
3
|
-
export * from './text-field';
|
|
4
|
-
export * from './scale-field';
|
|
5
|
-
export * from './
|
|
1
|
+
export * from './single-fields/base-field';
|
|
2
|
+
export * from './single-fields/number-field';
|
|
3
|
+
export * from './single-fields/text-field';
|
|
4
|
+
export * from './single-fields/scale-field';
|
|
5
|
+
export * from './repeatable-fields/repeatable-base-field';
|
|
6
|
+
export * from './repeatable-fields/repeatable-text-field';
|
|
7
|
+
export * from './repeatable-fields/repeatable-number-field';
|
|
8
|
+
export * from './repeatable-fields/repeatable-scale-field';
|
|
9
|
+
export * from './field-renderer-component';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import '@unicef-polymer/etools-upload/etools-upload';
|
|
2
|
+
import { RepeatableBaseField } from './repeatable-base-field';
|
|
3
|
+
import { StoredAttachment, UploadFinishedDetails } from '../../form-attachments-popup';
|
|
4
|
+
import { TemplateResult, CSSResultArray } from 'lit-element';
|
|
5
|
+
export declare class RepeatableAttachmentField extends RepeatableBaseField<StoredAttachment> {
|
|
6
|
+
get uploadUrl(): string;
|
|
7
|
+
get jwtLocalStorageKey(): string;
|
|
8
|
+
computedPath: string[];
|
|
9
|
+
protected render(): TemplateResult;
|
|
10
|
+
protected controlTemplate(): TemplateResult;
|
|
11
|
+
protected customValidation(): string | null;
|
|
12
|
+
protected attachmentsUploaded({ success, error }: UploadFinishedDetails): void;
|
|
13
|
+
protected downloadFile(attachment: StoredAttachment | null): void;
|
|
14
|
+
private isUploadedAttachment;
|
|
15
|
+
private isOfflineSavedAttachment;
|
|
16
|
+
static get styles(): CSSResultArray;
|
|
17
|
+
}
|