2017-09-22 12:26:08 +02:00
|
|
|
/**
|
|
|
|
* Created by stefania on 7/13/17.
|
|
|
|
*/
|
2018-12-03 12:33:03 +01:00
|
|
|
import { Component, ViewChild, ElementRef } from '@angular/core';
|
2017-09-22 12:26:08 +02:00
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
|
|
|
import { PageContentFormComponent } from "./page-help-content-form.component";
|
|
|
|
import { PageHelpContent } from "../../domain/page-help-content";
|
|
|
|
import { HelpContentService } from "../../services/help-content.service";
|
2018-03-06 16:36:33 +01:00
|
|
|
import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties';
|
2017-09-22 12:26:08 +02:00
|
|
|
|
2018-11-13 16:26:49 +01:00
|
|
|
import {Session} from '../../openaireLibrary/login/utils/helper.class';
|
|
|
|
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
|
2019-04-24 13:44:46 +02:00
|
|
|
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
|
2018-11-13 16:26:49 +01:00
|
|
|
|
2017-09-22 12:26:08 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'new-page-help-content',
|
|
|
|
templateUrl: 'new-page-help-content.component.html',
|
|
|
|
})
|
|
|
|
|
|
|
|
export class NewPageHelpContentComponent {
|
|
|
|
|
|
|
|
@ViewChild(PageContentFormComponent)
|
|
|
|
public formComponent : PageContentFormComponent;
|
|
|
|
|
2018-10-30 16:31:16 +01:00
|
|
|
//private errorMessage : string = null;
|
2017-09-22 12:26:08 +02:00
|
|
|
|
2018-01-29 23:45:42 +01:00
|
|
|
private communityPid: string;
|
2017-12-13 12:15:19 +01:00
|
|
|
|
2017-12-20 15:26:30 +01:00
|
|
|
private pageId: string;
|
2018-03-06 16:36:33 +01:00
|
|
|
public properties:EnvProperties = null;
|
2017-12-20 15:26:30 +01:00
|
|
|
|
2018-10-30 16:31:16 +01:00
|
|
|
public showLoading: boolean = false;
|
|
|
|
public errorMessage: string = '';
|
|
|
|
public updateErrorMessage: string = '';
|
|
|
|
|
2017-09-22 12:26:08 +02:00
|
|
|
constructor(
|
2018-12-03 12:33:03 +01:00
|
|
|
private element: ElementRef,
|
2017-09-22 12:26:08 +02:00
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private _helpContentService: HelpContentService) {}
|
|
|
|
|
2017-12-13 12:15:19 +01:00
|
|
|
ngOnInit() {
|
2018-03-06 16:36:33 +01:00
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
this.route.queryParams.subscribe(params => {
|
2019-04-24 13:44:46 +02:00
|
|
|
HelperFunctions.scroll();
|
2018-12-03 12:33:03 +01:00
|
|
|
|
2018-10-30 16:31:16 +01:00
|
|
|
this.communityPid = params['communityId'];
|
2018-03-06 16:36:33 +01:00
|
|
|
this.pageId = params['pageId'];
|
|
|
|
});
|
|
|
|
});
|
2017-12-13 12:15:19 +01:00
|
|
|
}
|
|
|
|
|
2017-09-22 12:26:08 +02:00
|
|
|
private saveCustom() {
|
2018-11-13 16:26:49 +01:00
|
|
|
if(!Session.isLoggedIn()){
|
|
|
|
this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this.router.url} });
|
|
|
|
} else {
|
2018-10-30 16:31:16 +01:00
|
|
|
//this.errorMessage = null;
|
2017-12-13 12:15:19 +01:00
|
|
|
|
2017-09-22 12:26:08 +02:00
|
|
|
if(this.formComponent.myForm.valid) {
|
2018-10-30 16:31:16 +01:00
|
|
|
this.showLoading = true;
|
|
|
|
this.updateErrorMessage = "";
|
|
|
|
|
2017-09-22 12:26:08 +02:00
|
|
|
let pageHelpContent : PageHelpContent = this.formComponent.myForm.value;
|
2018-01-24 16:45:12 +01:00
|
|
|
|
2018-03-06 16:36:33 +01:00
|
|
|
this._helpContentService.savePageHelpContent(pageHelpContent, this.properties.adminToolsAPIURL).subscribe(
|
2017-12-20 15:26:30 +01:00
|
|
|
_ => {
|
|
|
|
if(this.pageId) {
|
2018-10-30 16:31:16 +01:00
|
|
|
this.router.navigate( ['/pageContents/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } );
|
2017-12-20 15:26:30 +01:00
|
|
|
} else {
|
2018-10-30 16:31:16 +01:00
|
|
|
this.router.navigate(['/pageContents'], { queryParams: { "communityId": this.communityPid} });
|
2017-12-20 15:26:30 +01:00
|
|
|
}
|
2018-10-30 16:31:16 +01:00
|
|
|
this.showLoading = false;
|
2017-12-20 15:26:30 +01:00
|
|
|
},
|
2018-10-30 16:31:16 +01:00
|
|
|
err => this.handleUpdateError('System error saving page content', err)
|
2017-09-22 12:26:08 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.errorMessage = "Please fill all required fields";
|
|
|
|
}
|
2018-11-13 16:26:49 +01:00
|
|
|
}
|
2017-09-22 12:26:08 +02:00
|
|
|
}
|
|
|
|
|
2018-01-24 16:45:12 +01:00
|
|
|
private cancelCustom() {
|
|
|
|
if(this.pageId) {
|
2018-10-30 16:31:16 +01:00
|
|
|
this.router.navigate( ['/pageContents/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } );
|
2018-01-24 16:45:12 +01:00
|
|
|
} else {
|
2018-10-30 16:31:16 +01:00
|
|
|
this.router.navigate(['/pageContents'], { queryParams: { "communityId": this.communityPid} } );
|
2018-01-24 16:45:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-30 16:31:16 +01:00
|
|
|
handleUpdateError(message: string, error) {
|
|
|
|
this.updateErrorMessage = message;
|
|
|
|
console.log('Server responded: ' + error);
|
2017-09-22 12:26:08 +02:00
|
|
|
|
2018-10-30 16:31:16 +01:00
|
|
|
this.showLoading = false;
|
2017-09-22 12:26:08 +02:00
|
|
|
}
|
2017-12-13 12:15:19 +01:00
|
|
|
}
|