Guest User

Untitled

a guest
Jul 18th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. constructor(private location: PlatformLocation,
  2. private _dialog: DialogService,
  3. private router: Router) { }
  4.  
  5. open() {
  6. this.showDialog = true;
  7. const body = document.body;
  8. body.classList.add('cell-modal-open');
  9. }
  10.  
  11. close() {
  12. this.dialog = undefined;
  13. }
  14.  
  15. private handleDialog(d: Dialog) {
  16. if (!d) {
  17. this.close();
  18. } else if (d.template) {
  19. if (this.showDialog) {
  20. this.close();
  21. }
  22. this.dialog = d;
  23. this.open();
  24. }
  25. }
  26.  
  27. ngOnInit() {
  28. this.subscription = this
  29. ._dialog
  30. .getDialog()
  31. .subscribe({
  32. next: (d) => { this.handleDialog(d); console.log('subscribed dialog') },
  33. error: (err) => this.handleDialogError(err)
  34. });
  35. this.initialiseRoutingEventListeners();
  36. }
  37.  
  38. private d: Dialog = { template: null, size: DialogSizeEnum.XLarge };
  39. private dialogSubject = new BehaviorSubject<Dialog>({ template: null, size: DialogSizeEnum.XLarge });
  40.  
  41. constructor() { }
  42.  
  43. showDialog(template: TemplateRef<any>, size = DialogSizeEnum.XLarge, requiresAction = false) {
  44. Object.assign(this.d, { template: template, size: size, requiresAction: requiresAction });
  45. if (this.d !== null) {
  46. this.dialogSubject.next(this.d);
  47. }
  48. }
  49.  
  50. getDialog(): BehaviorSubject<Dialog> {
  51. return this.dialogSubject;
  52. }
  53.  
  54. clear() {
  55. this.dialogSubject.next(null);
  56. }
Add Comment
Please, Sign In to add comment