125 lines
4.0 KiB
TypeScript
125 lines
4.0 KiB
TypeScript
import { Component, NgZone, OnChanges, OnDestroy, ViewChild } from "@angular/core";
|
|
import { NgForm } from "@angular/forms";
|
|
|
|
import { AddEditComponent as BaseAddEditComponent } from "@bitwarden/angular/components/add-edit.component";
|
|
import { AuditService } from "@bitwarden/common/abstractions/audit.service";
|
|
import { BroadcasterService } from "@bitwarden/common/abstractions/broadcaster.service";
|
|
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
|
|
import { CollectionService } from "@bitwarden/common/abstractions/collection.service";
|
|
import { EventService } from "@bitwarden/common/abstractions/event.service";
|
|
import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction";
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
|
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
|
|
import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction";
|
|
import { PasswordRepromptService } from "@bitwarden/common/abstractions/passwordReprompt.service";
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction";
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
|
|
|
const BroadcasterSubscriptionId = "AddEditComponent";
|
|
|
|
@Component({
|
|
selector: "app-vault-add-edit",
|
|
templateUrl: "add-edit.component.html",
|
|
})
|
|
export class AddEditComponent extends BaseAddEditComponent implements OnChanges, OnDestroy {
|
|
@ViewChild("form")
|
|
private form: NgForm;
|
|
constructor(
|
|
cipherService: CipherService,
|
|
folderService: FolderService,
|
|
i18nService: I18nService,
|
|
platformUtilsService: PlatformUtilsService,
|
|
auditService: AuditService,
|
|
stateService: StateService,
|
|
collectionService: CollectionService,
|
|
messagingService: MessagingService,
|
|
eventService: EventService,
|
|
policyService: PolicyService,
|
|
passwordRepromptService: PasswordRepromptService,
|
|
private broadcasterService: BroadcasterService,
|
|
private ngZone: NgZone,
|
|
logService: LogService,
|
|
organizationService: OrganizationService
|
|
) {
|
|
super(
|
|
cipherService,
|
|
folderService,
|
|
i18nService,
|
|
platformUtilsService,
|
|
auditService,
|
|
stateService,
|
|
collectionService,
|
|
messagingService,
|
|
eventService,
|
|
policyService,
|
|
logService,
|
|
passwordRepromptService,
|
|
organizationService
|
|
);
|
|
}
|
|
|
|
async ngOnInit() {
|
|
this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => {
|
|
this.ngZone.run(() => {
|
|
switch (message.command) {
|
|
case "windowHidden":
|
|
this.onWindowHidden();
|
|
break;
|
|
default:
|
|
}
|
|
});
|
|
});
|
|
// We use ngOnChanges for everything else instead.
|
|
}
|
|
|
|
async ngOnChanges() {
|
|
await super.init();
|
|
await this.load();
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
|
}
|
|
|
|
async load() {
|
|
if (
|
|
document.querySelectorAll("app-vault-add-edit .ng-dirty").length === 0 ||
|
|
(this.cipher != null && this.cipherId !== this.cipher.id)
|
|
) {
|
|
this.cipher = null;
|
|
}
|
|
super.load();
|
|
}
|
|
|
|
onWindowHidden() {
|
|
this.showPassword = false;
|
|
this.showCardNumber = false;
|
|
this.showCardCode = false;
|
|
if (this.cipher !== null && this.cipher.hasFields) {
|
|
this.cipher.fields.forEach((field) => {
|
|
field.showValue = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
allowOwnershipOptions(): boolean {
|
|
return (
|
|
(!this.editMode || this.cloneMode) &&
|
|
this.ownershipOptions &&
|
|
(this.ownershipOptions.length > 1 || !this.allowPersonal)
|
|
);
|
|
}
|
|
|
|
markPasswordAsDirty() {
|
|
this.form.controls["Login.Password"].markAsDirty();
|
|
}
|
|
|
|
openHelpReprompt() {
|
|
this.platformUtilsService.launchUri(
|
|
"https://bitwarden.com/help/managing-items/#protect-individual-items"
|
|
);
|
|
}
|
|
}
|