1
|
import {Component, OnInit, Input} from '@angular/core';
|
2
|
import {FormGroup, FormArray, FormBuilder, Validators} from "@angular/forms";
|
3
|
import { HelpContentService } from "../../services/help-content.service";
|
4
|
import { Page } from "../../domain/page";
|
5
|
|
6
|
@Component({
|
7
|
selector: 'divId-form',
|
8
|
templateUrl: './divId-form.component.html',
|
9
|
})
|
10
|
|
11
|
export class DivIdFormComponent implements OnInit{
|
12
|
@Input('group')
|
13
|
myForm: FormGroup;
|
14
|
@Input('communityPid')
|
15
|
communityPid: string;
|
16
|
@Input('pageId')
|
17
|
pageId: string;
|
18
|
@Input('availablePages')
|
19
|
availablePages : Page[] = [];
|
20
|
|
21
|
public errorMessage: string;
|
22
|
|
23
|
constructor(public _fb: FormBuilder, private _helpContentService: HelpContentService){}
|
24
|
|
25
|
ngOnInit(): void {
|
26
|
|
27
|
}
|
28
|
|
29
|
public get form() {
|
30
|
return this._fb.group({
|
31
|
_id : '',
|
32
|
name : ['', Validators.required],
|
33
|
page : [this.pageId,Validators.required],
|
34
|
community : this.communityPid,
|
35
|
});
|
36
|
}
|
37
|
|
38
|
public reset() {
|
39
|
this.myForm.patchValue({
|
40
|
_id : '',
|
41
|
name : '',
|
42
|
page: '',
|
43
|
community: this.communityPid
|
44
|
});
|
45
|
}
|
46
|
|
47
|
handleError(message: string, error) {
|
48
|
if(error == null) {
|
49
|
this.reset();
|
50
|
}
|
51
|
this.errorMessage = message + ' (Server responded: ' + error + ')';
|
52
|
}
|
53
|
}
|