From f8a378b26d68826fe41bd487b26c73797921bcb9 Mon Sep 17 00:00:00 2001 From: Alberto Franco Date: Thu, 7 Nov 2019 08:55:23 -0500 Subject: [PATCH] Warn of unsaved changes (#338) * Warn of unsaved changes on new or edited entries * Fixed message box options * Limit 'ng-dirty' to details DOM node --- src/app/vault/vault.component.ts | 14 +++++++++++++- src/locales/en/messages.json | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/app/vault/vault.component.ts b/src/app/vault/vault.component.ts index 331ce1a297c..42e4b807ed6 100644 --- a/src/app/vault/vault.component.ts +++ b/src/app/vault/vault.component.ts @@ -223,9 +223,21 @@ export class VaultComponent implements OnInit, OnDestroy { }); } - viewCipher(cipher: CipherView) { + async viewCipher(cipher: CipherView) { if (this.action === 'view' && this.cipherId === cipher.id) { return; + } else if ( + (this.action == 'add' || this.action === 'edit') + && document.getElementById('details').getElementsByClassName('ng-dirty').length > 0 + ) { + const confirmed = await this.platformUtilsService.showDialog( + this.i18nService.t('unsavedChangesConfirmation'), + this.i18nService.t('unsavedChangesTitle'), + this.i18nService.t('yes'), + this.i18nService.t('no'), + 'warning' + ); + if (!confirmed) return; } this.cipherId = cipher.id; diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index d031645f804..26e856bbd8f 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -1267,5 +1267,11 @@ }, "privacyPolicy": { "message": "Privacy Policy" + }, + "unsavedChangesConfirmation": { + "message": "Are you sure you want to leave? If you leave now then your current information won't be saved" + }, + "unsavedChangesTitle": { + "message": "There Are Unsaved Changes" } }