2017-09-22 12:26:08 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
2017-12-13 12:15:19 +01:00
|
|
|
@Input('communityId')
|
|
|
|
communityId: string;
|
2017-09-22 12:26:08 +02:00
|
|
|
|
|
|
|
private availablePages : Page[] = [];
|
|
|
|
private errorMessage: string;
|
|
|
|
|
|
|
|
private ckeditorContent : string;
|
|
|
|
|
|
|
|
constructor(private _fb: FormBuilder, private _helpContentService: HelpContentService){}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.myForm = this.form;
|
2017-12-13 12:15:19 +01:00
|
|
|
this._helpContentService.getCommunityPages(this.communityId).subscribe(
|
2017-09-22 12:26:08 +02:00
|
|
|
pages => this.availablePages = pages,
|
|
|
|
error => this.handleError('System error retrieving pages', error));
|
|
|
|
}
|
|
|
|
|
|
|
|
public get form() {
|
|
|
|
return this._fb.group({
|
|
|
|
page : ['',Validators.required],
|
2017-12-13 12:15:19 +01:00
|
|
|
community : this.communityId,
|
2017-09-22 12:26:08 +02:00
|
|
|
placement : ['', Validators.required],
|
|
|
|
content : ['', Validators.required],
|
|
|
|
order : ['1', Validators.required],
|
|
|
|
isActive : true,
|
|
|
|
_id : '',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public reset() {
|
|
|
|
this.myForm.patchValue({
|
|
|
|
page : '',
|
2017-12-13 12:15:19 +01:00
|
|
|
community : this.communityId,
|
2017-09-22 12:26:08 +02:00
|
|
|
placement : '',
|
|
|
|
content : [''],
|
|
|
|
order : '1',
|
|
|
|
isActive : true,
|
|
|
|
_id : ''
|
|
|
|
});
|
|
|
|
this.myForm.markAsPristine();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleError(message: string, error) {
|
|
|
|
this.errorMessage = message + ' (Server responded: ' + error + ')';
|
|
|
|
}
|
2017-12-13 12:15:19 +01:00
|
|
|
}
|