@unicef-polymer/etools-form-builder 2.1.8 → 3.0.0-rc.1
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 -6
- package/dist/assets/translations.js +67 -67
- package/dist/form-attachments-popup/form-attachments-popup.d.ts +84 -86
- 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 +249 -255
- package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +7 -3
- package/dist/form-attachments-popup/form-attachments-popup.tpl.js +102 -91
- 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 -33
- package/dist/form-fields/abstract-field-base.class.js +209 -213
- package/dist/form-fields/field-renderer-component.d.ts +20 -20
- package/dist/form-fields/field-renderer-component.js +251 -255
- 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 +19 -17
- package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +212 -209
- package/dist/form-fields/repeatable-fields/repeatable-base-field.d.ts +21 -20
- package/dist/form-fields/repeatable-fields/repeatable-base-field.js +121 -124
- package/dist/form-fields/repeatable-fields/repeatable-number-field.d.ts +10 -10
- package/dist/form-fields/repeatable-fields/repeatable-number-field.js +63 -67
- package/dist/form-fields/repeatable-fields/repeatable-scale-field.d.ts +15 -15
- package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +106 -108
- package/dist/form-fields/repeatable-fields/repeatable-text-field.d.ts +8 -8
- package/dist/form-fields/repeatable-fields/repeatable-text-field.js +49 -53
- package/dist/form-fields/single-fields/attachment-field.d.ts +16 -16
- package/dist/form-fields/single-fields/attachment-field.js +94 -98
- package/dist/form-fields/single-fields/base-field.d.ts +11 -11
- package/dist/form-fields/single-fields/base-field.js +53 -58
- package/dist/form-fields/single-fields/boolean-field.d.ts +8 -8
- package/dist/form-fields/single-fields/boolean-field.js +45 -49
- package/dist/form-fields/single-fields/number-field.d.ts +10 -10
- package/dist/form-fields/single-fields/number-field.js +63 -67
- package/dist/form-fields/single-fields/scale-field.d.ts +18 -18
- package/dist/form-fields/single-fields/scale-field.js +109 -108
- package/dist/form-fields/single-fields/text-field.d.ts +8 -8
- package/dist/form-fields/single-fields/text-field.js +49 -54
- package/dist/form-groups/form-abstract-group.d.ts +71 -71
- package/dist/form-groups/form-abstract-group.js +396 -398
- package/dist/form-groups/form-card.d.ts +35 -32
- package/dist/form-groups/form-card.js +115 -113
- package/dist/form-groups/form-collapsed-card.d.ts +72 -71
- package/dist/form-groups/form-collapsed-card.js +261 -259
- 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 -18
- package/dist/lib/additional-components/confirmation-dialog.js +68 -72
- package/dist/lib/additional-components/etools-fb-card.d.ts +21 -21
- package/dist/lib/additional-components/etools-fb-card.js +242 -239
- 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 +1 -0
- package/dist/lib/types/form-builder.types.d.ts +59 -59
- package/dist/lib/types/form-builder.types.js +1 -0
- package/dist/lib/types/global.types.d.ts +4 -4
- package/dist/lib/types/global.types.js +1 -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 -1
- package/dist/lib/utils/translate.js +9 -9
- package/dist/lib/utils/validations.helper.d.ts +26 -26
- package/dist/lib/utils/validations.helper.js +42 -42
- package/package.json +51 -56
|
@@ -1,108 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import '
|
|
10
|
-
import '
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return typeof option === 'object' ? option.
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
RepeatableScaleField
|
|
106
|
-
|
|
107
|
-
], RepeatableScaleField);
|
|
108
|
-
export { RepeatableScaleField };
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { css, html } from 'lit';
|
|
3
|
+
import { property, customElement } from 'lit/decorators.js';
|
|
4
|
+
import { repeat } from 'lit/directives/repeat.js';
|
|
5
|
+
import '@shoelace-style/shoelace/dist/components/radio-group/radio-group.js';
|
|
6
|
+
import '@shoelace-style/shoelace/dist/components/radio/radio.js';
|
|
7
|
+
import '@shoelace-style/shoelace/dist/components/button/button.js';
|
|
8
|
+
import { buttonsStyles } from '@unicef-polymer/etools-unicef/src/styles/button-styles';
|
|
9
|
+
import { InputStyles } from '../../lib/styles/input-styles';
|
|
10
|
+
import { RepeatableBaseField } from './repeatable-base-field';
|
|
11
|
+
import { getTranslation } from '../../lib/utils/translate';
|
|
12
|
+
import { AbstractFieldBaseClass } from '../abstract-field-base.class';
|
|
13
|
+
let RepeatableScaleField = class RepeatableScaleField extends RepeatableBaseField {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.options = [];
|
|
17
|
+
}
|
|
18
|
+
controlTemplate(value, index) {
|
|
19
|
+
return html `
|
|
20
|
+
${InputStyles}
|
|
21
|
+
<div class="container">
|
|
22
|
+
<sl-radio-group
|
|
23
|
+
class="radio-group"
|
|
24
|
+
.value="${value}"
|
|
25
|
+
@sl-change="${(e) => this.onSelect(e.target.value, index)}"
|
|
26
|
+
>
|
|
27
|
+
${repeat(this.options, (option) => html `
|
|
28
|
+
<sl-radio class="radio-button" value="${this.getValue(option)}"> ${this.getLabel(option)} </sl-radio>
|
|
29
|
+
`)}
|
|
30
|
+
</sl-radio-group>
|
|
31
|
+
<sl-button
|
|
32
|
+
variant="primary"
|
|
33
|
+
?hidden="${this.isReadonly}"
|
|
34
|
+
@click="${() => this.valueChanged(null, index)}"
|
|
35
|
+
class="clear-button"
|
|
36
|
+
>
|
|
37
|
+
<etools-icon name="clear" slot="prefix"></etools-icon>
|
|
38
|
+
${getTranslation(this.language, 'CLEAR')}
|
|
39
|
+
</sl-button>
|
|
40
|
+
</div>
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
onSelect(itemValue, index) {
|
|
44
|
+
this.valueChanged(itemValue, index);
|
|
45
|
+
}
|
|
46
|
+
getLabel(option) {
|
|
47
|
+
return typeof option === 'object' ? option.label : option;
|
|
48
|
+
}
|
|
49
|
+
getValue(option) {
|
|
50
|
+
return typeof option === 'object' ? option.value : option;
|
|
51
|
+
}
|
|
52
|
+
customValidation() {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
static get styles() {
|
|
56
|
+
// language=CSS
|
|
57
|
+
return [
|
|
58
|
+
...AbstractFieldBaseClass.styles,
|
|
59
|
+
buttonsStyles,
|
|
60
|
+
css `
|
|
61
|
+
.container {
|
|
62
|
+
position: relative;
|
|
63
|
+
min-height: 48px;
|
|
64
|
+
display: flex;
|
|
65
|
+
align-items: center;
|
|
66
|
+
flex-direction: row;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.radio-group {
|
|
70
|
+
display: flex;
|
|
71
|
+
flex-direction: row;
|
|
72
|
+
flex-wrap: wrap;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
:host([is-readonly]) paper-radio-group {
|
|
76
|
+
pointer-events: none;
|
|
77
|
+
opacity: 0.55;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@media (max-width: 1080px) {
|
|
81
|
+
.container {
|
|
82
|
+
flex-direction: column;
|
|
83
|
+
align-items: flex-start;
|
|
84
|
+
}
|
|
85
|
+
.radio-group {
|
|
86
|
+
flex-direction: column;
|
|
87
|
+
}
|
|
88
|
+
.radio-button {
|
|
89
|
+
padding-left: 3px;
|
|
90
|
+
}
|
|
91
|
+
.clear-button {
|
|
92
|
+
margin: 0;
|
|
93
|
+
padding-left: 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
`
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
__decorate([
|
|
101
|
+
property({ type: Array })
|
|
102
|
+
], RepeatableScaleField.prototype, "options", void 0);
|
|
103
|
+
RepeatableScaleField = __decorate([
|
|
104
|
+
customElement('repeatable-scale-field')
|
|
105
|
+
], RepeatableScaleField);
|
|
106
|
+
export { RepeatableScaleField };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CSSResultArray, TemplateResult } from 'lit
|
|
2
|
-
import '@polymer/
|
|
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
|
-
}
|
|
1
|
+
import { CSSResultArray, TemplateResult } from 'lit';
|
|
2
|
+
import '@unicef-polymer/etools-unicef/src/etools-input/etools-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
|
+
}
|
|
@@ -1,53 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
RepeatableTextField = __decorate([
|
|
51
|
-
customElement('repeatable-text-field')
|
|
52
|
-
], RepeatableTextField);
|
|
53
|
-
export { RepeatableTextField };
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { css, html } from 'lit';
|
|
3
|
+
import { customElement } from 'lit/decorators.js';
|
|
4
|
+
import '@unicef-polymer/etools-unicef/src/etools-input/etools-textarea';
|
|
5
|
+
import { InputStyles } from '../../lib/styles/input-styles';
|
|
6
|
+
import { RepeatableBaseField } from './repeatable-base-field';
|
|
7
|
+
import { AbstractFieldBaseClass } from '../abstract-field-base.class';
|
|
8
|
+
let RepeatableTextField = class RepeatableTextField extends RepeatableBaseField {
|
|
9
|
+
controlTemplate(value, index) {
|
|
10
|
+
return html `
|
|
11
|
+
${InputStyles}
|
|
12
|
+
<etools-textarea
|
|
13
|
+
id="textarea"
|
|
14
|
+
class="no-padding-left"
|
|
15
|
+
no-label-float
|
|
16
|
+
placeholder="${this.isReadonly ? '—' : this.placeholder}"
|
|
17
|
+
.value="${value}"
|
|
18
|
+
@value-changed="${({ detail }) => this.valueChanged(detail.value, index)}"
|
|
19
|
+
?readonly="${this.isReadonly}"
|
|
20
|
+
?invalid="${this.errorMessage[index]}"
|
|
21
|
+
error-message="${this.errorMessage[index]}"
|
|
22
|
+
>
|
|
23
|
+
</etools-textarea>
|
|
24
|
+
`;
|
|
25
|
+
}
|
|
26
|
+
customValidation() {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
static get styles() {
|
|
30
|
+
// language=CSS
|
|
31
|
+
return [
|
|
32
|
+
...AbstractFieldBaseClass.styles,
|
|
33
|
+
css `
|
|
34
|
+
:host(.wide) paper-textarea {
|
|
35
|
+
padding-left: 0;
|
|
36
|
+
}
|
|
37
|
+
@media (max-width: 380px) {
|
|
38
|
+
.no-padding-left {
|
|
39
|
+
padding-left: 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
RepeatableTextField = __decorate([
|
|
47
|
+
customElement('repeatable-text-field')
|
|
48
|
+
], RepeatableTextField);
|
|
49
|
+
export { RepeatableTextField };
|
|
@@ -1,16 +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 {
|
|
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
|
-
}
|
|
1
|
+
import '@unicef-polymer/etools-unicef/scr/etools-upload/etools-upload';
|
|
2
|
+
import { BaseField } from './base-field';
|
|
3
|
+
import { SingleUploadFinishedDetails, StoredAttachment } from '../../form-attachments-popup';
|
|
4
|
+
import { CSSResultArray, TemplateResult } from 'lit';
|
|
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
|
+
}
|
|
@@ -1,98 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
import '
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
console.
|
|
64
|
-
this.
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
};
|
|
95
|
-
AttachmentField = __decorate([
|
|
96
|
-
customElement('attachments-field')
|
|
97
|
-
], AttachmentField);
|
|
98
|
-
export { AttachmentField };
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import '@unicef-polymer/etools-unicef/scr/etools-upload/etools-upload';
|
|
3
|
+
import { BaseField } from './base-field';
|
|
4
|
+
import { AttachmentsHelper } from '../../form-attachments-popup';
|
|
5
|
+
import { html } from 'lit';
|
|
6
|
+
import { customElement } from 'lit/decorators.js';
|
|
7
|
+
import { fireEvent } from '../../lib/utils/fire-custom-event';
|
|
8
|
+
import { SharedStyles } from '../../lib/styles/shared-styles';
|
|
9
|
+
import { AttachmentsStyles } from '../../lib/styles/attachments.styles';
|
|
10
|
+
import { getTranslation } from '../../lib/utils/translate';
|
|
11
|
+
let AttachmentField = class AttachmentField extends BaseField {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.computedPath = [];
|
|
15
|
+
}
|
|
16
|
+
get uploadUrl() {
|
|
17
|
+
return AttachmentsHelper.uploadUrl;
|
|
18
|
+
}
|
|
19
|
+
get jwtLocalStorageKey() {
|
|
20
|
+
return AttachmentsHelper.jwtLocalStorageKey;
|
|
21
|
+
}
|
|
22
|
+
controlTemplate() {
|
|
23
|
+
return html `
|
|
24
|
+
<!-- Upload button -->
|
|
25
|
+
<etools-upload
|
|
26
|
+
class="with-padding"
|
|
27
|
+
activate-offline
|
|
28
|
+
.uploadedFileInfo="${this.value}"
|
|
29
|
+
?readonly="${this.isReadonly}"
|
|
30
|
+
@upload-finished="${({ detail }) => this.attachmentsUploaded(detail)}"
|
|
31
|
+
@delete-file="${() => this.valueChanged(null)}"
|
|
32
|
+
.endpointInfo="${{ endpoint: this.uploadUrl, extraInfo: { composedPath: this.computedPath } }}"
|
|
33
|
+
.jwtLocalStorageKey="${this.jwtLocalStorageKey}"
|
|
34
|
+
>
|
|
35
|
+
</etools-upload>
|
|
36
|
+
`;
|
|
37
|
+
}
|
|
38
|
+
customValidation() {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
attachmentsUploaded({ success, error }) {
|
|
42
|
+
if (this.isUploadedAttachment(success)) {
|
|
43
|
+
this.valueChanged({
|
|
44
|
+
url: success.file_link,
|
|
45
|
+
attachment: success.id,
|
|
46
|
+
filename: success.filename,
|
|
47
|
+
file_type: null
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else if (this.isOfflineSavedAttachment(success)) {
|
|
51
|
+
this.valueChanged({
|
|
52
|
+
attachment: success.id,
|
|
53
|
+
filename: success.filename,
|
|
54
|
+
composedPath: [],
|
|
55
|
+
file_type: null
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
console.warn('Missing fields in parsed attachment');
|
|
60
|
+
this.valueChanged(null);
|
|
61
|
+
}
|
|
62
|
+
if (error && error.length) {
|
|
63
|
+
console.error(error);
|
|
64
|
+
fireEvent(this, 'toast', { text: getTranslation(this.language, 'UPLOAD_ATTACHMENTS_FAILED') });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
downloadFile(attachment) {
|
|
68
|
+
if (!(attachment === null || attachment === void 0 ? void 0 : attachment.url)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const link = document.createElement('a');
|
|
72
|
+
link.target = '_blank';
|
|
73
|
+
link.href = attachment.url;
|
|
74
|
+
link.click();
|
|
75
|
+
window.URL.revokeObjectURL(attachment.url);
|
|
76
|
+
}
|
|
77
|
+
isUploadedAttachment(attachment) {
|
|
78
|
+
return (attachment.hasOwnProperty('filename') &&
|
|
79
|
+
attachment.hasOwnProperty('id') &&
|
|
80
|
+
attachment.hasOwnProperty('file_link') &&
|
|
81
|
+
!attachment.hasOwnProperty('unsynced'));
|
|
82
|
+
}
|
|
83
|
+
isOfflineSavedAttachment(attachment) {
|
|
84
|
+
return (attachment.hasOwnProperty('filename') && attachment.hasOwnProperty('id') && attachment.hasOwnProperty('unsynced'));
|
|
85
|
+
}
|
|
86
|
+
static get styles() {
|
|
87
|
+
// language=CSS
|
|
88
|
+
return [...BaseField.styles, SharedStyles, AttachmentsStyles];
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
AttachmentField = __decorate([
|
|
92
|
+
customElement('attachments-field')
|
|
93
|
+
], AttachmentField);
|
|
94
|
+
export { AttachmentField };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { TemplateResult } from 'lit
|
|
2
|
-
import { AbstractFieldBaseClass } from '../abstract-field-base.class';
|
|
3
|
-
export declare abstract class BaseField<T> extends AbstractFieldBaseClass<T> {
|
|
4
|
-
set errorMessage(message: string | null);
|
|
5
|
-
get errorMessage(): string | null;
|
|
6
|
-
protected _errorMessage: string | null;
|
|
7
|
-
protected valueChanged(newValue: T): void;
|
|
8
|
-
protected setValue(newValue: T | null): void;
|
|
9
|
-
protected validateField(value: T): void;
|
|
10
|
-
protected abstract controlTemplate(): TemplateResult;
|
|
11
|
-
}
|
|
1
|
+
import { TemplateResult } from 'lit';
|
|
2
|
+
import { AbstractFieldBaseClass } from '../abstract-field-base.class';
|
|
3
|
+
export declare abstract class BaseField<T> extends AbstractFieldBaseClass<T> {
|
|
4
|
+
set errorMessage(message: string | null);
|
|
5
|
+
get errorMessage(): string | null;
|
|
6
|
+
protected _errorMessage: string | null;
|
|
7
|
+
protected valueChanged(newValue: T): void;
|
|
8
|
+
protected setValue(newValue: T | null): void;
|
|
9
|
+
protected validateField(value: T): void;
|
|
10
|
+
protected abstract controlTemplate(): TemplateResult;
|
|
11
|
+
}
|