@unicef-polymer/etools-form-builder 1.0.3 → 2.0.0-rc.5

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 (59) hide show
  1. package/dist/form-attachments-popup/form-attachments-popup.d.ts +10 -2
  2. package/dist/form-attachments-popup/form-attachments-popup.js +12 -3
  3. package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +0 -5
  4. package/dist/form-attachments-popup/form-attachments-popup.tpl.js +0 -5
  5. package/dist/form-fields/abstract-field-base.class.d.ts +28 -0
  6. package/dist/form-fields/{base-field.js → abstract-field-base.class.js} +64 -38
  7. package/dist/form-fields/field-renderer-component.d.ts +20 -0
  8. package/dist/form-fields/field-renderer-component.js +249 -0
  9. package/dist/form-fields/index.d.ts +11 -5
  10. package/dist/form-fields/index.js +11 -5
  11. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.d.ts +17 -0
  12. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +208 -0
  13. package/dist/form-fields/repeatable-fields/repeatable-base-field.d.ts +20 -0
  14. package/dist/form-fields/repeatable-fields/repeatable-base-field.js +123 -0
  15. package/dist/form-fields/repeatable-fields/repeatable-number-field.d.ts +10 -0
  16. package/dist/form-fields/repeatable-fields/repeatable-number-field.js +66 -0
  17. package/dist/form-fields/repeatable-fields/repeatable-scale-field.d.ts +15 -0
  18. package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +108 -0
  19. package/dist/form-fields/repeatable-fields/repeatable-text-field.d.ts +8 -0
  20. package/dist/form-fields/repeatable-fields/repeatable-text-field.js +53 -0
  21. package/dist/form-fields/single-fields/attachment-field.d.ts +16 -0
  22. package/dist/form-fields/single-fields/attachment-field.js +97 -0
  23. package/dist/form-fields/single-fields/base-field.d.ts +11 -0
  24. package/dist/form-fields/single-fields/base-field.js +57 -0
  25. package/dist/form-fields/single-fields/boolean-field.d.ts +8 -0
  26. package/dist/form-fields/single-fields/boolean-field.js +49 -0
  27. package/dist/form-fields/{number-field.d.ts → single-fields/number-field.d.ts} +1 -0
  28. package/dist/form-fields/single-fields/number-field.js +66 -0
  29. package/dist/form-fields/{scale-field.d.ts → single-fields/scale-field.d.ts} +4 -2
  30. package/dist/form-fields/{scale-field.js → single-fields/scale-field.js} +21 -5
  31. package/dist/form-fields/{text-field.d.ts → single-fields/text-field.d.ts} +0 -0
  32. package/dist/form-fields/{wide-field.js → single-fields/text-field.js} +29 -26
  33. package/dist/form-groups/form-abstract-group.d.ts +12 -12
  34. package/dist/form-groups/form-abstract-group.js +141 -114
  35. package/dist/form-groups/form-card.d.ts +1 -0
  36. package/dist/form-groups/form-card.js +32 -3
  37. package/dist/form-groups/form-collapsed-card.d.ts +3 -1
  38. package/dist/form-groups/form-collapsed-card.js +31 -7
  39. package/dist/index.d.ts +3 -14
  40. package/dist/index.js +3 -19
  41. package/dist/lib/additional-components/confirmation-dialog.d.ts +16 -0
  42. package/dist/lib/additional-components/confirmation-dialog.js +65 -0
  43. package/dist/lib/additional-components/etools-fb-card.js +7 -0
  44. package/dist/lib/styles/attachments.styles.js +5 -2
  45. package/dist/lib/styles/form-builder-card.styles.js +8 -3
  46. package/dist/lib/styles/page-layout-styles.js +1 -1
  47. package/dist/lib/types/form-builder.interfaces.d.ts +2 -2
  48. package/dist/lib/types/form-builder.types.d.ts +8 -2
  49. package/dist/lib/utils/validations.helper.d.ts +3 -3
  50. package/dist/lib/utils/validations.helper.js +7 -7
  51. package/package.json +3 -2
  52. package/dist/form-fields/base-field.d.ts +0 -20
  53. package/dist/form-fields/custom-elements.define.d.ts +0 -1
  54. package/dist/form-fields/custom-elements.define.js +0 -11
  55. package/dist/form-fields/number-field.js +0 -43
  56. package/dist/form-fields/text-field.js +0 -39
  57. package/dist/form-fields/wide-field.d.ts +0 -11
  58. package/dist/form-groups/custom-elements.define.d.ts +0 -1
  59. package/dist/form-groups/custom-elements.define.js +0 -9
