mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.0 KiB
102 lines
2.0 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { BehaviorSubject, Observable } from 'rxjs';
|
|
|
|
export interface Openable {
|
|
isOpenChanges: Observable<boolean>;
|
|
|
|
isOpen: boolean;
|
|
}
|
|
|
|
export class DialogModel implements Openable {
|
|
private readonly isOpen$: BehaviorSubject<boolean>;
|
|
|
|
public get isOpenChanges(): Observable<boolean> {
|
|
return this.isOpen$;
|
|
}
|
|
|
|
public get isOpen(): boolean {
|
|
return this.isOpen$.value;
|
|
}
|
|
|
|
constructor(isOpen = false) {
|
|
this.isOpen$ = new BehaviorSubject<boolean>(isOpen);
|
|
}
|
|
|
|
public show(): DialogModel {
|
|
this.isOpen$.next(true);
|
|
|
|
return this;
|
|
}
|
|
|
|
public hide(): DialogModel {
|
|
this.isOpen$.next(false);
|
|
|
|
return this;
|
|
}
|
|
|
|
public toggle(): DialogModel {
|
|
this.isOpen$.next(!this.isOpen$.value);
|
|
|
|
return this;
|
|
}
|
|
}
|
|
|
|
export class ModalModel implements Openable {
|
|
private readonly isOpen$: BehaviorSubject<boolean>;
|
|
|
|
public get isOpenChanges(): Observable<boolean> {
|
|
return this.isOpen$;
|
|
}
|
|
|
|
public get isOpen(): boolean {
|
|
return this.isOpen$.value;
|
|
}
|
|
|
|
constructor(isOpen = false) {
|
|
this.isOpen$ = new BehaviorSubject<boolean>(isOpen);
|
|
}
|
|
|
|
public show(): ModalModel {
|
|
if (!this.isOpen$.value) {
|
|
if (openModal && openModal !== this) {
|
|
openModal.hide();
|
|
}
|
|
|
|
openModal = this;
|
|
|
|
this.isOpen$.next(true);
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
public hide(): ModalModel {
|
|
if (this.isOpen$.value) {
|
|
if (openModal === this) {
|
|
openModal = null;
|
|
}
|
|
|
|
this.isOpen$.next(false);
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
public toggle(): ModalModel {
|
|
if (this.isOpen$.value) {
|
|
this.hide();
|
|
} else {
|
|
this.show();
|
|
}
|
|
|
|
return this;
|
|
}
|
|
}
|
|
|
|
let openModal: ModalModel | null = null;
|