From f5854fd32c19c44d32a3e6739b30271d4dccd393 Mon Sep 17 00:00:00 2001 From: Avi Ziv Date: Mon, 31 Jul 2017 15:50:46 +0300 Subject: [SDC] code rebase for sdc resync to LF Change-Id: If6d87c9e324f508a8a6b80b10a03d1843901472e Signed-off-by: Michael Lando --- catalog-ui/src/app/ng2/services/modal.service.ts | 27 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'catalog-ui/src/app/ng2/services/modal.service.ts') diff --git a/catalog-ui/src/app/ng2/services/modal.service.ts b/catalog-ui/src/app/ng2/services/modal.service.ts index 32192f40c2..65ff870769 100644 --- a/catalog-ui/src/app/ng2/services/modal.service.ts +++ b/catalog-ui/src/app/ng2/services/modal.service.ts @@ -11,10 +11,10 @@ export class ModalService { constructor(private componentFactoryResolver: ComponentFactoryResolver, private applicationRef: ApplicationRef) { } - /* Shortcut method to open a simple modal with title, message, and close button that simply closes the modal. */ + /* Shortcut method to open an alert modal with title, message, and close button that simply closes the modal. */ public openAlertModal(title: string, message: string, closeButtonText?:string) { let closeButton: ButtonModel = new ButtonModel(closeButtonText || 'Close', 'grey', this.closeCurrentModal); - let modalModel: ModalModel = new ModalModel('sm', title, message, [closeButton]); + let modalModel: ModalModel = new ModalModel('sm', title, message, [closeButton], 'alert'); this.createCustomModal(modalModel).instance.open(); } @@ -22,19 +22,28 @@ export class ModalService { /** * Shortcut method to open a basic modal with title, message, and an action button with callback, as well as close button. * NOTE: To close the modal from within the callback, use modalService.closeCurrentModal() //if you run into zone issues with callbacks see:https://stackoverflow.com/questions/36566698/how-to-dynamically-create-bootstrap-modals-as-angular2-components + * NOTE: To add dynamic content to the modal, use modalService.addDynamicContentToModal(). First param is the return value of this function -- componentRef. * @param title Heading for modal * @param message Message for modal * @param actionButtonText Blue call to action button * @param actionButtonCallback function to invoke when button is clicked * @param cancelButtonText text for close/cancel button */ - public openActionModal = (title:string, message:string, actionButtonText:string, actionButtonCallback:Function, cancelButtonText:string) => { + public createActionModal = (title: string, message: string, actionButtonText: string, actionButtonCallback: Function, cancelButtonText: string): ComponentRef => { let actionButton: ButtonModel = new ButtonModel(actionButtonText, 'blue', actionButtonCallback); let cancelButton: ButtonModel = new ButtonModel(cancelButtonText, 'grey', this.closeCurrentModal); let modalModel: ModalModel = new ModalModel('sm', title, message, [actionButton, cancelButton]); - this.createCustomModal(modalModel).instance.open(); + let modalInstance: ComponentRef = this.createCustomModal(modalModel); + return modalInstance; + } + + + public createErrorModal = (closeButtonText?: string, errorMessage?: string):ComponentRef => { + let closeButton: ButtonModel = new ButtonModel(closeButtonText || 'Close', 'grey', this.closeCurrentModal); + let modalModel: ModalModel = new ModalModel('sm', 'Error', errorMessage, [closeButton], 'error'); + let modalInstance: ComponentRef = this.createCustomModal(modalModel); + return modalInstance; } - /* Use this method to create a modal with title, message, and completely custom buttons. Use response.instance.open() to open */ public createCustomModal = (customModalData: ModalModel): ComponentRef => { @@ -53,6 +62,14 @@ export class ModalService { } + public addDynamicContentToModal = (modalInstance: ComponentRef, dynamicComponentType: Type, dynamicComponentInput: any) => { + + let dynamicContent = this.createDynamicComponent(dynamicComponentType, modalInstance.instance.dynamicContentContainer); + dynamicContent.instance.input = dynamicComponentInput; + modalInstance.instance.dynamicContent = dynamicContent; + return modalInstance; + } + //Creates a component dynamically (aka during runtime). If a view container is not specified, it will append the new component to the app root. //To subscribe to an event from invoking component: componentRef.instance.clicked.subscribe((m) => console.log(m.name)); private createDynamicComponent(componentType: Type, viewContainerRef?:ViewContainerRef): ComponentRef { -- cgit 1.2.3-korg