1 | import { Component, Input } from '@angular/core';
|
2 |
|
3 | import { Message } from 'primeng/components/common/api';
|
4 | import { MessageService } from 'primeng/components/common/messageservice';
|
5 | import { Utils } from './utils';
|
6 |
|
7 | @Component({
|
8 | selector: 'message-box',
|
9 | template: `<p-growl [(value)]="msgs" [sticky]="isSticky"></p-growl>
|
10 | <p-dialog [modal]="true" [header]="header" [draggable]="false" [closable]="false" [visible]="isRunning" [width]="150"
|
11 | [height]="188" [minWidth]="148" [minHeight]="128" >
|
12 | <div style="margin-left: 60px" class="loading"></div>
|
13 | </p-dialog>`
|
14 | })
|
15 | export class MessageBoxComponent {
|
16 | @Input() isRunning: boolean;
|
17 | msgs: Message[] = [];
|
18 | isSticky = false;
|
19 |
|
20 | header = Utils.resolveLocalizedMessage('loading.data');
|
21 | showMessage(style: string, msg: string): void {
|
22 | this.msgs = [];
|
23 | this.isSticky = "error" == style;
|
24 | let title = Utils.resolveLocalizedMessage("msg.type." + style);
|
25 | this.msgs.push({ severity: style, summary: title, detail: msg });
|
26 | }
|
27 | showMessages(style: string, msgs: string[]): void {
|
28 | this.isSticky = "error" == style;
|
29 | for (let msg of msgs) {
|
30 | this.msgs = [];
|
31 | let title = Utils.resolveLocalizedMessage("msg.type." + style);
|
32 | this.msgs.push({ severity: style, summary: title, detail: msg });
|
33 | }
|
34 | }
|
35 |
|
36 | getOffset(): any {
|
37 |
|
38 | let clientWidth = document.documentElement.clientWidth;
|
39 | let clientHeight = document.documentElement.clientHeight;
|
40 | let top = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
|
41 | let left = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
|
42 | let x = (clientWidth - 100) / 2 + left;
|
43 | let y = (clientHeight - 30) / 2 + top;
|
44 |
|
45 | return { left: x, top: y };
|
46 | }
|
47 | }
|