1
|
import { Component, ViewChild } from '@angular/core';
|
2
|
import { ActivatedRoute, Router } from "@angular/router";
|
3
|
import { DivContentFormComponent } from "./div-help-content-form.component";
|
4
|
import { DivHelpContent } from "../../domain/div-help-content";
|
5
|
import { HelpContentService } from "../../services/help-content.service";
|
6
|
import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties';
|
7
|
|
8
|
@Component({
|
9
|
selector: 'new-div-help-content',
|
10
|
templateUrl: 'new-div-help-content.component.html',
|
11
|
})
|
12
|
|
13
|
export class NewDivHelpContentComponent {
|
14
|
|
15
|
@ViewChild(DivContentFormComponent)
|
16
|
public formComponent : DivContentFormComponent;
|
17
|
|
18
|
//private errorMessage : string = null;
|
19
|
|
20
|
private communityPid: string;
|
21
|
|
22
|
private pageId: string;
|
23
|
public properties:EnvProperties = null;
|
24
|
|
25
|
public showLoading: boolean = false;
|
26
|
public errorMessage: string = '';
|
27
|
public updateErrorMessage: string = '';
|
28
|
|
29
|
constructor(
|
30
|
private route: ActivatedRoute,
|
31
|
private router: Router,
|
32
|
private _helpContentService: HelpContentService) {}
|
33
|
|
34
|
ngOnInit() {
|
35
|
this.route.data
|
36
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
37
|
this.properties = data.envSpecific;
|
38
|
this.route.queryParams.subscribe(params => {
|
39
|
this.communityPid = params['communityId'];
|
40
|
this.pageId = params['pageId'];
|
41
|
});
|
42
|
});
|
43
|
}
|
44
|
|
45
|
private saveCustom() {
|
46
|
if(this.formComponent.myForm.valid) {
|
47
|
this.showLoading = true;
|
48
|
this.updateErrorMessage = "";
|
49
|
|
50
|
let divHelpContent : DivHelpContent = this.formComponent.myForm.value;
|
51
|
console.info(divHelpContent);
|
52
|
|
53
|
this._helpContentService.insertOrUpdateDivHelpContent(divHelpContent, this.properties.adminToolsAPIURL).subscribe(
|
54
|
_ => {
|
55
|
if(this.pageId) {
|
56
|
this.router.navigate( ['/classContents/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } );
|
57
|
} else {
|
58
|
this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid } } );
|
59
|
}
|
60
|
this.showLoading = false;
|
61
|
},
|
62
|
err => this.handleUpdateError('System error saving page content', err)
|
63
|
);
|
64
|
} else {
|
65
|
this.errorMessage = "Please fill all required fields";
|
66
|
}
|
67
|
}
|
68
|
|
69
|
private cancelCustom() {
|
70
|
if(this.pageId) {
|
71
|
this.router.navigate( ['/classContents/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId } } );
|
72
|
} else {
|
73
|
this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid } } );
|
74
|
}
|
75
|
}
|
76
|
|
77
|
handleUpdateError(message: string, error) {
|
78
|
this.errorMessage = message;
|
79
|
console.log('Server responded: ' + error);
|
80
|
this.showLoading = false;
|
81
|
}
|
82
|
}
|