@@ -0,0 +1,208 @@
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 '@unicef-polymer/etools-upload/etools-upload';
8
+ import { RepeatableBaseField } from './repeatable-base-field';
9
+ import { AttachmentsHelper } from '../../form-attachments-popup';
10
+ import { html, css, customElement } from 'lit-element';
11
+ import { fireEvent } from '../../lib/utils/fire-custom-event';
12
+ import { SharedStyles } from '../../lib/styles/shared-styles';
13
+ import { AttachmentsStyles } from '../../lib/styles/attachments.styles';
14
+ let RepeatableAttachmentField = class RepeatableAttachmentField extends RepeatableBaseField {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.computedPath = [];
18
+ }
19
+ get uploadUrl() {
20
+ return AttachmentsHelper.uploadUrl;
21
+ }
22
+ get jwtLocalStorageKey() {
23
+ return AttachmentsHelper.jwtLocalStorageKey;
24
+ }
25
+ render() {
26
+ var _a;
27
+ const values = this.getValues();
28
+ return html `
29
+ <div class="finding-container">
30
+ <div class="question layout start"><slot>${this.questionTemplate()}</slot></div>
31
+ <div class="question-control layout vertical center-justified start">
32
+ ${values.map((value, index) => value
33
+ ? html `
34
+ <div class="layout horizontal file-container">
35
+ <!-- File name component -->
36
+ <div class="filename-container file-selector__filename">
37
+ <iron-icon class="file-icon" icon="attachment"></iron-icon>
38
+ <span class="filename" title="${value.filename}">${value.filename}</span>
39
+ </div>
40
+
41
+ <!-- Download Button -->
42
+ <paper-button
43
+ ?hidden="${!value.url}"
44
+ class="download-button file-selector__download"
45
+ @tap="${() => this.downloadFile(value)}"
46
+ >
47
+ <iron-icon icon="cloud-download" class="dw-icon"></iron-icon>
48
+ Download
49
+ </paper-button>
50
+
51
+ <!-- Delete Button -->
52
+ <paper-button
53
+ class="delete-button file-selector__delete"
54
+ ?hidden="${this.isReadonly}"
55
+ @tap="${() => this.removeControl(index)}"
56
+ >
57
+ Delete
58
+ </paper-button>
59
+ </div>
60
+ `
61
+ : '')}
62
+ <!-- Upload button -->
63
+ <etools-upload-multi
64
+ class="with-padding"
65
+ activate-offline
66
+ ?hidden="${this.isReadonly}"
67
+ @upload-finished="${({ detail }) => this.attachmentsUploaded(detail)}"
68
+ .endpointInfo="${{ endpoint: this.uploadUrl, extraInfo: { composedPath: this.computedPath } }}"
69
+ .jwtLocalStorageKey="${this.jwtLocalStorageKey}"
70
+ >
71
+ </etools-upload-multi>
72
+ <div ?hidden="${!this.isReadonly || ((_a = this.value) === null || _a === void 0 ? void 0 : _a.length)}">—</div>
73
+ </div>
74
+ </div>
75
+ `;
76
+ }
77
+ controlTemplate() {
78
+ return html ``;
79
+ }
80
+ customValidation() {
81
+ return null;
82
+ }
83
+ attachmentsUploaded({ success, error }) {
84
+ success === null || success === void 0 ? void 0 : success.forEach((file, index) => {
85
+ var _a, _b;
86
+ const newIndex = ((_b = Number((_a = this.editedValues) === null || _a === void 0 ? void 0 : _a.length)) !== null && _b !== void 0 ? _b : 0) + index;
87
+ if (this.isUploadedAttachment(file)) {
88
+ this.valueChanged({
89
+ url: file.file_link,
90
+ attachment: file.id,
91
+ filename: file.filename,
92
+ file_type: null
93
+ }, newIndex);
94
+ }
95
+ else if (this.isOfflineSavedAttachment(file)) {
96
+ this.valueChanged({
97
+ attachment: file.id,
98
+ filename: file.filename,
99
+ composedPath: [],
100
+ file_type: null
101
+ }, newIndex);
102
+ }
103
+ else {
104
+ console.warn('Missing fields in parsed attachment');
105
+ }
106
+ });
107
+ if (error && error.length) {
108
+ console.error(error);
109
+ fireEvent(this, 'toast', { text: 'Can not upload attachments. Please try again later' });
110
+ }
111
+ }
112
+ downloadFile(attachment) {
113
+ if (!(attachment === null || attachment === void 0 ? void 0 : attachment.url)) {
114
+ return;
115
+ }
116
+ const link = document.createElement('a');
117
+ link.target = '_blank';
118
+ link.href = attachment.url;
119
+ link.click();
120
+ window.URL.revokeObjectURL(attachment.url);
121
+ }
122
+ isUploadedAttachment(attachment) {
123
+ return (attachment.hasOwnProperty('filename') &&
124
+ attachment.hasOwnProperty('id') &&
125
+ attachment.hasOwnProperty('file_link') &&
126
+ !attachment.hasOwnProperty('unsynced'));
127
+ }
128
+ isOfflineSavedAttachment(attachment) {
129
+ return (attachment.hasOwnProperty('filename') && attachment.hasOwnProperty('id') && attachment.hasOwnProperty('unsynced'));
130
+ }
131
+ static get styles() {
132
+ // language=CSS
133
+ return [
134
+ ...RepeatableBaseField.styles,
135
+ SharedStyles,
136
+ AttachmentsStyles,
137
+ css `
138
+ .file-selector__type-dropdown {
139
+ flex-basis: 25%;
140
+ padding-left: 8px;
141
+ padding-right: 8px;
142
+ }
143
+
144
+ .file-selector__filename {
145
+ flex-basis: 35%;
146
+ }
147
+
148
+ .file-selector__download {
149
+ flex-basis: 10%;
150
+ }
151
+
152
+ .file-selector__delete {
153
+ flex-basis: 10%;
154
+ }
155
+
156
+ .file-selector-container.with-type-dropdown {
157
+ flex-wrap: nowrap;
158
+ }
159
+
160
+ .popup-container {
161
+ padding: 12px 12px 0;
162
+ }
163
+
164
+ .file-container {
165
+ padding: 8px 0;
166
+ }
167
+
168
+ @media (max-width: 380px) {
169
+ .file-selector-container.with-type-dropdown {
170
+ justify-content: center;
171
+ }
172
+
173
+ .file-selector-container.with-type-dropdown etools-dropdown.type-dropdown {
174
+ flex-basis: 90%;
175
+ }
176
+
177
+ .file-selector__filename {
178
+ flex-basis: 90%;
179
+ }
180
+
181
+ .file-selector__download {
182
+ flex-basis: 5%;
183
+ }
184
+
185
+ .file-selector__delete {
186
+ flex-basis: 5%;
187
+ }
188
+ }
189
+
190
+ @media (max-width: 600px) {
191
+ etools-dropdown {
192
+ padding: 0;
193
+ }
194
+
195
+ .file-selector-container.with-type-dropdown {
196
+ border-bottom: 1px solid lightgrey;
197
+ flex-wrap: wrap;
198
+ padding-bottom: 10px;
199
+ }
200
+ }
201
+ `
202
+ ];
203
+ }
204
+ };
205
+ RepeatableAttachmentField = __decorate([
206
+ customElement('repeatable-attachments-field')
207
+ ], RepeatableAttachmentField);
208
+ export { RepeatableAttachmentField };
@@ -0,0 +1,20 @@
1
+ import { CSSResultArray, TemplateResult } from 'lit-element';
2
+ import { AbstractFieldBaseClass } from '../abstract-field-base.class';
3
+ export declare abstract class RepeatableBaseField<T> extends AbstractFieldBaseClass<T[]> {
4
+ set errorMessage(messages: (string | null)[]);
5
+ get errorMessage(): (string | null)[];
6
+ protected _errorMessage: (string | null)[];
7
+ protected editedValues: (T | null)[] | null;
8
+ protected render(): TemplateResult;
9
+ protected questionTemplate(): TemplateResult;
10
+ protected valueChanged(newValue: T, index: number): void;
11
+ protected setValue(value: (T | null)[]): void;
12
+ protected validateField(value: T[]): void;
13
+ protected validateField(value: T, index: number): void;
14
+ protected addNewField(): void;
15
+ protected removeControl(index: number): void;
16
+ protected getValues(): (T | null)[];
17
+ private isArrayData;
18
+ protected abstract controlTemplate(value: T | null, index: number): TemplateResult;
19
+ static get styles(): CSSResultArray;
20
+ }
@@ -0,0 +1,123 @@
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, property } from 'lit-element';
8
+ import { AbstractFieldBaseClass } from '../abstract-field-base.class';
9
+ import { fireEvent } from '../../lib/utils/fire-custom-event';
10
+ export class RepeatableBaseField extends AbstractFieldBaseClass {
11
+ constructor() {
12
+ super(...arguments);
13
+ this._errorMessage = [];
14
+ this.editedValues = null;
15
+ }
16
+ set errorMessage(messages) {
17
+ this._errorMessage = messages || [];
18
+ }
19
+ get errorMessage() {
20
+ return this.isReadonly ? [] : this._errorMessage;
21
+ }
22
+ render() {
23
+ const values = this.getValues();
24
+ return html `
25
+ <div class="finding-container">
26
+ <div class="question layout start"><slot>${this.questionTemplate()}</slot></div>
27
+ <div class="question-control layout vertical center-justified start">
28
+ ${values.map((value, index) => html `<div class="layout horizontal center full-width">
29
+ ${this.controlTemplate(value, index)}
30
+ <iron-icon
31
+ icon="close"
32
+ ?hidden="${this.isReadonly || values.length < 2}"
33
+ @click="${() => this.removeControl(index)}"
34
+ ></iron-icon>
35
+ </div>`)}
36
+ <paper-button class="add-button" ?hidden="${this.isReadonly}" @click="${() => this.addNewField()}">
37
+ Add
38
+ </paper-button>
39
+ </div>
40
+ </div>
41
+ `;
42
+ }
43
+ questionTemplate() {
44
+ return html `<span class="question-text">${this.questionText}</span>`;
45
+ }
46
+ valueChanged(newValue, index) {
47
+ if (!this.isReadonly) {
48
+ this.validateField(newValue, index);
49
+ }
50
+ else {
51
+ this._errorMessage = [];
52
+ }
53
+ if (this.editedValues && newValue !== this.editedValues[index]) {
54
+ this.editedValues[index] = newValue;
55
+ this.setValue(this.editedValues);
56
+ }
57
+ }
58
+ setValue(value) {
59
+ this.editedValues = value;
60
+ this.value = value.filter((value) => Boolean(value));
61
+ fireEvent(this, 'value-changed', { value: this.value });
62
+ }
63
+ validateField(value, index) {
64
+ if (this.isArrayData(value)) {
65
+ return value.forEach((item, index) => this.validateField(item, index));
66
+ }
67
+ let errorMessage;
68
+ if (this.required && !value && value !== null && typeof value !== 'number') {
69
+ errorMessage = 'This field is required!';
70
+ }
71
+ else {
72
+ errorMessage = this.metaValidation(value);
73
+ }
74
+ const oldError = (this._errorMessage || [])[index] || null;
75
+ if (oldError !== errorMessage) {
76
+ const errors = this.editedValues.map((_, index) => (this._errorMessage && this._errorMessage[index]) || null);
77
+ errors.splice(index, 1, errorMessage);
78
+ const newErrors = errors.some((error) => error !== null) ? errors : null;
79
+ fireEvent(this, 'error-changed', { error: newErrors });
80
+ this._errorMessage = errors;
81
+ this.requestUpdate();
82
+ }
83
+ }
84
+ addNewField() {
85
+ this.editedValues = [...this.editedValues, null];
86
+ }
87
+ removeControl(index) {
88
+ this.editedValues.splice(index, 1);
89
+ this.value = this.editedValues.filter((value) => Boolean(value));
90
+ fireEvent(this, 'value-changed', { value: this.value });
91
+ this.requestUpdate();
92
+ }
93
+ getValues() {
94
+ if (this.isReadonly) {
95
+ this.editedValues = Array.isArray(this.value) && this.value.length ? this.value : [null];
96
+ }
97
+ else if (!this.editedValues) {
98
+ this.editedValues = Array.isArray(this.value) && this.value.length ? this.value : [null];
99
+ }
100
+ return this.editedValues || [null];
101
+ }
102
+ isArrayData(value) {
103
+ return Array.isArray(value);
104
+ }
105
+ static get styles() {
106
+ // language=CSS
107
+ return [
108
+ ...AbstractFieldBaseClass.styles,
109
+ css `
110
+ :host(:not([is-readonly])) .question-control,
111
+ :host(:not([is-readonly])) .question {
112
+ padding-bottom: 10px;
113
+ }
114
+ `
115
+ ];
116
+ }
117
+ }
118
+ __decorate([
119
+ property()
120
+ ], RepeatableBaseField.prototype, "_errorMessage", void 0);
121
+ __decorate([
122
+ property()
123
+ ], RepeatableBaseField.prototype, "editedValues", void 0);
@@ -0,0 +1,10 @@
1
+ import { CSSResultArray, TemplateResult } from 'lit-element';
2
+ import '@polymer/paper-input/paper-input';
3
+ import { RepeatableBaseField } from './repeatable-base-field';
4
+ export declare class RepeatableNumberField extends RepeatableBaseField<number> {
5
+ isInteger: boolean;
6
+ protected controlTemplate(value: number | null, index: number): TemplateResult;
7
+ protected valueChanged(newValue: number, index: number): void;
8
+ protected customValidation(value: number): string | null;
9
+ static get styles(): CSSResultArray;
10
+ }
@@ -0,0 +1,66 @@
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, customElement, html } from 'lit-element';
8
+ import '@polymer/paper-input/paper-input';
9
+ import { InputStyles } from '../../lib/styles/input-styles';
10
+ import { RepeatableBaseField } from './repeatable-base-field';
11
+ import { AbstractFieldBaseClass } from '../abstract-field-base.class';
12
+ let RepeatableNumberField = class RepeatableNumberField extends RepeatableBaseField {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.isInteger = false;
16
+ }
17
+ controlTemplate(value, index) {
18
+ return html `
19
+ ${InputStyles}
20
+ <paper-input
21
+ class="without-border no-padding-left form-control"
22
+ no-label-float
23
+ placeholder="${this.isReadonly ? '—' : this.placeholder}"
24
+ .value="${value}"
25
+ @value-changed="${({ detail }) => this.valueChanged(detail.value, index)}"
26
+ placeholder="&#8212;"
27
+ ?invalid="${this.errorMessage[index]}"
28
+ error-message="${this.errorMessage[index]}"
29
+ ?disabled="${this.isReadonly}"
30
+ >
31
+ </paper-input>
32
+ `;
33
+ }
34
+ valueChanged(newValue, index) {
35
+ const formatted = Number(newValue);
36
+ const isNumber = !isNaN(formatted) && `${newValue}` !== '' && `${newValue}` !== 'null';
37
+ super.valueChanged(isNumber ? formatted : newValue, index);
38
+ }
39
+ customValidation(value) {
40
+ if (!value) {
41
+ return null;
42
+ }
43
+ if (isNaN(value)) {
44
+ return 'Must be a number';
45
+ }
46
+ const integerValidation = !this.isInteger || value - Math.floor(value) === 0;
47
+ return integerValidation ? null : 'Must be an integer';
48
+ }
49
+ static get styles() {
50
+ // language=CSS
51
+ return [
52
+ ...AbstractFieldBaseClass.styles,
53
+ css `
54
+ @media (max-width: 380px) {
55
+ .no-padding-left {
56
+ padding-left: 0;
57
+ }
58
+ }
59
+ `
60
+ ];
61
+ }
62
+ };
63
+ RepeatableNumberField = __decorate([
64
+ customElement('repeatable-number-field')
65
+ ], RepeatableNumberField);
66
+ export { RepeatableNumberField };
@@ -0,0 +1,15 @@
1
+ import { TemplateResult, CSSResultArray } from 'lit-element';
2
+ import '@polymer/paper-radio-group/paper-radio-group';
3
+ import '@polymer/paper-radio-button/paper-radio-button';
4
+ import { PaperRadioButtonElement } from '@polymer/paper-radio-button/paper-radio-button';
5
+ import { RepeatableBaseField } from './repeatable-base-field';
6
+ import { FieldOption } from '..';
7
+ export declare class RepeatableScaleField extends RepeatableBaseField<string | number | null> {
8
+ options: (FieldOption | string | number)[];
9
+ protected controlTemplate(value: string | null, index: number): TemplateResult;
10
+ protected onSelect(item: PaperRadioButtonElement, index: number): void;
11
+ protected getLabel(option: FieldOption | string | number): unknown;
12
+ protected getValue(option: FieldOption | string | number): unknown;
13
+ protected customValidation(): string | null;
14
+ static get styles(): CSSResultArray;
15
+ }
@@ -0,0 +1,108 @@
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, css, customElement } from 'lit-element';
8
+ import { repeat } from 'lit-html/directives/repeat';
9
+ import '@polymer/paper-radio-group/paper-radio-group';
10
+ import '@polymer/paper-radio-button/paper-radio-button';
11
+ import { InputStyles } from '../../lib/styles/input-styles';
12
+ import { RepeatableBaseField } from './repeatable-base-field';
13
+ import { AbstractFieldBaseClass } from '../abstract-field-base.class';
14
+ let RepeatableScaleField = class RepeatableScaleField extends RepeatableBaseField {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.options = [];
18
+ }
19
+ controlTemplate(value, index) {
20
+ return html `
21
+ ${InputStyles}
22
+ <div class="container">
23
+ <paper-radio-group
24
+ class="radio-group"
25
+ selected="${value}"
26
+ @iron-select="${({ detail }) => this.onSelect(detail.item, index)}"
27
+ >
28
+ ${repeat(this.options, (option) => html `
29
+ <paper-radio-button class="radio-button" name="${this.getValue(option)}">
30
+ ${this.getLabel(option)}
31
+ </paper-radio-button>
32
+ `)}
33
+ </paper-radio-group>
34
+
35
+ <paper-button
36
+ ?hidden="${this.isReadonly}"
37
+ @click="${() => this.valueChanged(null, index)}"
38
+ class="clear-button"
39
+ >
40
+ <iron-icon icon="clear"></iron-icon>Clear
41
+ </paper-button>
42
+ </div>
43
+ `;
44
+ }
45
+ onSelect(item, index) {
46
+ const newValue = item.get('name');
47
+ this.valueChanged(newValue, index);
48
+ }
49
+ getLabel(option) {
50
+ return typeof option === 'object' ? option.label : option;
51
+ }
52
+ getValue(option) {
53
+ return typeof option === 'object' ? option.value : option;
54
+ }
55
+ customValidation() {
56
+ return null;
57
+ }
58
+ static get styles() {
59
+ // language=CSS
60
+ return [
61
+ ...AbstractFieldBaseClass.styles,
62
+ css `
63
+ .container {
64
+ position: relative;
65
+ min-height: 48px;
66
+ display: flex;
67
+ align-items: center;
68
+ flex-direction: row;
69
+ }
70
+
71
+ .radio-group {
72
+ display: flex;
73
+ flex-direction: row;
74
+ flex-wrap: wrap;
75
+ }
76
+
77
+ :host([is-readonly]) paper-radio-group {
78
+ pointer-events: none;
79
+ opacity: 0.55;
80
+ }
81
+
82
+ @media (max-width: 1080px) {
83
+ .container {
84
+ flex-direction: column;
85
+ align-items: flex-start;
86
+ }
87
+ .radio-group {
88
+ flex-direction: column;
89
+ }
90
+ .radio-button {
91
+ padding-left: 3px;
92
+ }
93
+ .clear-button {
94
+ margin: 0;
95
+ padding-left: 0;
96
+ }
97
+ }
98
+ `
99
+ ];
100
+ }
101
+ };
102
+ __decorate([
103
+ property({ type: Array })
104
+ ], RepeatableScaleField.prototype, "options", void 0);
105
+ RepeatableScaleField = __decorate([
106
+ customElement('repeatable-scale-field')
107
+ ], RepeatableScaleField);
108
+ export { RepeatableScaleField };
@@ -0,0 +1,8 @@
1
+ import { CSSResultArray, TemplateResult } from 'lit-element';
2
+ import '@polymer/paper-input/paper-textarea';
3
+ import { RepeatableBaseField } from './repeatable-base-field';
4
+ export declare class RepeatableTextField extends RepeatableBaseField<string> {
5
+ protected controlTemplate(value: string | null, index: number): TemplateResult;
6
+ protected customValidation(): string | null;
7
+ static get styles(): CSSResultArray;
8
+ }
@@ -0,0 +1,53 @@
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, customElement, html } from 'lit-element';
8
+ import '@polymer/paper-input/paper-textarea';
9
+ import { InputStyles } from '../../lib/styles/input-styles';
10
+ import { RepeatableBaseField } from './repeatable-base-field';
11
+ import { AbstractFieldBaseClass } from '../abstract-field-base.class';
12
+ let RepeatableTextField = class RepeatableTextField extends RepeatableBaseField {
13
+ controlTemplate(value, index) {
14
+ return html `
15
+ ${InputStyles}
16
+ <paper-textarea
17
+ id="textarea"
18
+ class="no-padding-left form-control"
19
+ no-label-float
20
+ placeholder="${this.isReadonly ? '—' : this.placeholder}"
21
+ .value="${value}"
22
+ @value-changed="${({ detail }) => this.valueChanged(detail.value, index)}"
23
+ ?disabled="${this.isReadonly}"
24
+ ?invalid="${this.errorMessage[index]}"
25
+ error-message="${this.errorMessage[index]}"
26
+ >
27
+ </paper-textarea>
28
+ `;
29
+ }
30
+ customValidation() {
31
+ return null;
32
+ }
33
+ static get styles() {
34
+ // language=CSS
35
+ return [
36
+ ...AbstractFieldBaseClass.styles,
37
+ css `
38
+ :host(.wide) paper-textarea {
39
+ padding-left: 0;
40
+ }
41
+ @media (max-width: 380px) {
42
+ .no-padding-left {
43
+ padding-left: 0;
44
+ }
45
+ }
46
+ `
47
+ ];
48
+ }
49
+ };
50
+ RepeatableTextField = __decorate([
51
+ customElement('repeatable-text-field')
52
+ ], RepeatableTextField);
53
+ export { RepeatableTextField };
@@ -0,0 +1,16 @@
1
+ import '@unicef-polymer/etools-upload/etools-upload';
2
+ import { BaseField } from './base-field';
3
+ import { SingleUploadFinishedDetails, StoredAttachment } from '../../form-attachments-popup';
4
+ import { TemplateResult, CSSResultArray } from 'lit-element';
5
+ export declare class AttachmentField extends BaseField<StoredAttachment | null> {
6
+ get uploadUrl(): string;
7
+ get jwtLocalStorageKey(): string;
8
+ computedPath: string[];
9
+ protected controlTemplate(): TemplateResult;
10
+ protected customValidation(): string | null;
11
+ protected attachmentsUploaded({ success, error }: SingleUploadFinishedDetails): void;
12
+ protected downloadFile(attachment: StoredAttachment | null): void;
13
+ private isUploadedAttachment;
14
+ private isOfflineSavedAttachment;
15
+ static get styles(): CSSResultArray;
16
+ }