Project

General

Profile

1 50607 konstantin
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 51057 argiro.kok
import { EnvProperties } from '../../openaireLibrary/utils/properties/env-properties';
7 50607 konstantin
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 51417 konstantin
    //private errorMessage : string = null;
19 50607 konstantin
20
    private communityPid: string;
21
22
    private pageId: string;
23 51057 argiro.kok
    public properties:EnvProperties = null;
24 50607 konstantin
25 51417 konstantin
    public showLoading: boolean = false;
26
    public errorMessage: string = '';
27
    public updateErrorMessage: string = '';
28
29 50607 konstantin
    constructor(
30
        private route: ActivatedRoute,
31
        private router: Router,
32
        private _helpContentService: HelpContentService) {}
33
34
    ngOnInit() {
35 51057 argiro.kok
      this.route.data
36
        .subscribe((data: { envSpecific: EnvProperties }) => {
37
           this.properties = data.envSpecific;
38 51417 konstantin
           this.route.queryParams.subscribe(params => {
39
             this.communityPid = params['communityId'];
40
             this.pageId = params['pageId'];
41
           });
42 50607 konstantin
        });
43
    }
44
45
    private saveCustom() {
46 51417 konstantin
        if(this.formComponent.myForm.valid) {
47
            this.showLoading = true;
48
            this.updateErrorMessage = "";
49 50607 konstantin
50
            let divHelpContent : DivHelpContent = this.formComponent.myForm.value;
51 51343 konstantin
            console.info(divHelpContent);
52 50607 konstantin
53 51057 argiro.kok
            this._helpContentService.insertOrUpdateDivHelpContent(divHelpContent, this.properties.adminToolsAPIURL).subscribe(
54 50607 konstantin
                _ => {
55
                  if(this.pageId) {
56 51343 konstantin
                    this.router.navigate( ['/classContents/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId  } } );
57 50607 konstantin
                  } else {
58 51343 konstantin
                    this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid } } );
59 50607 konstantin
                  }
60 51417 konstantin
                  this.showLoading = false;
61 50607 konstantin
                },
62 51417 konstantin
                err => this.handleUpdateError('System error saving page content', err)
63 50607 konstantin
            );
64
        } else {
65
            this.errorMessage = "Please fill all required fields";
66
        }
67
    }
68
69
    private cancelCustom() {
70
      if(this.pageId) {
71 51343 konstantin
        this.router.navigate( ['/classContents/'], { queryParams: { "communityId": this.communityPid, "pageId": this.pageId  } } );
72 50607 konstantin
      } else {
73 51343 konstantin
        this.router.navigate(['/classContents'], { queryParams: { "communityId": this.communityPid } } );
74 50607 konstantin
      }
75
    }
76
77 51417 konstantin
    handleUpdateError(message: string, error) {
78
        this.errorMessage = message;
79
        console.log('Server responded: ' + error);
80
        this.showLoading = false;
81 50607 konstantin
    }
82
}