@unicef-polymer/etools-form-builder 0.1.25 → 1.0.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.
Files changed (64) hide show
  1. package/dist/form-attachments-popup/form-attachments-popup.d.ts +77 -77
  2. package/dist/form-attachments-popup/form-attachments-popup.helper.d.ts +8 -8
  3. package/dist/form-attachments-popup/form-attachments-popup.helper.js +14 -14
  4. package/dist/form-attachments-popup/form-attachments-popup.js +191 -191
  5. package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +8 -8
  6. package/dist/form-attachments-popup/form-attachments-popup.tpl.js +15 -15
  7. package/dist/form-attachments-popup/index.d.ts +2 -2
  8. package/dist/form-attachments-popup/index.js +2 -2
  9. package/dist/form-fields/base-field.d.ts +20 -20
  10. package/dist/form-fields/base-field.js +80 -80
  11. package/dist/form-fields/custom-elements.define.d.ts +1 -1
  12. package/dist/form-fields/custom-elements.define.js +11 -11
  13. package/dist/form-fields/index.d.ts +5 -5
  14. package/dist/form-fields/index.js +5 -5
  15. package/dist/form-fields/number-field.d.ts +9 -9
  16. package/dist/form-fields/number-field.js +24 -24
  17. package/dist/form-fields/scale-field.d.ts +16 -16
  18. package/dist/form-fields/scale-field.js +38 -38
  19. package/dist/form-fields/text-field.d.ts +8 -8
  20. package/dist/form-fields/text-field.js +19 -19
  21. package/dist/form-fields/wide-field.d.ts +11 -11
  22. package/dist/form-fields/wide-field.js +36 -36
  23. package/dist/form-groups/custom-elements.define.d.ts +1 -1
  24. package/dist/form-groups/custom-elements.define.js +9 -9
  25. package/dist/form-groups/form-abstract-group.d.ts +60 -60
  26. package/dist/form-groups/form-abstract-group.js +199 -199
  27. package/dist/form-groups/form-card.d.ts +31 -31
  28. package/dist/form-groups/form-card.js +69 -69
  29. package/dist/form-groups/form-collapsed-card.d.ts +68 -68
  30. package/dist/form-groups/form-collapsed-card.js +208 -207
  31. package/dist/form-groups/index.d.ts +3 -3
  32. package/dist/form-groups/index.js +3 -3
  33. package/dist/index.d.ts +14 -14
  34. package/dist/index.js +19 -19
  35. package/dist/lib/additional-components/etools-fb-card.d.ts +16 -16
  36. package/dist/lib/additional-components/etools-fb-card.js +80 -80
  37. package/dist/lib/styles/attachments.styles.d.ts +2 -2
  38. package/dist/lib/styles/attachments.styles.js +3 -3
  39. package/dist/lib/styles/card-styles.d.ts +2 -2
  40. package/dist/lib/styles/card-styles.js +3 -3
  41. package/dist/lib/styles/dialog.styles.d.ts +2 -2
  42. package/dist/lib/styles/dialog.styles.js +3 -3
  43. package/dist/lib/styles/elevation-styles.d.ts +9 -9
  44. package/dist/lib/styles/elevation-styles.js +10 -10
  45. package/dist/lib/styles/flex-layout-classes.d.ts +2 -2
  46. package/dist/lib/styles/flex-layout-classes.js +3 -3
  47. package/dist/lib/styles/form-builder-card.styles.d.ts +2 -2
  48. package/dist/lib/styles/form-builder-card.styles.js +3 -3
  49. package/dist/lib/styles/input-styles.d.ts +2 -2
  50. package/dist/lib/styles/input-styles.js +5 -5
  51. package/dist/lib/styles/page-layout-styles.d.ts +2 -2
  52. package/dist/lib/styles/page-layout-styles.js +3 -3
  53. package/dist/lib/styles/shared-styles.d.ts +2 -2
  54. package/dist/lib/styles/shared-styles.js +3 -3
  55. package/dist/lib/types/form-builder.interfaces.d.ts +83 -83
  56. package/dist/lib/types/form-builder.types.d.ts +53 -53
  57. package/dist/lib/types/global.types.d.ts +4 -4
  58. package/dist/lib/utils/dialog.d.ts +10 -10
  59. package/dist/lib/utils/dialog.js +21 -21
  60. package/dist/lib/utils/fire-custom-event.d.ts +1 -1
  61. package/dist/lib/utils/fire-custom-event.js +7 -7
  62. package/dist/lib/utils/validations.helper.d.ts +26 -26
  63. package/dist/lib/utils/validations.helper.js +35 -35
  64. package/package.json +7 -7
