novo-elements
Version:
Bullhorn's NOVO Element Repository for Angular 2
141 lines (120 loc) • 3.62 kB
text/typescript
// NG2
import { Component, ViewContainerRef, ViewChild, AfterViewInit, Input, Output, EventEmitter, OnInit, Injectable } from '@angular/core';
// APP
import { Deferred } from './../../utils/deferred/Deferred';
import { ComponentUtils } from '../../utils/component-utils/ComponentUtils';
/**
* Params that can be passed to the Modal
*/
export interface ModalParams {
[propName: string]: any;
}
export class NovoModalParams implements ModalParams {
}
/**
* Reference to an opened dialog.
*/
export class NovoModalRef {
component: any = null;
contentRef: any = null;
containerRef: any = null;
isClosed: boolean = false;
_onClosed: any = Deferred();
// Gets a promise that is resolved when the dialog is closed.
get onClosed() {
return this._onClosed;
}
open() {
document.body.classList.add('modal-open');
}
close(result?: any) {
document.body.classList.remove('modal-open');
if (this.contentRef) {
this.contentRef.destroy();
}
if (this.containerRef) {
this.containerRef.destroy();
}
this._onClosed.resolve(result);
}
}
export class NovoModalContainerElement implements AfterViewInit {
container: ViewContainerRef;
constructor(private modalRef: NovoModalRef, private componentUtils: ComponentUtils) {}
ngAfterViewInit() {
setTimeout(() => {
this.modalRef.contentRef = this.componentUtils.appendNextToLocation(this.modalRef.component, this.container);
});
}
}
export class NovoModalElement {
constructor(private modalRef: NovoModalRef) {
}
close() {
this.modalRef.close();
}
}
export class NovoModalNotificationElement implements OnInit {
type: string;
icon: string;
cancel: EventEmitter<any> = new EventEmitter();
iconType: string;
constructor(private modalRef: NovoModalRef) {
this.modalRef = modalRef;
}
close() {
this.cancel.emit();
this.modalRef.close();
}
ngOnInit() {
switch (this.type) {
case 'success':
this.iconType = 'bhi-check';
break;
case 'warning':
this.iconType = 'bhi-caution-o';
break;
case 'error':
this.iconType = 'bhi-caution-o';
break;
case 'custom':
this.iconType = `bhi-${this.icon}`;
break;
default:
break;
}
}
}