Project

General

Profile

1
import { Component, OnInit, Input } from '@angular/core';
2
import { ActivatedRoute } from "@angular/router";
3
import { FormGroup, FormBuilder, Validators } from "@angular/forms";
4
import { Page } from "../../domain/page";
5
import { HelpContentService } from "../../services/help-content.service";
6
import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties';
7

    
8

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

    
14
export class PageContentFormComponent implements OnInit{
15

    
16
    @Input('group')
17
    myForm: FormGroup;
18
    @Input('communityPid')
19
    communityPid: string;
20
    @Input('pageId')
21
    pageId: string;
22

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

    
26
    private ckeditorContent : string;
27
    public properties:EnvProperties = null;
28

    
29
    public showLoading: boolean = true;
30
    public errorMessage: string = '';
31
    @Input() updateErrorMessage: string = '';
32

    
33
    constructor(private route: ActivatedRoute,private _fb: FormBuilder, private _helpContentService: HelpContentService){}
34

    
35
    ngOnInit() {
36
        this.myForm = this.form;
37
        this.route.data
38
          .subscribe((data: { envSpecific: EnvProperties }) => {
39
             this.properties = data.envSpecific;
40

    
41
             this._helpContentService.getPages(this.properties.adminToolsAPIURL, this.communityPid).subscribe(
42
               pages => {
43
                 this.availablePages = pages;
44
                 this.showLoading = false;
45
               },
46
               error => this.handleError('System error retrieving pages', error));
47
        });
48
    }
49

    
50
    public get form() {
51
        return this._fb.group({
52
            page : [this.pageId,Validators.required],
53
            community : this.communityPid,
54
            placement : ['', Validators.required],
55
            content : ['', Validators.required],
56
            order : ['1', Validators.required],
57
            isActive : true,
58
            isPriorTo : false,
59
            _id : '',
60
        });
61
    }
62

    
63
    public reset() {
64
        this.myForm.patchValue({
65
            page : '',
66
            community : this.communityPid,
67
            placement : '',
68
            content : [''],
69
            order : '1',
70
            isActive : true,
71
            isPriorTo : false,
72
            _id : ''
73
        });
74
        this.myForm.markAsPristine();
75
    }
76

    
77
    handleError(message: string, error) {
78
        this.errorMessage = message;
79
        console.log('Server responded: ' + error);
80

    
81
        this.showLoading = false;
82
    }
83
}
(6-6/8)