Project

General

Profile

1
/**
2
 * Created by stefania on 7/14/17.
3
 */
4
import { Component, OnInit, Input } from '@angular/core';
5
import { FormGroup, FormBuilder, Validators } from "@angular/forms";
6
import { Page } from "../../domain/page";
7
import { HelpContentService } from "../../services/help-content.service";
8

    
9

    
10
@Component({
11
    selector: 'page-content-form',
12
    templateUrl: './page-help-content-form.component.html',
13
})
14

    
15
export class PageContentFormComponent implements OnInit{
16

    
17
    @Input('group')
18
    myForm: FormGroup;
19
    @Input('communityId')
20
    communityId: string;
21

    
22
    private availablePages : Page[] = [];
23
    private errorMessage: string;
24

    
25
    private ckeditorContent : string;
26

    
27
    constructor(private _fb: FormBuilder, private _helpContentService: HelpContentService){}
28

    
29
    ngOnInit() {
30
        this.myForm = this.form;
31
        this._helpContentService.getCommunityPages(this.communityId).subscribe(
32
            pages => this.availablePages = pages,
33
            error => this.handleError('System error retrieving pages', error));
34
    }
35

    
36
    public get form() {
37
        return this._fb.group({
38
            page : ['',Validators.required],
39
            community : this.communityId,
40
            placement : ['', Validators.required],
41
            content : ['', Validators.required],
42
            order : ['1', Validators.required],
43
            isActive : true,
44
            _id : '',
45
        });
46
    }
47

    
48
    public reset() {
49
        this.myForm.patchValue({
50
            page : '',
51
            community : this.communityId,
52
            placement : '',
53
            content : [''],
54
            order : '1',
55
            isActive : true,
56
            _id : ''
57
        });
58
        this.myForm.markAsPristine();
59
    }
60

    
61
    handleError(message: string, error) {
62
        this.errorMessage = message + ' (Server responded: ' + error + ')';
63
    }
64
}
(12-12/18)