@@ -1,77 +1,77 @@
1
- import { CSSResultArray, LitElement, TemplateResult } from 'lit-element';
2
- import { GenericObject } from '../lib/types/global.types';
3
- import { BlueprintMetadata } from '../lib/types/form-builder.types';
4
- export declare type FormBuilderAttachmentsPopupData = {
5
- attachments: StoredAttachment[];
6
- metadata: BlueprintMetadata;
7
- title: string;
8
- readonly?: boolean;
9
- computedPath: string[];
10
- errors: GenericObject[];
11
- };
12
- export declare type StoredAttachment = {
13
- attachment: string | number;
14
- filename: string;
15
- file_type: number | null;
16
- url?: string;
17
- composedPath?: string[];
18
- };
19
- export declare type UploadedAttachment = {
20
- id: number;
21
- object_link: string;
22
- file_type: string;
23
- file_link: string;
24
- filename: string;
25
- uploaded_by: string;
26
- created: string;
27
- attachment: number;
28
- };
29
- export declare type OfflineSavedAttachment = {
30
- id: string;
31
- filetype: string;
32
- filename: string;
33
- extraInfo: string[];
34
- unsynced: boolean;
35
- };
36
- declare type UploadFinishedDetails = {
37
- success: (UploadedAttachment | OfflineSavedAttachment)[];
38
- error: any[];
39
- };
40
- export declare class FormAttachmentsPopup extends LitElement {
41
- dialogOpened: boolean;
42
- saveBtnClicked: boolean;
43
- attachments: StoredAttachment[];
44
- metadata: BlueprintMetadata;
45
- link: HTMLLinkElement;
46
- readonly: boolean;
47
- popupTitle: string;
48
- computedPath: string[];
49
- errors: GenericObject;
50
- /**
51
- * Array of offline saved fileIds that was remove from popup.
52
- * We need to remove them from IDB but only after confirm button click
53
- */
54
- private filesForRemove;
55
- private originalAttachments;
56
- set dialogData({ attachments, title, metadata, readonly, computedPath, errors }: FormBuilderAttachmentsPopupData);
57
- get uploadUrl(): string;
58
- get jwtLocalStorageKey(): string;
59
- constructor();
60
- render(): TemplateResult | void;
61
- /**
62
- * on Cancel button click
63
- * Remove offline saved attachments from IDB if they are missing in originalAttachments
64
- */
65
- onClose(): void;
66
- saveChanges(): Promise<void>;
67
- checkFileType(index: number): boolean;
68
- retrieveErrorMessage(index: number): string;
69
- protected downloadFile(attachment: GenericObject): void;
70
- protected changeFileType(attachment: GenericObject, newType: number | null, index: number): void;
71
- protected attachmentsUploaded({ success, error }: UploadFinishedDetails): void;
72
- protected deleteAttachment(index: number): void;
73
- private isUploadedAttachment;
74
- private isOfflineSavedAttachment;
75
- static get styles(): CSSResultArray;
76
- }
77
- export {};
1
+ import { CSSResultArray, LitElement, TemplateResult } from 'lit-element';
2
+ import { GenericObject } from '../lib/types/global.types';
3
+ import { BlueprintMetadata } from '../lib/types/form-builder.types';
4
+ export declare type FormBuilderAttachmentsPopupData = {
5
+ attachments: StoredAttachment[];
6
+ metadata: BlueprintMetadata;
7
+ title: string;
8
+ readonly?: boolean;
9
+ computedPath: string[];
10
+ errors: GenericObject[];
11
+ };
12
+ export declare type StoredAttachment = {
13
+ attachment: string | number;
14
+ filename: string;
15
+ file_type: number | null;
16
+ url?: string;
17
+ composedPath?: string[];
18
+ };
19
+ export declare type UploadedAttachment = {
20
+ id: number;
21
+ object_link: string;
22
+ file_type: string;
23
+ file_link: string;
24
+ filename: string;
25
+ uploaded_by: string;
26
+ created: string;
27
+ attachment: number;
28
+ };
29
+ export declare type OfflineSavedAttachment = {
30
+ id: string;
31
+ filetype: string;
32
+ filename: string;
33
+ extraInfo: string[];
34
+ unsynced: boolean;
35
+ };
36
+ declare type UploadFinishedDetails = {
37
+ success: (UploadedAttachment | OfflineSavedAttachment)[];
38
+ error: any[];
39
+ };
40
+ export declare class FormAttachmentsPopup extends LitElement {
41
+ dialogOpened: boolean;
42
+ saveBtnClicked: boolean;
43
+ attachments: StoredAttachment[];
44
+ metadata: BlueprintMetadata;
45
+ link: HTMLLinkElement;
46
+ readonly: boolean;
47
+ popupTitle: string;
48
+ computedPath: string[];
49
+ errors: GenericObject;
50
+ /**
51
+ * Array of offline saved fileIds that was remove from popup.
52
+ * We need to remove them from IDB but only after confirm button click
53
+ */
54
+ private filesForRemove;
55
+ private originalAttachments;
56
+ set dialogData({ attachments, title, metadata, readonly, computedPath, errors }: FormBuilderAttachmentsPopupData);
57
+ get uploadUrl(): string;
58
+ get jwtLocalStorageKey(): string;
59
+ constructor();
60
+ render(): TemplateResult | void;
61
+ /**
62
+ * on Cancel button click
63
+ * Remove offline saved attachments from IDB if they are missing in originalAttachments
64
+ */
65
+ onClose(): void;
66
+ saveChanges(): Promise<void>;
67
+ checkFileType(index: number): boolean;
68
+ retrieveErrorMessage(index: number): string;
69
+ protected downloadFile(attachment: GenericObject): void;
70
+ protected changeFileType(attachment: GenericObject, newType: number | null, index: number): void;
71
+ protected attachmentsUploaded({ success, error }: UploadFinishedDetails): void;
72
+ protected deleteAttachment(index: number): void;
73
+ private isUploadedAttachment;
74
+ private isOfflineSavedAttachment;
75
+ static get styles(): CSSResultArray;
76
+ }
77
+ export {};
@@ -1,8 +1,8 @@
1
- export declare class FormAttachmentsPopupHelper {
2
- get isInitialized(): boolean;
3
- uploadUrl: string | null;
4
- jwtLocalStorageKey?: string;
5
- initialize(uploadUrl: string, jwtLocalStorageKey?: string): void;
6
- }
7
- declare const AttachmentsHelper: FormAttachmentsPopupHelper;
8
- export { AttachmentsHelper };
1
+ export declare class FormAttachmentsPopupHelper {
2
+ get isInitialized(): boolean;
3
+ uploadUrl: string | null;
4
+ jwtLocalStorageKey?: string;
5
+ initialize(uploadUrl: string, jwtLocalStorageKey?: string): void;
6
+ }
7
+ declare const AttachmentsHelper: FormAttachmentsPopupHelper;
8
+ export { AttachmentsHelper };
@@ -1,14 +1,14 @@
1
- export class FormAttachmentsPopupHelper {
2
- constructor() {
3
- this.uploadUrl = null;
4
- }
5
- get isInitialized() {
6
- return Boolean(this.uploadUrl);
7
- }
8
- initialize(uploadUrl, jwtLocalStorageKey) {
9
- this.uploadUrl = uploadUrl;
10
- this.jwtLocalStorageKey = jwtLocalStorageKey;
11
- }
12
- }
13
- const AttachmentsHelper = new FormAttachmentsPopupHelper();
14
- export { AttachmentsHelper };
1
+ export class FormAttachmentsPopupHelper {
2
+ constructor() {
3
+ this.uploadUrl = null;
4
+ }
5
+ get isInitialized() {
6
+ return Boolean(this.uploadUrl);
7
+ }
8
+ initialize(uploadUrl, jwtLocalStorageKey) {
9
+ this.uploadUrl = uploadUrl;
10
+ this.jwtLocalStorageKey = jwtLocalStorageKey;
11
+ }
12
+ }
13
+ const AttachmentsHelper = new FormAttachmentsPopupHelper();
14
+ export { AttachmentsHelper };
@@ -1,175 +1,175 @@
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, LitElement, property, query } from 'lit-element';
8
- import { clone, equals } from 'ramda';
9
- import { template } from './form-attachments-popup.tpl';
10
- import { fireEvent } from '../lib/utils/fire-custom-event';
11
- import { SharedStyles } from '../lib/styles/shared-styles';
12
- import { AttachmentsStyles } from '../lib/styles/attachments.styles';
13
- import { AttachmentsHelper } from './form-attachments-popup.helper';
14
- import { deleteFileFromDexie } from '@unicef-polymer/etools-upload/offline/dexie-operations';
15
- export class FormAttachmentsPopup extends LitElement {
16
- constructor() {
17
- super();
18
- this.dialogOpened = true;
19
- this.saveBtnClicked = false;
20
- this.attachments = [];
21
- this.readonly = false;
22
- this.popupTitle = '';
23
- this.computedPath = [];
24
- this.errors = [];
25
- /**
26
- * Array of offline saved fileIds that was remove from popup.
27
- * We need to remove them from IDB but only after confirm button click
28
- */
29
- this.filesForRemove = [];
30
- this.originalAttachments = [];
31
- if (!AttachmentsHelper.isInitialized) {
32
- throw new Error('Please initialize attachments popup before use');
33
- }
34
- }
35
- set dialogData({ attachments, title, metadata, readonly, computedPath, errors }) {
36
- this.popupTitle = title;
37
- this.attachments = clone(attachments) || [];
38
- this.originalAttachments = clone(attachments) || [];
39
- this.metadata = clone(metadata);
40
- this.readonly = Boolean(readonly);
41
- this.computedPath = computedPath;
42
- this.errors = clone(errors) || [];
43
- }
44
- get uploadUrl() {
45
- return AttachmentsHelper.uploadUrl;
46
- }
47
- get jwtLocalStorageKey() {
48
- return AttachmentsHelper.jwtLocalStorageKey;
49
- }
50
- render() {
51
- return template.call(this);
52
- }
53
- /**
54
- * on Cancel button click
55
- * Remove offline saved attachments from IDB if they are missing in originalAttachments
56
- */
57
- onClose() {
58
- this.attachments.forEach(({ url, attachment }) => {
59
- const existsInOriginal = this.originalAttachments
60
- .map((item) => item.attachment || [])
61
- .includes(attachment);
62
- if (!existsInOriginal && !url) {
63
- deleteFileFromDexie(attachment);
64
- }
65
- });
66
- fireEvent(this, 'response', { confirmed: false });
67
- }
68
- async saveChanges() {
69
- let fileTypeNotSelected = false;
70
- this.attachments.forEach((attachment, index) => {
71
- if (!attachment.file_type) {
72
- fileTypeNotSelected = true;
73
- this.errors[index] = { file_type: ['This field is required'] };
74
- }
75
- else {
76
- this.errors[index] = [];
77
- }
78
- });
79
- this.requestUpdate();
80
- if (fileTypeNotSelected) {
81
- return;
82
- }
83
- if (this.filesForRemove.length) {
84
- for (const fileId of this.filesForRemove) {
85
- await deleteFileFromDexie(fileId);
86
- }
87
- }
88
- /**
89
- * Don't confirm popup if no changes was made
90
- */
91
- if (!equals(this.attachments, this.originalAttachments)) {
92
- fireEvent(this, 'response', { confirmed: true, attachments: this.attachments });
93
- }
94
- else {
95
- fireEvent(this, 'response', { confirmed: false });
96
- }
97
- }
98
- checkFileType(index) {
99
- var _a;
100
- return (_a = this.errors[index]) === null || _a === void 0 ? void 0 : _a.file_type;
101
- }
102
- retrieveErrorMessage(index) {
103
- return this.errors[index] && this.errors[index].file_type ? this.errors[index].file_type[0] : '';
104
- }
105
- downloadFile(attachment) {
106
- const url = attachment.url;
107
- this.link.href = url;
108
- this.link.click();
109
- window.URL.revokeObjectURL(url);
110
- }
111
- changeFileType(attachment, newType, index) {
112
- if (newType && attachment.file_type !== newType) {
113
- attachment.file_type = newType;
114
- this.errors[index] = [];
115
- this.requestUpdate();
116
- }
117
- }
118
- attachmentsUploaded({ success, error }) {
119
- const parsedAttachments = success
120
- .map((attachment) => {
121
- if (this.isUploadedAttachment(attachment)) {
122
- return {
123
- url: attachment.file_link,
124
- attachment: attachment.id,
125
- filename: attachment.filename,
126
- file_type: null
127
- };
128
- }
129
- else if (this.isOfflineSavedAttachment(attachment)) {
130
- return {
131
- attachment: attachment.id,
132
- filename: attachment.filename,
133
- composedPath: this.computedPath,
134
- file_type: null
135
- };
136
- }
137
- else {
138
- console.warn('Missing fields in parsed attachment');
139
- return null;
140
- }
141
- })
142
- .filter((attachment) => Boolean(attachment));
143
- this.attachments = [...this.attachments, ...parsedAttachments];
144
- if (error && error.length) {
145
- console.error(error);
146
- fireEvent(this, 'toast', { text: 'Can not upload attachments. Please try again later' });
147
- }
148
- }
149
- deleteAttachment(index) {
150
- const [attachment] = this.attachments.splice(index, 1);
151
- if (!attachment.hasOwnProperty('url')) {
152
- /**
153
- * prepare attachment for remove from IDB after Popup confirm
154
- */
155
- this.filesForRemove.push(attachment.attachment);
156
- }
157
- this.attachments = [...this.attachments];
158
- }
159
- isUploadedAttachment(attachment) {
160
- return (attachment.hasOwnProperty('filename') &&
161
- attachment.hasOwnProperty('id') &&
162
- attachment.hasOwnProperty('file_link') &&
163
- !attachment.hasOwnProperty('unsynced'));
164
- }
165
- isOfflineSavedAttachment(attachment) {
166
- return (attachment.hasOwnProperty('filename') && attachment.hasOwnProperty('id') && attachment.hasOwnProperty('unsynced'));
167
- }
168
- static get styles() {
169
- // language=CSS
170
- return [
171
- SharedStyles,
172
- AttachmentsStyles,
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, LitElement, property, query } from 'lit-element';
8
+ import { clone, equals } from 'ramda';
9
+ import { template } from './form-attachments-popup.tpl';
10
+ import { fireEvent } from '../lib/utils/fire-custom-event';
11
+ import { SharedStyles } from '../lib/styles/shared-styles';
12
+ import { AttachmentsStyles } from '../lib/styles/attachments.styles';
13
+ import { AttachmentsHelper } from './form-attachments-popup.helper';
14
+ import { deleteFileFromDexie } from '@unicef-polymer/etools-upload/offline/dexie-operations';
15
+ export class FormAttachmentsPopup extends LitElement {
16
+ constructor() {
17
+ super();
18
+ this.dialogOpened = true;
19
+ this.saveBtnClicked = false;
20
+ this.attachments = [];
21
+ this.readonly = false;
22
+ this.popupTitle = '';
23
+ this.computedPath = [];
24
+ this.errors = [];
25
+ /**
26
+ * Array of offline saved fileIds that was remove from popup.
27
+ * We need to remove them from IDB but only after confirm button click
28
+ */
29
+ this.filesForRemove = [];
30
+ this.originalAttachments = [];
31
+ if (!AttachmentsHelper.isInitialized) {
32
+ throw new Error('Please initialize attachments popup before use');
33
+ }
34
+ }
35
+ set dialogData({ attachments, title, metadata, readonly, computedPath, errors }) {
36
+ this.popupTitle = title;
37
+ this.attachments = clone(attachments) || [];
38
+ this.originalAttachments = clone(attachments) || [];
39
+ this.metadata = clone(metadata);
40
+ this.readonly = Boolean(readonly);
41
+ this.computedPath = computedPath;
42
+ this.errors = clone(errors) || [];
43
+ }
44
+ get uploadUrl() {
45
+ return AttachmentsHelper.uploadUrl;
46
+ }
47
+ get jwtLocalStorageKey() {
48
+ return AttachmentsHelper.jwtLocalStorageKey;
49
+ }
50
+ render() {
51
+ return template.call(this);
52
+ }
53
+ /**
54
+ * on Cancel button click
55
+ * Remove offline saved attachments from IDB if they are missing in originalAttachments
56
+ */
57
+ onClose() {
58
+ this.attachments.forEach(({ url, attachment }) => {
59
+ const existsInOriginal = this.originalAttachments
60
+ .map((item) => item.attachment || [])
61
+ .includes(attachment);
62
+ if (!existsInOriginal && !url) {
63
+ deleteFileFromDexie(attachment);
64
+ }
65
+ });
66
+ fireEvent(this, 'response', { confirmed: false });
67
+ }
68
+ async saveChanges() {
69
+ let fileTypeNotSelected = false;
70
+ this.attachments.forEach((attachment, index) => {
71
+ if (!attachment.file_type) {
72
+ fileTypeNotSelected = true;
73
+ this.errors[index] = { file_type: ['This field is required'] };
74
+ }
75
+ else {
76
+ this.errors[index] = [];
77
+ }
78
+ });
79
+ this.requestUpdate();
80
+ if (fileTypeNotSelected) {
81
+ return;
82
+ }
83
+ if (this.filesForRemove.length) {
84
+ for (const fileId of this.filesForRemove) {
85
+ await deleteFileFromDexie(fileId);
86
+ }
87
+ }
88
+ /**
89
+ * Don't confirm popup if no changes was made
90
+ */
91
+ if (!equals(this.attachments, this.originalAttachments)) {
92
+ fireEvent(this, 'response', { confirmed: true, attachments: this.attachments });
93
+ }
94
+ else {
95
+ fireEvent(this, 'response', { confirmed: false });
96
+ }
97
+ }
98
+ checkFileType(index) {
99
+ var _a;
100
+ return (_a = this.errors[index]) === null || _a === void 0 ? void 0 : _a.file_type;
101
+ }
102
+ retrieveErrorMessage(index) {
103
+ return this.errors[index] && this.errors[index].file_type ? this.errors[index].file_type[0] : '';
104
+ }
105
+ downloadFile(attachment) {
106
+ const url = attachment.url;
107
+ this.link.href = url;
108
+ this.link.click();
109
+ window.URL.revokeObjectURL(url);
110
+ }
111
+ changeFileType(attachment, newType, index) {
112
+ if (newType && attachment.file_type !== newType) {
113
+ attachment.file_type = newType;
114
+ this.errors[index] = [];
115
+ this.requestUpdate();
116
+ }
117
+ }
118
+ attachmentsUploaded({ success, error }) {
119
+ const parsedAttachments = success
120
+ .map((attachment) => {
121
+ if (this.isUploadedAttachment(attachment)) {
122
+ return {
123
+ url: attachment.file_link,
124
+ attachment: attachment.id,
125
+ filename: attachment.filename,
126
+ file_type: null
127
+ };
128
+ }
129
+ else if (this.isOfflineSavedAttachment(attachment)) {
130
+ return {
131
+ attachment: attachment.id,
132
+ filename: attachment.filename,
133
+ composedPath: this.computedPath,
134
+ file_type: null
135
+ };
136
+ }
137
+ else {
138
+ console.warn('Missing fields in parsed attachment');
139
+ return null;
140
+ }
141
+ })
142
+ .filter((attachment) => Boolean(attachment));
143
+ this.attachments = [...this.attachments, ...parsedAttachments];
144
+ if (error && error.length) {
145
+ console.error(error);
146
+ fireEvent(this, 'toast', { text: 'Can not upload attachments. Please try again later' });
147
+ }
148
+ }
149
+ deleteAttachment(index) {
150
+ const [attachment] = this.attachments.splice(index, 1);
151
+ if (!attachment.hasOwnProperty('url')) {
152
+ /**
153
+ * prepare attachment for remove from IDB after Popup confirm
154
+ */
155
+ this.filesForRemove.push(attachment.attachment);
156
+ }
157
+ this.attachments = [...this.attachments];
158
+ }
159
+ isUploadedAttachment(attachment) {
160
+ return (attachment.hasOwnProperty('filename') &&
161
+ attachment.hasOwnProperty('id') &&
162
+ attachment.hasOwnProperty('file_link') &&
163
+ !attachment.hasOwnProperty('unsynced'));
164
+ }
165
+ isOfflineSavedAttachment(attachment) {
166
+ return (attachment.hasOwnProperty('filename') && attachment.hasOwnProperty('id') && attachment.hasOwnProperty('unsynced'));
167
+ }
168
+ static get styles() {
169
+ // language=CSS
170
+ return [
171
+ SharedStyles,
172
+ AttachmentsStyles,
173
173
  css `
174
174
  .file-selector__type-dropdown {
175
175
  flex-basis: 25%;
@@ -218,22 +218,22 @@ export class FormAttachmentsPopup extends LitElement {
218
218
  padding-bottom: 10px;
219
219
  }
220
220
  }
221
- `
222
- ];
223
- }
224
- }
225
- __decorate([
226
- property()
227
- ], FormAttachmentsPopup.prototype, "dialogOpened", void 0);
228
- __decorate([
229
- property()
230
- ], FormAttachmentsPopup.prototype, "saveBtnClicked", void 0);
231
- __decorate([
232
- property()
233
- ], FormAttachmentsPopup.prototype, "attachments", void 0);
234
- __decorate([
235
- property()
236
- ], FormAttachmentsPopup.prototype, "metadata", void 0);
237
- __decorate([
238
- query('#link')
239
- ], FormAttachmentsPopup.prototype, "link", void 0);
221
+ `
222
+ ];
223
+ }
224
+ }
225
+ __decorate([
226
+ property()
227
+ ], FormAttachmentsPopup.prototype, "dialogOpened", void 0);
228
+ __decorate([
229
+ property()
230
+ ], FormAttachmentsPopup.prototype, "saveBtnClicked", void 0);
231
+ __decorate([
232
+ property()
233
+ ], FormAttachmentsPopup.prototype, "attachments", void 0);
234
+ __decorate([
235
+ property()
236
+ ], FormAttachmentsPopup.prototype, "metadata", void 0);
237
+ __decorate([
238
+ query('#link')
239
+ ], FormAttachmentsPopup.prototype, "link", void 0);
@@ -1,8 +1,8 @@
1
- import { FormAttachmentsPopup } from './form-attachments-popup';
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
- export declare function template(this: FormAttachmentsPopup): TemplateResult;
1
+ import { FormAttachmentsPopup } from './form-attachments-popup';
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
+ export declare function template(this: FormAttachmentsPopup): TemplateResult;
@@ -1,13 +1,13 @@
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
- import { InputStyles } from '../lib/styles/input-styles';
8
- import { DialogStyles } from '../lib/styles/dialog.styles';
9
- export function template() {
10
- var _a;
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
+ import { InputStyles } from '../lib/styles/input-styles';
8
+ import { DialogStyles } from '../lib/styles/dialog.styles';
9
+ export function template() {
10
+ var _a;
11
11
  return html `
12
12
  ${InputStyles} ${DialogStyles}
13
13
  <etools-dialog
@@ -26,8 +26,8 @@ export function template() {
26
26
  <a id="link" target="_blank" hidden></a>
27
27
 
28
28
  <div class="popup-container">
29
- ${(_a = this.attachments) === null || _a === void 0 ? void 0 : _a.map((attachment, index) => {
30
- var _a, _b;
29
+ ${(_a = this.attachments) === null || _a === void 0 ? void 0 : _a.map((attachment, index) => {
30
+ var _a, _b;
31
31
  return html `
32
32
  <div class="file-selector-container with-type-dropdown">
33
33
  <!-- Type select Dropdown -->
@@ -76,7 +76,7 @@ export function template() {
76
76
  Delete
77
77
  </paper-button>
78
78
  </div>
79
- `;
79
+ `;
80
80
  })}
81
81
 
82
82
  <!-- Upload button -->
@@ -91,5 +91,5 @@ export function template() {
91
91
  </etools-upload-multi>
92
92
  </div>
93
93
  </etools-dialog>
94
- `;
95
- }
94
+ `;
95
+ }