93 lines
2.2 KiB
TypeScript
93 lines
2.2 KiB
TypeScript
import { Inject, Component, OnInit, OnDestroy, ViewEncapsulation } from '@angular/core';
|
|
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
|
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
|
|
import { UntypedFormBuilder, Validators, UntypedFormGroup, FormControl } from '@angular/forms';
|
|
import { User } from '../user.model';
|
|
import { Owner } from '../owner.model';
|
|
|
|
@Component({
|
|
selector: 'app-settings',
|
|
templateUrl: './settings.component.html',
|
|
styleUrls: ['/settings.component.css']
|
|
})
|
|
|
|
export class SettingsComponent implements OnInit {
|
|
|
|
settingsForm: UntypedFormGroup;
|
|
owner: Owner;
|
|
useZats: boolean;
|
|
useVKey: boolean = false;
|
|
coins = [
|
|
{
|
|
label: 'US Dollar',
|
|
symbol: 'usd'
|
|
},{
|
|
label: 'Euro',
|
|
symbol: 'eur'
|
|
},{
|
|
label: 'British Pound',
|
|
symbol: 'gbp'
|
|
},{
|
|
label: 'Canadian Dollar',
|
|
symbol: 'cad'
|
|
},{
|
|
label: 'Australian Dollar',
|
|
symbol: 'aud'
|
|
}
|
|
];
|
|
|
|
constructor(
|
|
private fb: UntypedFormBuilder,
|
|
private dialogRef: MatDialogRef<SettingsComponent>,
|
|
@Inject(MAT_DIALOG_DATA) public data: Owner) {
|
|
this.useZats = data.zats;
|
|
this.useVKey = data.payconf;
|
|
this.settingsForm = fb.group({
|
|
name: [data.name, Validators.required],
|
|
currency: [data.currency, Validators.required],
|
|
useZats: [data.zats, Validators.required],
|
|
useVKey: [data.payconf, Validators.required],
|
|
vKey: [data.viewkey]
|
|
});
|
|
if (data.payconf) {
|
|
this.settingsForm.get('vKey')!.enable();
|
|
}
|
|
this.owner = data;
|
|
}
|
|
|
|
ngOnInit() {
|
|
}
|
|
|
|
close() {
|
|
this.dialogRef.close();
|
|
}
|
|
|
|
save() {
|
|
this.owner.name = this.settingsForm.value.name;
|
|
this.owner.currency = this.settingsForm.value.currency;
|
|
this.owner.zats = this.settingsForm.value.useZats;
|
|
this.owner.payconf = this.settingsForm.value.useVKey;
|
|
|
|
this.owner.viewkey = this.settingsForm.value.vKey;
|
|
|
|
this.dialogRef.close(this.owner);
|
|
}
|
|
|
|
onChange(ob: MatSlideToggleChange) {
|
|
this.useZats = ob.checked;
|
|
}
|
|
|
|
onChangeVKeyOn(ob: MatSlideToggleChange) {
|
|
// console.log("Viewing key switch is " +
|
|
// ( ob.checked ? "[ON]." : "[OFF]." ) );
|
|
|
|
this.useVKey = ob.checked;
|
|
|
|
if ( ob.checked )
|
|
this.settingsForm.get('vKey')!.enable();
|
|
else
|
|
this.settingsForm.get('vKey')!.disable();
|
|
|
|
}
|
|
}
|