2019-10-16 15:36:18 +09:00
|
|
|
import { Component, OnInit, Inject } from '@angular/core';
|
2020-01-14 15:13:20 +09:00
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
FormBuilder,
|
|
|
|
Validators,
|
|
|
|
ValidatorFn,
|
|
|
|
AbstractControl
|
|
|
|
} from '@angular/forms';
|
2019-10-16 15:36:18 +09:00
|
|
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
2019-10-21 16:32:22 +09:00
|
|
|
import { GroupDetailData } from '@ucap-webmessenger/protocol-sync';
|
2019-10-16 15:36:18 +09:00
|
|
|
|
|
|
|
export interface EditGroupDialogData {
|
|
|
|
title: string;
|
2019-10-21 16:32:22 +09:00
|
|
|
group: GroupDetailData;
|
2019-10-16 15:36:18 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface EditGroupDialogResult {
|
|
|
|
choice: boolean;
|
2019-10-21 16:32:22 +09:00
|
|
|
groupName: string;
|
|
|
|
group: GroupDetailData;
|
2019-10-16 15:36:18 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-layout-messenger-edit-group',
|
|
|
|
templateUrl: './edit-group.dialog.component.html',
|
|
|
|
styleUrls: ['./edit-group.dialog.component.scss']
|
|
|
|
})
|
|
|
|
export class EditGroupDialogComponent implements OnInit {
|
2019-10-21 16:32:22 +09:00
|
|
|
groupName: string;
|
|
|
|
inputForm: FormGroup;
|
|
|
|
|
2019-10-16 15:36:18 +09:00
|
|
|
constructor(
|
|
|
|
public dialogRef: MatDialogRef<EditGroupDialogData, EditGroupDialogResult>,
|
2019-10-21 16:32:22 +09:00
|
|
|
@Inject(MAT_DIALOG_DATA) public data: EditGroupDialogData,
|
|
|
|
private formBuilder: FormBuilder
|
2019-10-16 15:36:18 +09:00
|
|
|
) {}
|
|
|
|
|
2019-10-21 16:32:22 +09:00
|
|
|
ngOnInit(): void {
|
|
|
|
this.inputForm = this.formBuilder.group({
|
2020-01-14 15:13:20 +09:00
|
|
|
groupName: [
|
|
|
|
this.data.group.name,
|
|
|
|
[Validators.required, this.checkSpecialCharacter()]
|
|
|
|
]
|
2019-10-21 16:32:22 +09:00
|
|
|
});
|
|
|
|
}
|
2019-10-16 15:36:18 +09:00
|
|
|
|
2020-01-14 15:13:20 +09:00
|
|
|
checkSpecialCharacter(): ValidatorFn {
|
|
|
|
return (control: AbstractControl): { [key: string]: any } | null => {
|
|
|
|
const forbidden = /[\{\}\[\]\/?.;:|\)*~`!^+<>@\#$%&\\\=\(\'\"]/g.test(
|
|
|
|
control.value
|
|
|
|
);
|
|
|
|
return forbidden ? { groupName: { value: control.value } } : null;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-10-16 15:36:18 +09:00
|
|
|
onClickChoice(choice: boolean): void {
|
|
|
|
this.dialogRef.close({
|
2019-10-21 16:32:22 +09:00
|
|
|
choice,
|
|
|
|
groupName: this.inputForm.get('groupName').value,
|
|
|
|
group: this.data.group
|
2019-10-16 15:36:18 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|