|
| 1 | +import { Component, Input } from "@angular/core"; |
| 2 | +import { ModalController } from "@ionic/angular"; |
| 3 | +import { FlowTypes, ITemplateContainerProps } from "../../../models"; |
| 4 | +import { TemplateContainerComponent } from "../../../template-container.component"; |
| 5 | + |
| 6 | +@Component({ |
| 7 | + templateUrl: "./popup.component.html", |
| 8 | + styleUrl: "./popup.component.scss", |
| 9 | +}) |
| 10 | +/** |
| 11 | + * When opening a template as a popup, provide a minimal interface and load |
| 12 | + * the template directly as a regular template-container element |
| 13 | + */ |
| 14 | +export class TemplatePopupComponent { |
| 15 | + @Input() props: ITemplatePopupComponentProps; |
| 16 | + |
| 17 | + constructor(private modalCtrl: ModalController) {} |
| 18 | + |
| 19 | + /** |
| 20 | + * When templates emit completed/uncompleted value from standalone popup close the popup |
| 21 | + * NOTE - we do not want to respond to non-standalone templates as this is done through template nav-actions |
| 22 | + * */ |
| 23 | + handleEmittedValue(value: { emit_value: string; emit_data: any }) { |
| 24 | + const { emit_value } = value; |
| 25 | + if (this.props.dismissOnEmit) { |
| 26 | + if (["completed", "uncompleted"].includes(emit_value)) { |
| 27 | + this.dismiss(value); |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + dismissOnBackdrop(e: MouseEvent) { |
| 33 | + const el = e.target as HTMLElement; |
| 34 | + if (el.classList.contains("popup-backdrop")) { |
| 35 | + this.dismiss(); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + dismiss(value?: { emit_value: string; emit_data: any }) { |
| 40 | + this.modalCtrl.dismiss(value); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +export interface ITemplatePopupComponentProps extends ITemplateContainerProps { |
| 45 | + name: string; |
| 46 | + templatename: string; |
| 47 | + parent?: TemplateContainerComponent; |
| 48 | + row?: FlowTypes.TemplateRow; |
| 49 | + showCloseButton?: boolean; |
| 50 | + /** Dismiss popup when completed or uncompleted is emitted from child template */ |
| 51 | + dismissOnEmit?: boolean; |
| 52 | + /** Wait for template to be self-dismissed before returning (default: True) */ |
| 53 | + waitForDismiss?: boolean; |
| 54 | + /** Display fullscreen overlayed on top of all other app content */ |
| 55 | + fullscreen?: boolean; |
| 56 | +} |
0 commit comments