Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 1 | /************************************************************************************************ |
| 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 | |
| 30 | import { Component } from '@angular/core'; |
| 31 | import { MessageBoxData} from './messageBox.data'; |
| 32 | import { MessageBoxService } from './messageBox.service'; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 33 | import { SdcUiServices} from "onap-ui-angular"; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 34 | |
| 35 | @Component({ |
| 36 | selector: 'message-box', |
| 37 | template: '<div id="message-box"></div>' |
| 38 | }) |
| 39 | |
| 40 | export class MessageBoxComponent { |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 41 | modalService: SdcUiServices.ModalService; |
| 42 | isOpened : boolean = false; |
| 43 | constructor(modalService: SdcUiServices.ModalService, private _messageBoxService : MessageBoxService) { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 44 | this.modalService = modalService; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 45 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 46 | MessageBoxService.openModal.subscribe((messageBoxData: MessageBoxData) => { |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 47 | if(this.isOpened) return; |
| 48 | this.isOpened = true; |
| 49 | modalService.openModal(this._messageBoxService.setConfig(messageBoxData)).onDestroy(()=>{ |
| 50 | this.isOpened = false; |
| 51 | }) |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 52 | }); |
| 53 | } |
| 54 | } |
| 55 | |