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

2
jslib

@ -1 +1 @@
Subproject commit b3d1e9d233aa7ed235d6ec0b26cdba41afa065ae
Subproject commit 57e49207e9ad57c71576fc487a38513a4d0fe120

8
package-lock.json generated
View File

@ -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": {

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;

View File

@ -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"
}
}