notification.component.ts
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {Injectable, Inject} from "ng-forward";
import {LanguageService} from "../language-selector/language.service";
@Injectable()
@Inject("$log", "SweetAlert", LanguageService)
export class Notification {
    constructor(
        private $log: ng.ILogService,
        private SweetAlert: any,
        private languageService: LanguageService
    ) { }
    public static DEFAULT_ERROR_TITLE = "notification.error.default.title";
    public static DEFAULT_ERROR_MESSAGE = "notification.error.default.message";
    public static DEFAULT_SUCCESS_TIMER = 1000;
    error(message: string = Notification.DEFAULT_ERROR_MESSAGE, title: string = Notification.DEFAULT_ERROR_TITLE) {
        this.$log.debug("Notification error:", title, message, this.languageService.currentLanguage());
        this.SweetAlert.swal({
            title: this.languageService.translate(title),
            text: this.languageService.translate(message),
            type: "error"
        });
    }
    httpError(status: number, data: any): boolean {
        this.error(`notification.http_error.${status}.message`);
        return true; // return true to indicate that the error was already handled
    }
    success(title: string, text: string, timer: number = Notification.DEFAULT_SUCCESS_TIMER) {
        this.SweetAlert.swal({
            title: title,
            text: text,
            type: "success",
            timer: timer
        });
    }
}