From 4e9759cd620cd6ee3d3a76f9bbf93f3c473de391 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 7 Nov 2019 10:06:00 -0500 Subject: [PATCH] detect other times nav away from dirty input --- jslib | 2 +- package-lock.json | 8 +++--- src/app/vault/vault.component.ts | 48 ++++++++++++++++++-------------- src/locales/en/messages.json | 4 +-- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/jslib b/jslib index b3d1e9d233..57e49207e9 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit b3d1e9d233aa7ed235d6ec0b26cdba41afa065ae +Subproject commit 57e49207e9ad57c71576fc487a38513a4d0fe120 diff --git a/package-lock.json b/package-lock.json index 5a2b5314c2..421a36c961 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1581,12 +1581,12 @@ "dev": true }, "async": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.1.tgz", - "integrity": "sha512-fNEiL2+AZt6AlAw/29Cr0UDe4sRAHCpEHh54WMz+Bb7QfNcFw4h3loofyJpLeQs4Yx7yuqu/2dLgM5hKOs6HlQ==", + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", + "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", "dev": true, "requires": { - "lodash": "^4.17.10" + "lodash": "^4.17.14" } }, "async-done": { diff --git a/src/app/vault/vault.component.ts b/src/app/vault/vault.component.ts index 42e4b807ed..589e4bfaf1 100644 --- a/src/app/vault/vault.component.ts +++ b/src/app/vault/vault.component.ts @@ -91,16 +91,16 @@ export class VaultComponent implements OnInit, OnDestroy { switch (message.command) { case 'newLogin': - this.addCipher(CipherType.Login); + await this.addCipher(CipherType.Login); break; case 'newCard': - this.addCipher(CipherType.Card); + await this.addCipher(CipherType.Card); break; case 'newIdentity': - this.addCipher(CipherType.Identity); + await this.addCipher(CipherType.Identity); break; case 'newSecureNote': - this.addCipher(CipherType.SecureNote); + await this.addCipher(CipherType.SecureNote); break; case 'newFolder': await this.addFolder(); @@ -190,12 +190,12 @@ export class VaultComponent implements OnInit, OnDestroy { const cipherView = new CipherView(); cipherView.id = params.cipherId; if (params.action === 'edit') { - this.editCipher(cipherView); + await this.editCipher(cipherView); } else { - this.viewCipher(cipherView); + await this.viewCipher(cipherView); } } else if (params.action === 'add') { - this.addCipher(); + await this.addCipher(); } if (params.favorites) { @@ -226,18 +226,8 @@ export class VaultComponent implements OnInit, OnDestroy { 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; + } else if (this.dirtyInput() && await this.wantsToSaveChanges()) { + return; } this.cipherId = cipher.id; @@ -313,9 +303,11 @@ export class VaultComponent implements OnInit, OnDestroy { menu.popup({ window: remote.getCurrentWindow() }); } - editCipher(cipher: CipherView) { + async editCipher(cipher: CipherView) { if (this.action === 'edit' && this.cipherId === cipher.id) { return; + } else if (this.dirtyInput() && await this.wantsToSaveChanges()) { + return; } this.cipherId = cipher.id; @@ -323,9 +315,11 @@ export class VaultComponent implements OnInit, OnDestroy { this.go(); } - addCipher(type: CipherType = null) { + async addCipher(type: CipherType = null) { if (this.action === 'add') { return; + } else if (this.dirtyInput() && await this.wantsToSaveChanges()) { + return; } this.addType = type; @@ -578,6 +572,18 @@ export class VaultComponent implements OnInit, OnDestroy { }); } + private dirtyInput(): boolean { + return (this.action === 'add' || this.action === 'edit') && + document.querySelectorAll('app-vault-add-edit .ng-dirty').length > 0; + } + + private async wantsToSaveChanges(): Promise { + const confirmed = await this.platformUtilsService.showDialog( + this.i18nService.t('unsavedChangesConfirmation'), this.i18nService.t('unsavedChangesTitle'), + this.i18nService.t('yes'), this.i18nService.t('no'), 'warning'); + return !confirmed; + } + private clearFilters() { this.folderId = null; this.collectionId = null; diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index 26e856bbd8..613b30a8d9 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -1269,9 +1269,9 @@ "message": "Privacy Policy" }, "unsavedChangesConfirmation": { - "message": "Are you sure you want to leave? If you leave now then your current information won't be saved" + "message": "Are you sure you want to leave? If you leave now then your current information will not be saved." }, "unsavedChangesTitle": { - "message": "There Are Unsaved Changes" + "message": "Unsaved Changes" } }