import { Component, ViewChild } from '@angular/core'; import { ActivatedRoute, Router } from "@angular/router"; import { DivContentFormComponent } from "./div-help-content-form.component"; import { DivHelpContent } from "../../domain/div-help-content"; import { HelpContentService } from "../../services/help-content.service"; @Component({ selector: 'new-div-help-content', templateUrl: 'new-div-help-content.component.html', }) export class NewDivHelpContentComponent { @ViewChild(DivContentFormComponent) public formComponent : DivContentFormComponent; private errorMessage : string = null; private communityPid: string; private pageId: string; constructor( private route: ActivatedRoute, private router: Router, private _helpContentService: HelpContentService) {} ngOnInit() { this.route.queryParams.subscribe(params => { this.communityPid = params['community']; this.pageId = params['pageId']; }); } private saveCustom() { this.errorMessage = null; if(this.formComponent.myForm.valid) { let divHelpContent : DivHelpContent = this.formComponent.myForm.value; this._helpContentService.insertOrUpdateDivHelpContent(divHelpContent).subscribe( _ => { if(this.pageId) { this.router.navigate( ['/classContents/'], { queryParams: { "community": this.communityPid, "page": this.pageId } } ); } else { this.router.navigate(['/classContents']); } }, err => this.handleError('System error saving page content', err) ); } else { this.errorMessage = "Please fill all required fields"; } } private cancelCustom() { if(this.pageId) { this.router.navigate( ['/classContents/'], { queryParams: { "community": this.communityPid, "page": this.pageId } } ); } else { this.router.navigate(['/classContents']); } } handleError(message: string, error) { this.errorMessage = message + ' (Server responded: ' + error + ')'; } }