1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 00:03:56 +00:00

detect other times nav away from dirty input

This commit is contained in:
Kyle Spearrin
2019-11-07 10:06:00 -05:00
parent f8a378b26d
commit 4e9759cd62
4 changed files with 34 additions and 28 deletions

View File

@@ -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<boolean> {
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;