[SDC-29] rebase continue work to align source
[sdc.git] / catalog-ui / src / app / ng2 / components / modal / modal.component.ts
1 /**
2  * Created by rc2122 on 6/1/2017.
3  */
4 import { Component, ElementRef, Input, OnInit, OnDestroy } from '@angular/core';
5 import * as $ from 'jquery';
6 import {ButtonsModelMap} from "app/models/button";
7
8 @Component({
9     selector: 'modal',
10     templateUrl: './modal.component.html',
11     styleUrls:['modal.component.less']
12 })
13
14 export class ModalComponent implements OnInit, OnDestroy {
15     @Input() size: string; 'xl|l|md|sm|xsm'
16     @Input() title: string;
17     @Input() public buttons:ButtonsModelMap;
18     private modalElement: JQuery;
19     private buttonsNames:Array<string>;
20
21     constructor( el: ElementRef ) {
22         this.modalElement = $(el.nativeElement);
23     }
24
25     ngOnInit(): void {
26         let modal = this;
27         this.modalElement.appendTo('body');
28         if(this.buttons){
29             this.buttonsNames = Object.keys(this.buttons);
30         }
31     }
32
33     ngOnDestroy(): void {
34         this.modalElement.remove();
35     }
36
37     open(): void {
38         this.modalElement.show();
39         $('body').addClass('modal-open');
40     }
41
42     close(): void {
43         this.modalElement.hide();
44         $('body').removeClass('modal-open');
45     }
46 }