2018-04-06 05:49:04 +02:00
|
|
|
import { Location } from '@angular/common';
|
2018-10-23 16:29:05 +02:00
|
|
|
import { Component } from '@angular/core';
|
2018-04-06 05:49:04 +02:00
|
|
|
import {
|
|
|
|
ActivatedRoute,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
|
|
|
|
|
|
|
import { AuditService } from 'jslib/abstractions/audit.service';
|
|
|
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
2018-10-23 16:29:05 +02:00
|
|
|
import { CollectionService } from 'jslib/abstractions/collection.service';
|
2018-04-06 05:49:04 +02:00
|
|
|
import { FolderService } from 'jslib/abstractions/folder.service';
|
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
2018-04-09 23:35:16 +02:00
|
|
|
import { StateService } from 'jslib/abstractions/state.service';
|
2018-10-23 16:29:05 +02:00
|
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
2018-04-06 05:49:04 +02:00
|
|
|
|
|
|
|
import { AddEditComponent as BaseAddEditComponent } from 'jslib/angular/components/add-edit.component';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-vault-add-edit',
|
2018-04-06 17:48:45 +02:00
|
|
|
templateUrl: 'add-edit.component.html',
|
2018-04-06 05:49:04 +02:00
|
|
|
})
|
2018-10-23 16:29:05 +02:00
|
|
|
export class AddEditComponent extends BaseAddEditComponent {
|
2018-07-25 05:23:44 +02:00
|
|
|
showAttachments = true;
|
2018-04-14 20:56:30 +02:00
|
|
|
|
2018-04-06 05:49:04 +02:00
|
|
|
constructor(cipherService: CipherService, folderService: FolderService,
|
|
|
|
i18nService: I18nService, platformUtilsService: PlatformUtilsService,
|
2018-04-09 23:35:16 +02:00
|
|
|
auditService: AuditService, stateService: StateService,
|
2018-10-23 16:29:05 +02:00
|
|
|
userService: UserService, collectionService: CollectionService,
|
2018-04-09 23:35:16 +02:00
|
|
|
private route: ActivatedRoute, private router: Router,
|
|
|
|
private location: Location) {
|
2018-10-23 16:29:05 +02:00
|
|
|
super(cipherService, folderService, i18nService, platformUtilsService, auditService, stateService,
|
|
|
|
userService, collectionService);
|
2018-04-06 05:49:04 +02:00
|
|
|
}
|
|
|
|
|
2018-10-23 16:29:05 +02:00
|
|
|
async ngOnInit() {
|
|
|
|
await super.ngOnInit();
|
2018-07-25 05:23:44 +02:00
|
|
|
this.showAttachments = !this.platformUtilsService.isEdge();
|
2018-04-06 05:49:04 +02:00
|
|
|
this.route.queryParams.subscribe(async (params) => {
|
|
|
|
if (params.cipherId) {
|
|
|
|
this.cipherId = params.cipherId;
|
|
|
|
}
|
2018-04-10 06:04:49 +02:00
|
|
|
if (params.folderId) {
|
|
|
|
this.folderId = params.folderId;
|
|
|
|
}
|
|
|
|
if (params.type) {
|
|
|
|
const type = parseInt(params.type, null);
|
|
|
|
this.type = type;
|
|
|
|
}
|
2018-04-06 05:49:04 +02:00
|
|
|
this.editMode = !params.cipherId;
|
|
|
|
await this.load();
|
2018-04-10 06:04:49 +02:00
|
|
|
|
|
|
|
if (!this.editMode) {
|
2018-06-06 20:45:05 +02:00
|
|
|
if (params.name && (this.cipher.name == null || this.cipher.name === '')) {
|
2018-04-10 06:04:49 +02:00
|
|
|
this.cipher.name = params.name;
|
|
|
|
}
|
2018-06-06 20:45:05 +02:00
|
|
|
if (params.uri && (this.cipher.login.uris[0].uri == null || this.cipher.login.uris[0].uri === '')) {
|
2018-04-10 06:04:49 +02:00
|
|
|
this.cipher.login.uris[0].uri = params.uri;
|
|
|
|
}
|
|
|
|
}
|
2018-04-06 05:49:04 +02:00
|
|
|
});
|
2018-04-10 06:04:49 +02:00
|
|
|
|
2018-04-18 21:49:03 +02:00
|
|
|
window.setTimeout(() => {
|
2018-04-10 06:04:49 +02:00
|
|
|
if (!this.editMode) {
|
|
|
|
if (this.cipher.name != null && this.cipher.name !== '') {
|
|
|
|
document.getElementById('loginUsername').focus();
|
|
|
|
} else {
|
|
|
|
document.getElementById('name').focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 200);
|
2018-04-06 05:49:04 +02:00
|
|
|
}
|
|
|
|
|
2018-04-06 05:51:58 +02:00
|
|
|
async submit(): Promise<boolean> {
|
2018-04-06 05:49:04 +02:00
|
|
|
if (await super.submit()) {
|
|
|
|
this.location.back();
|
2018-04-06 05:51:58 +02:00
|
|
|
return true;
|
2018-04-06 05:49:04 +02:00
|
|
|
}
|
2018-04-06 05:51:58 +02:00
|
|
|
|
|
|
|
return false;
|
2018-04-06 05:49:04 +02:00
|
|
|
}
|
|
|
|
|
2018-04-11 19:51:09 +02:00
|
|
|
attachments() {
|
|
|
|
super.attachments();
|
|
|
|
this.router.navigate(['/attachments'], { queryParams: { cipherId: this.cipher.id } });
|
|
|
|
}
|
|
|
|
|
2018-10-23 15:25:44 +02:00
|
|
|
share() {
|
2018-10-23 16:29:05 +02:00
|
|
|
this.router.navigate(['/share-cipher'], { queryParams: { cipherId: this.cipher.id } });
|
2018-10-23 15:25:44 +02:00
|
|
|
}
|
|
|
|
|
2018-04-06 05:49:04 +02:00
|
|
|
cancel() {
|
|
|
|
super.cancel();
|
|
|
|
this.location.back();
|
|
|
|
}
|
2018-04-09 23:35:16 +02:00
|
|
|
|
2018-04-10 20:20:03 +02:00
|
|
|
async generatePassword(): Promise<boolean> {
|
|
|
|
const confirmed = await super.generatePassword();
|
|
|
|
if (confirmed) {
|
|
|
|
this.stateService.save('addEditCipher', this.cipher);
|
|
|
|
this.router.navigate(['generator']);
|
|
|
|
}
|
|
|
|
return confirmed;
|
2018-04-09 23:35:16 +02:00
|
|
|
}
|
2018-04-11 22:23:05 +02:00
|
|
|
|
2018-04-12 04:33:32 +02:00
|
|
|
async delete(): Promise<boolean> {
|
|
|
|
const confirmed = await super.delete();
|
|
|
|
if (confirmed) {
|
2018-04-11 22:27:20 +02:00
|
|
|
this.router.navigate(['/tabs/vault']);
|
|
|
|
}
|
2018-04-12 04:33:32 +02:00
|
|
|
return confirmed;
|
2018-04-11 22:23:05 +02:00
|
|
|
}
|
2018-04-06 05:49:04 +02:00
|
|
|
}
|