diff --git a/jslib b/jslib index dddcc2bc93c..25a91313ad0 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit dddcc2bc93c15df4d9b6a38e7f9a76d01fe8b384 +Subproject commit 25a91313ad0441d1c02e043113f931f203fd57e6 diff --git a/src/app/vault/add-edit.component.ts b/src/app/vault/add-edit.component.ts index 97d15d59a11..c1ecbdbc0f5 100644 --- a/src/app/vault/add-edit.component.ts +++ b/src/app/vault/add-edit.component.ts @@ -77,6 +77,7 @@ export class AddEditComponent extends BaseAddEditComponent implements OnChanges, onWindowHidden() { this.showPassword = false; + this.showCardNumber = false; this.showCardCode = false; if (this.cipher !== null && this.cipher.hasFields) { this.cipher.fields.forEach(field => { diff --git a/src/app/vault/vault.component.html b/src/app/vault/vault.component.html index 9c7cef1e7fe..804ff24beba 100644 --- a/src/app/vault/vault.component.html +++ b/src/app/vault/vault.component.html @@ -9,7 +9,7 @@ (onAddCipherOptions)="addCipherOptions()"> diff --git a/src/app/vault/vault.component.ts b/src/app/vault/vault.component.ts index 06a393095a1..7c13db5633f 100644 --- a/src/app/vault/vault.component.ts +++ b/src/app/vault/vault.component.ts @@ -229,9 +229,7 @@ export class VaultComponent implements OnInit, OnDestroy { } async viewCipher(cipher: CipherView) { - if (this.action === 'view' && this.cipherId === cipher.id) { - return; - } else if (this.dirtyInput() && await this.wantsToSaveChanges()) { + if (!await this.canNavigateAway('view', cipher)) { return; } @@ -328,11 +326,17 @@ export class VaultComponent implements OnInit, OnDestroy { } async editCipher(cipher: CipherView) { - if (this.action === 'edit' && this.cipherId === cipher.id) { + if (!await this.canNavigateAway('edit', cipher)) { return; - } else if (this.dirtyInput() && await this.wantsToSaveChanges()) { + } else if (!await this.passwordReprompt(cipher)) { return; - } else if (cipher.reprompt !== CipherRepromptType.None && !await this.passwordRepromptService.showPasswordPrompt()) { + } + + await this.editCipherWithoutPasswordPrompt(cipher); + } + + async editCipherWithoutPasswordPrompt(cipher: CipherView) { + if (!await this.canNavigateAway('edit', cipher)) { return; } @@ -342,11 +346,17 @@ export class VaultComponent implements OnInit, OnDestroy { } async cloneCipher(cipher: CipherView) { - if (this.action === 'clone' && this.cipherId === cipher.id) { + if (!await this.canNavigateAway('clone', cipher)) { return; - } else if (this.dirtyInput() && await this.wantsToSaveChanges()) { + } else if (!await this.passwordReprompt(cipher)) { return; - } else if (cipher.reprompt !== CipherRepromptType.None && !await this.passwordRepromptService.showPasswordPrompt()) { + } + + await this.cloneCipherWithoutPasswordPrompt(cipher); + } + + async cloneCipherWithoutPasswordPrompt(cipher: CipherView) { + if (!await this.canNavigateAway('edit', cipher)) { return; } @@ -356,9 +366,7 @@ export class VaultComponent implements OnInit, OnDestroy { } async addCipher(type: CipherType = null) { - if (this.action === 'add') { - return; - } else if (this.dirtyInput() && await this.wantsToSaveChanges()) { + if (!await this.canNavigateAway('add', null)) { return; } @@ -680,4 +688,19 @@ export class VaultComponent implements OnInit, OnDestroy { this.addOrganizationId = null; this.addCollectionIds = null; } + + private async canNavigateAway(action: string, cipher?: CipherView) { + // Don't navigate to same route + if (this.action === action && (cipher == null || this.cipherId === cipher.id)) { + return false; + } else if (this.dirtyInput() && await this.wantsToSaveChanges()) { + return false; + } + + return true; + } + + private async passwordReprompt(cipher: CipherView) { + return cipher.reprompt === CipherRepromptType.None || await this.passwordRepromptService.showPasswordPrompt(); + } } diff --git a/src/app/vault/view.component.ts b/src/app/vault/view.component.ts index ef3e1463d22..705a4ccece9 100644 --- a/src/app/vault/view.component.ts +++ b/src/app/vault/view.component.ts @@ -81,6 +81,7 @@ export class ViewComponent extends BaseViewComponent implements OnChanges { onWindowHidden() { this.showPassword = false; + this.showCardNumber = false; this.showCardCode = false; if (this.cipher !== null && this.cipher.hasFields) { this.cipher.fields.forEach(field => {