1 | import { Response } from '@angular/http';
|
2 | import { ViewChild } from '@angular/core';
|
3 |
|
4 | import { Utils } from './utils';
|
5 | import { MessageBoxComponent } from './messagebox.component';
|
6 |
|
7 | declare var calLang: any, fileDownloadRoot: string, isRunning: number;
|
8 | export abstract class BaseComponent {
|
9 | @ViewChild(MessageBoxComponent) messageBox: MessageBoxComponent;
|
10 | calLang = calLang;
|
11 | static MSG_SAVED_KEY = "msg.saved.success";
|
12 | static MSG_DELETED_KEY = "msg.deleted.success";
|
13 | |
14 |
|
15 |
|
16 |
|
17 |
|
18 | resolveMessage(key: string, ...params: string[]): string {
|
19 | return Utils.resolveLocalizedMessage(key, params);
|
20 | }
|
21 | |
22 |
|
23 |
|
24 |
|
25 | resolveDownloadUrl(uri: string): string {
|
26 | return fileDownloadRoot + uri;
|
27 | }
|
28 | |
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | formatDate(date: Date, pattern: string): string {
|
35 | if (date) {
|
36 | return Utils.formatDate(date, pattern);
|
37 | }
|
38 | return "";
|
39 | }
|
40 | |
41 |
|
42 |
|
43 |
|
44 | protected handleError(error: any, mBox: MessageBoxComponent = this.messageBox): void {
|
45 | if (this && this.messageBox) {
|
46 | this.messageBox.showMessage("error", error);
|
47 | } else if (mBox) {
|
48 | mBox.showMessage("error", error);
|
49 | } else {
|
50 | alert(error);
|
51 | }
|
52 | }
|
53 | |
54 |
|
55 |
|
56 |
|
57 | protected showError(message: string) {
|
58 | this.showMessage(message, "error");
|
59 | }
|
60 | |
61 |
|
62 |
|
63 |
|
64 | protected showWarnKey(messageKey: string) {
|
65 | this.showMessage(this.resolveMessage(messageKey), "warn");
|
66 | }
|
67 | |
68 |
|
69 |
|
70 |
|
71 | protected showSuccessKey(messageKey: string) {
|
72 | this.showMessage(this.resolveMessage(messageKey), "success");
|
73 | }
|
74 | |
75 |
|
76 |
|
77 |
|
78 | protected showInfoKey(messageKey: string) {
|
79 | this.showMessage(this.resolveMessage(messageKey), "info");
|
80 | }
|
81 | |
82 |
|
83 |
|
84 |
|
85 | protected showErrorKey(messageKey: string) {
|
86 | this.showMessage(this.resolveMessage(messageKey), "error");
|
87 | }
|
88 | |
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | protected showMessage(message: string, style: string) {
|
95 | if (this && this.messageBox) {
|
96 | this.messageBox.showMessage(style, message);
|
97 | } else {
|
98 | alert(message);
|
99 | }
|
100 | }
|
101 | |
102 |
|
103 |
|
104 |
|
105 |
|
106 | protected getRequestParamValue(name: string): string {
|
107 | let result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
|
108 | if (result == null || result.length < 1) {
|
109 | return null;
|
110 | }
|
111 | return result[1];
|
112 | }
|
113 | |
114 |
|
115 |
|
116 |
|
117 | protected getRequestParamValues(name: string): string[] {
|
118 | let result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
|
119 | if (result == null || result.length < 1) {
|
120 | return null;
|
121 | }
|
122 | return result;
|
123 | }
|
124 | |
125 |
|
126 |
|
127 | isRunning(): boolean {
|
128 | return isRunning > 0;
|
129 | }
|
130 | } |
\ | No newline at end of file |