Took 25 hours 49 minutes
This commit is contained in:
2022-11-15 00:58:59 +01:00
parent a7fac21442
commit a356b39bad
46 changed files with 936 additions and 181 deletions

View File

@ -2,14 +2,19 @@ import {ButtonType} from "./ButtonType";
export class Modal {
private static currentModalId = "";
private static currentModalId: string | undefined = "";
private _title: string = "iTender";
private _content: string | undefined = "";
private _id: string = "";
private _loader: boolean = false;
private _buttons: { type: string, content: string, onclick: Function }[] = [];
private _leftCentered: boolean = false;
set leftCentered(value: boolean) {
this._leftCentered = value;
}
private static modalInClose = false;
constructor(id, title: string, content?: string) {
this._id = id;
@ -17,6 +22,10 @@ export class Modal {
this._content = content;
}
public static isModalOpen(): boolean {
return !(!this.currentModalId);
}
set title(value: string) {
this._title = value;
@ -34,8 +43,7 @@ export class Modal {
this._loader = value;
}
public addButton( type: ButtonType, content: string, onclick: Function )
{
public addButton(type: ButtonType, content: string, onclick: Function) {
this._buttons.push({type: type, content: content, onclick: onclick});
}
@ -43,16 +51,39 @@ export class Modal {
if (!this._content)
this._content = "";
if( this._leftCentered )
{
this._content = "<div style='text-align: left; padding-left: 2%;'>" + this._content;
}
if (this._loader)
this._content += "<br><div class=\"lds-ellipsis\">\n" +
" <div></div><div></div><div></div><div></div>\n" +
"</div>";
for (let btn of this._buttons) {
this._content += `<button class="btn btn-${btn.type}" onclick="${btn.onclick}">${btn.content}</button>`;
this._content += `<button class="btn btn-${btn.type}" onclick="(${btn.onclick})();">${btn.content}</button>`;
}
Modal.open(this._title, this._content, this._id);
if( this._leftCentered )
{
this._content+= "</div>";
}
let title = this._title;
let content = this._content;
let id = this._id;
function tryOpen()
{
if( Modal.modalInClose )
{
setTimeout( tryOpen, 50 );
return;
}
Modal.open(title, content, id );
}
tryOpen();
}
/**
@ -61,6 +92,7 @@ export class Modal {
* @param id
*/
public static open(title: string, content: string, id?: string): void {
const modal = document.getElementById("modal");
const modalContent = document.getElementById("modalInnerContent");
@ -82,9 +114,11 @@ export class Modal {
}
public static close(id?: string): void {
if (this.currentModalId != id)
if (id && this.currentModalId != id)
return;
Modal.modalInClose = true;
const modal = document.getElementById("modal");
const modalContent = document.getElementById("modal-content");
const modalInnerContent = document.getElementById("modalInnerContent");
@ -100,6 +134,9 @@ export class Modal {
modalInnerContent.innerHTML = "";
modalContent.classList.remove("modalBlendOut");
modal.classList.remove("modalBlendOut");
this.modalInClose = false;
}, 800);
this.currentModalId = undefined;
}
}