blob: c610110fd3f193302bc90084f395525e5e37cf3b [file] [log] [blame]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03001/************************************************************************************************
2 * @Component: Message box component
3 * In order to use component you need to do a number of things:
4 * 1) Inside your component constructor you need to add listener to the button trigger.
5 * 2) Inside the listener you should write your callback logic.
6 *
7 * Example:
8 * @Component({
9 * selector : 'some-component'
10 * ...
11 * })
12 *
13 * export class SomeComponent {
14 * openModal() : void {
15 * let messageBoxData : MessageBoxData = new MessageBoxData(
16 * "title", // modal title
17 * "message", ModalType.alert, // modal type
18 * [
19 {text:"Save", size:"'x-small'", callback: this.someFunction.bind(this), closeModal:true},
20 {text:"Cancel", size:"'x-small'", closeModal:true}
21 ]);
22 *
23 * MessageBoxService.openModal.next(messageBoxData); // open modal
24 * }
25 * }
26
27 ************************************************************************************************/
28
29
30import { Component } from '@angular/core';
31import { MessageBoxData} from './messageBox.data';
32import { MessageBoxService } from './messageBox.service';
Ittay Stern6f900cc2018-08-29 17:01:32 +030033import { SdcUiServices} from "onap-ui-angular";
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030034
35@Component({
36 selector: 'message-box',
37 template: '<div id="message-box"></div>'
38})
39
40export class MessageBoxComponent {
Ittay Stern6f900cc2018-08-29 17:01:32 +030041 modalService: SdcUiServices.ModalService;
42 isOpened : boolean = false;
43 constructor(modalService: SdcUiServices.ModalService, private _messageBoxService : MessageBoxService) {
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030044 this.modalService = modalService;
Ittay Stern6f900cc2018-08-29 17:01:32 +030045
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030046 MessageBoxService.openModal.subscribe((messageBoxData: MessageBoxData) => {
Ittay Stern6f900cc2018-08-29 17:01:32 +030047 if(this.isOpened) return;
48 this.isOpened = true;
49 modalService.openModal(this._messageBoxService.setConfig(messageBoxData)).onDestroy(()=>{
50 this.isOpened = false;
51 })
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030052 });
53 }
54}
55