/** * Created by stefania on 7/14/17. */ import { Component, OnInit, Input } from '@angular/core'; import { FormGroup, FormBuilder, Validators } from "@angular/forms"; import { Page } from "../../domain/page"; import { HelpContentService } from "../../services/help-content.service"; @Component({ selector: 'page-content-form', templateUrl: './page-help-content-form.component.html', }) export class PageContentFormComponent implements OnInit{ @Input('group') myForm: FormGroup; @Input('communityPid') communityPid: string; @Input('pageId') pageId: string; private availablePages : Page[] = []; private errorMessage: string; private ckeditorContent : string; constructor(private _fb: FormBuilder, private _helpContentService: HelpContentService){} ngOnInit() { this.myForm = this.form; this._helpContentService.getCommunityPages(this.communityPid).subscribe( pages => this.availablePages = pages, error => this.handleError('System error retrieving pages', error)); } public get form() { return this._fb.group({ page : [this.pageId,Validators.required], community : this.communityPid, placement : ['', Validators.required], content : ['', Validators.required], order : ['1', Validators.required], isActive : true, _id : '', }); } public reset() { this.myForm.patchValue({ page : '', community : this.communityPid, placement : '', content : [''], order : '1', isActive : true, _id : '' }); this.myForm.markAsPristine(); } handleError(message: string, error) { this.errorMessage = message + ' (Server responded: ' + error + ')'; } }