diff --git a/src/app/vault/attachments.component.html b/src/app/vault/attachments.component.html
index 9fbf3902..1cba8ec6 100644
--- a/src/app/vault/attachments.component.html
+++ b/src/app/vault/attachments.component.html
@@ -1,6 +1,6 @@
diff --git a/src/app/vault/attachments.component.ts b/src/app/vault/attachments.component.ts
index 574e77f4..7b34b96d 100644
--- a/src/app/vault/attachments.component.ts
+++ b/src/app/vault/attachments.component.ts
@@ -32,6 +32,8 @@ export class AttachmentsComponent implements OnInit {
cipherDomain: Cipher;
hasUpdatedKey: boolean;
canAccessAttachments: boolean;
+ formPromise: Promise
;
+ deletePromises: { [id: string]: Promise; } = {};
constructor(private cipherService: CipherService, private analytics: Angulartics2,
private toasterService: ToasterService, private i18nService: I18nService,
@@ -53,7 +55,7 @@ export class AttachmentsComponent implements OnInit {
}
}
- async save() {
+ async submit() {
if (!this.hasUpdatedKey) {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('updateKey'));
@@ -74,10 +76,13 @@ export class AttachmentsComponent implements OnInit {
return;
}
- this.cipherDomain = await this.cipherService.saveAttachmentWithServer(this.cipherDomain, files[0]);
- this.cipher = await this.cipherDomain.decrypt();
- this.analytics.eventTrack.next({ action: 'Added Attachment' });
- this.toasterService.popAsync('success', null, this.i18nService.t('attachmentSaved'));
+ try {
+ this.formPromise = this.cipherService.saveAttachmentWithServer(this.cipherDomain, files[0]);
+ this.cipherDomain = await this.formPromise;
+ this.cipher = await this.cipherDomain.decrypt();
+ this.analytics.eventTrack.next({ action: 'Added Attachment' });
+ this.toasterService.popAsync('success', null, this.i18nService.t('attachmentSaved'));
+ } catch { }
// reset file input
// ref: https://stackoverflow.com/a/20552042
@@ -87,16 +92,26 @@ export class AttachmentsComponent implements OnInit {
}
async delete(attachment: AttachmentView) {
+ if (this.deletePromises[attachment.id] != null) {
+ return;
+ }
+
if (!confirm(this.i18nService.t('deleteAttachmentConfirmation'))) {
return;
}
- await this.cipherService.deleteAttachmentWithServer(this.cipher.id, attachment.id);
- this.analytics.eventTrack.next({ action: 'Deleted Attachment' });
- this.toasterService.popAsync('success', null, this.i18nService.t('deletedAttachment'));
- const i = this.cipher.attachments.indexOf(attachment);
- if (i > -1) {
- this.cipher.attachments.splice(i, 1);
- }
+ try {
+ this.deletePromises[attachment.id] = this.cipherService.deleteAttachmentWithServer(
+ this.cipher.id, attachment.id);
+ await this.deletePromises[attachment.id];
+ this.analytics.eventTrack.next({ action: 'Deleted Attachment' });
+ this.toasterService.popAsync('success', null, this.i18nService.t('deletedAttachment'));
+ const i = this.cipher.attachments.indexOf(attachment);
+ if (i > -1) {
+ this.cipher.attachments.splice(i, 1);
+ }
+ } catch { }
+
+ this.deletePromises[attachment.id] = null;
}
}