[jslib] Updated shared components for cipher cloning (#60)
This commit is contained in:
parent
e1d42f95d9
commit
337a7ba59f
|
@ -42,6 +42,7 @@ import { SecureNoteView } from '../../models/view/secureNoteView';
|
||||||
import { Utils } from '../../misc/utils';
|
import { Utils } from '../../misc/utils';
|
||||||
|
|
||||||
export class AddEditComponent implements OnInit {
|
export class AddEditComponent implements OnInit {
|
||||||
|
@Input() cloneMode: boolean = false;
|
||||||
@Input() folderId: string = null;
|
@Input() folderId: string = null;
|
||||||
@Input() cipherId: string;
|
@Input() cipherId: string;
|
||||||
@Input() type: CipherType;
|
@Input() type: CipherType;
|
||||||
|
@ -160,7 +161,12 @@ export class AddEditComponent implements OnInit {
|
||||||
this.editMode = this.cipherId != null;
|
this.editMode = this.cipherId != null;
|
||||||
if (this.editMode) {
|
if (this.editMode) {
|
||||||
this.editMode = true;
|
this.editMode = true;
|
||||||
this.title = this.i18nService.t('editItem');
|
if (this.cloneMode) {
|
||||||
|
this.cloneMode = true;
|
||||||
|
this.title = this.i18nService.t('addItem');
|
||||||
|
} else{
|
||||||
|
this.title = this.i18nService.t('editItem');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.title = this.i18nService.t('addItem');
|
this.title = this.i18nService.t('addItem');
|
||||||
}
|
}
|
||||||
|
@ -176,6 +182,11 @@ export class AddEditComponent implements OnInit {
|
||||||
if (this.editMode) {
|
if (this.editMode) {
|
||||||
const cipher = await this.loadCipher();
|
const cipher = await this.loadCipher();
|
||||||
this.cipher = await cipher.decrypt();
|
this.cipher = await cipher.decrypt();
|
||||||
|
|
||||||
|
// Adjust Cipher Name if Cloning
|
||||||
|
if (this.cloneMode) {
|
||||||
|
this.cipher.name += " - " + this.i18nService.t('clone');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.cipher = new CipherView();
|
this.cipher = new CipherView();
|
||||||
this.cipher.organizationId = this.organizationId == null ? null : this.organizationId;
|
this.cipher.organizationId = this.organizationId == null ? null : this.organizationId;
|
||||||
|
@ -227,16 +238,21 @@ export class AddEditComponent implements OnInit {
|
||||||
this.collections.filter((c) => (c as any).checked).map((c) => c.id);
|
this.collections.filter((c) => (c as any).checked).map((c) => c.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear current Cipher Id to trigger "Add" cipher flow
|
||||||
|
if (this.cloneMode) {
|
||||||
|
this.cipher.id = null;
|
||||||
|
}
|
||||||
|
|
||||||
const cipher = await this.encryptCipher();
|
const cipher = await this.encryptCipher();
|
||||||
try {
|
try {
|
||||||
this.formPromise = this.saveCipher(cipher);
|
this.formPromise = this.saveCipher(cipher);
|
||||||
await this.formPromise;
|
await this.formPromise;
|
||||||
this.cipher.id = cipher.id;
|
this.cipher.id = cipher.id;
|
||||||
this.platformUtilsService.eventTrack(this.editMode ? 'Edited Cipher' : 'Added Cipher');
|
this.platformUtilsService.eventTrack(this.editMode && !this.cloneMode ? 'Edited Cipher' : 'Added Cipher');
|
||||||
this.platformUtilsService.showToast('success', null,
|
this.platformUtilsService.showToast('success', null,
|
||||||
this.i18nService.t(this.editMode ? 'editedItem' : 'addedItem'));
|
this.i18nService.t(this.editMode && !this.cloneMode ? 'editedItem' : 'addedItem'));
|
||||||
this.onSavedCipher.emit(this.cipher);
|
this.onSavedCipher.emit(this.cipher);
|
||||||
this.messagingService.send(this.editMode ? 'editedCipher' : 'addedCipher');
|
this.messagingService.send(this.editMode && !this.cloneMode ? 'editedCipher' : 'addedCipher');
|
||||||
return true;
|
return true;
|
||||||
} catch { }
|
} catch { }
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ const BroadcasterSubscriptionId = 'ViewComponent';
|
||||||
export class ViewComponent implements OnDestroy, OnInit {
|
export class ViewComponent implements OnDestroy, OnInit {
|
||||||
@Input() cipherId: string;
|
@Input() cipherId: string;
|
||||||
@Output() onEditCipher = new EventEmitter<CipherView>();
|
@Output() onEditCipher = new EventEmitter<CipherView>();
|
||||||
|
@Output() onCloneCipher = new EventEmitter<CipherView>();
|
||||||
|
|
||||||
cipher: CipherView;
|
cipher: CipherView;
|
||||||
showPassword: boolean;
|
showPassword: boolean;
|
||||||
|
@ -105,6 +106,10 @@ export class ViewComponent implements OnDestroy, OnInit {
|
||||||
this.onEditCipher.emit(this.cipher);
|
this.onEditCipher.emit(this.cipher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clone() {
|
||||||
|
this.onCloneCipher.emit(this.cipher);
|
||||||
|
}
|
||||||
|
|
||||||
togglePassword() {
|
togglePassword() {
|
||||||
this.platformUtilsService.eventTrack('Toggled Password');
|
this.platformUtilsService.eventTrack('Toggled Password');
|
||||||
this.showPassword = !this.showPassword;
|
this.showPassword = !this.showPassword;
|
||||||
|
|
Loading…
Reference in New Issue