128 lines
4.4 KiB
TypeScript
128 lines
4.4 KiB
TypeScript
import { Component, ViewChild, ElementRef } from '@angular/core';
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
|
import { PageContentFormComponent } from "./page-help-content-form.component";
|
|
import { PageHelpContent } from "../../utils/entities/adminTool/page-help-content";
|
|
import { HelpContentService } from "../../services/help-content.service";
|
|
import { EnvProperties } from '../../utils/properties/env-properties';
|
|
|
|
import {Session} from '../../login/utils/helper.class';
|
|
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
|
import {Page} from "../../utils/entities/adminTool/page";
|
|
import {properties} from "../../../../environments/environment";
|
|
|
|
@Component({
|
|
selector: 'new-page-help-content',
|
|
templateUrl: 'new-page-help-content.component.html',
|
|
})
|
|
|
|
export class NewPageHelpContentComponent {
|
|
|
|
@ViewChild(PageContentFormComponent)
|
|
public formComponent : PageContentFormComponent;
|
|
|
|
//private errorMessage : string = null;
|
|
|
|
public communityPid: string;
|
|
|
|
public pageId: string;
|
|
public page: Page;
|
|
|
|
public properties:EnvProperties = null;
|
|
|
|
public showLoading: boolean = true;
|
|
public errorMessage: string = '';
|
|
public updateErrorMessage: string = '';
|
|
|
|
constructor(
|
|
private element: ElementRef,
|
|
private route: ActivatedRoute,
|
|
private router: Router,
|
|
private _helpContentService: HelpContentService) {}
|
|
|
|
ngOnInit() {
|
|
this.route.data
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
this.properties = data.envSpecific;
|
|
this.route.queryParams.subscribe(params => {
|
|
HelperFunctions.scroll();
|
|
|
|
this.communityPid = params['communityId'];
|
|
this.pageId = params['pageId'];
|
|
|
|
if(this.pageId) {
|
|
this.getPage(this.pageId);
|
|
} else {
|
|
this.showLoading = false;
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
private getPage(pageId: string) {
|
|
this._helpContentService.getPage(pageId,this.properties.adminToolsAPIURL).subscribe(
|
|
page => {
|
|
if(this.properties.adminToolsPortalType != page.portalType) {
|
|
this.router.navigate(['/pageContents'], { queryParams: { "communityId": this.communityPid} });
|
|
} else {
|
|
this.page = page;
|
|
this.formComponent.setPlacements(this.page);
|
|
this.showLoading = false;
|
|
console.info(this.page);
|
|
}
|
|
},
|
|
error => this.handleError('System error retrieving page with id: '+pageId, error)
|
|
);
|
|
}
|
|
|
|
public saveCustom() {
|
|
if(!Session.isLoggedIn()){
|
|
this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} });
|
|
} else {
|
|
//this.errorMessage = null;
|
|
|
|
if(this.formComponent.myForm.valid) {
|
|
this.showLoading = true;
|
|
this.updateErrorMessage = "";
|
|
|
|
let pageHelpContent : PageHelpContent = this.formComponent.myForm.value;
|
|
|
|
this._helpContentService.savePageHelpContent(pageHelpContent, this.properties.adminToolsAPIURL).subscribe(
|
|
_ => {
|
|
if(this.pageId) {
|
|
this.router.navigate( ['/helptexts/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } );
|
|
} else {
|
|
this.router.navigate(['/helptexts'], { queryParams: { "communityId": this.communityPid} });
|
|
}
|
|
this.showLoading = false;
|
|
},
|
|
err => this.handleUpdateError('System error saving page content', err)
|
|
);
|
|
} else {
|
|
this.errorMessage = "Please fill all required fields";
|
|
}
|
|
}
|
|
}
|
|
|
|
public cancelCustom() {
|
|
if(this.pageId) {
|
|
this.router.navigate( ['/helptexts/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } );
|
|
} else {
|
|
this.router.navigate(['/helptexts'], { queryParams: { "communityId": this.communityPid} } );
|
|
}
|
|
}
|
|
|
|
handleUpdateError(message: string, error) {
|
|
this.updateErrorMessage = message;
|
|
console.log('Server responded: ' + error);
|
|
|
|
this.showLoading = false;
|
|
}
|
|
|
|
handleError(message: string, error) {
|
|
this.errorMessage = message;
|
|
console.log('Server responded: ' + error);
|
|
this.showLoading = false;
|
|
}
|
|
}
|