191 lines
6.6 KiB
TypeScript
191 lines
6.6 KiB
TypeScript
import { LocalizationSource as localizeSource} from "./Localization";
|
|
import {LocalizationManager} from "./Localization";
|
|
|
|
/**
|
|
* Stellt UI-Funktionen zur Verfügung
|
|
*/
|
|
export class Ui {
|
|
|
|
private static _instance : Ui;
|
|
|
|
private _localizer:LocalizationManager;
|
|
|
|
/**
|
|
* Callback-Funktion für den modalen Dialog
|
|
*/
|
|
private _modalDialogCallback: any = undefined;
|
|
|
|
/**
|
|
* Erstellt eine Instanz
|
|
*/
|
|
private constructor() {
|
|
this._modalDialogCallback = undefined;
|
|
this._localizer = LocalizationManager.getInstance();
|
|
this.init();
|
|
}
|
|
|
|
/**
|
|
* Instanz
|
|
*/
|
|
static getInstance(): Ui {
|
|
if (!Ui._instance) {
|
|
Ui._instance = new Ui();
|
|
}
|
|
return Ui._instance;
|
|
}
|
|
|
|
/**
|
|
* Initialisierung des Moduls
|
|
*/
|
|
private init(): void {
|
|
var self = this;
|
|
|
|
$("#modalDialogOk").on("click",
|
|
(e) => {
|
|
$("#modalDialog").ejDialog("close");
|
|
self._modalDialogCallback();
|
|
e.preventDefault();
|
|
});
|
|
|
|
$("#modalDialogCancel").on("click",
|
|
() => {
|
|
$("#modalDialog").ejDialog("close");
|
|
return false;
|
|
});
|
|
|
|
//BlockUi anpassen
|
|
$.blockUI.defaults.overlayCSS.backgroundColor = "rgba(72, 73, 77, 0.95)";
|
|
$.blockUI.defaults.css.border = "0;";
|
|
$.blockUI.defaults.css.backgroundColor = "transparent;";
|
|
$.blockUI.defaults.message = "<div class=\"spinner\"><div class=\"double-bounce1\"></div><div class=\"double-bounce2\"></div></div>";
|
|
$.blockUI.defaults.baseZ = 1000000;
|
|
//Funktion die den Klick-Handler für alle Elemente die die Klasse "blockMainUi" haben registriert
|
|
$(".blockMainUi").on("click", () => {
|
|
self.blockMainUi();
|
|
});
|
|
|
|
if (typeof toastr !== "undefined") {
|
|
//Prüfen ob toastr überhaupt geladen wurde
|
|
toastr.options.positionClass = "toast-top-center";
|
|
toastr.options.timeOut = 1500;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Zeigt eine Nachricht für den Benutzer an
|
|
* @param {string} title: Titel der Nachricht
|
|
* @param {string} message: Eigentliche Nachricht
|
|
* @param {number} type: Typ der Nachricht. 0: Info, 1: Warning, 2: Error, 3: Erfolg. Info ist default
|
|
* @param {number} timeout: Wie lange soll die Nachricht angezeigt werden (in Millisekunden)
|
|
* @param {boolean} closeButton: Soll ein Schließen-Button angezeigt werden? true für ja, false sonst
|
|
*/
|
|
showMessage(title: string, message: string, type: number, timeout: number, closeButton: boolean): void {
|
|
|
|
switch (type) {
|
|
case 0:
|
|
toastr.info(message, title, { closeButton: closeButton, timeOut: timeout });
|
|
break;
|
|
case 1:
|
|
toastr.warning(message, title, { closeButton: closeButton, timeOut: timeout });
|
|
break;
|
|
case 2:
|
|
toastr.error(message, title, { closeButton: closeButton, timeOut: timeout });
|
|
break;
|
|
case 3:
|
|
toastr.success(message, title, { closeButton: closeButton, timeOut: timeout });
|
|
break;
|
|
default:
|
|
toastr.info(message, title, { closeButton: closeButton, timeOut: timeout });
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Zeigt eine Erfolgs-Nachricht für den Benutzer an
|
|
* @param message: Eigentliche Nachricht
|
|
* @param title: Titel (Optional)
|
|
* @param timeout: Timout in Millisekunden (optional)
|
|
* @param showCloseButton: Soll ein Schließen-Button angezeigt werden (optional)
|
|
*/
|
|
showSuccessMessage(message: string, title:string = "", timeout:number = 4000, showCloseButton:boolean = false): void {
|
|
var self = this;
|
|
self.showMessage(title, message, 3, timeout, showCloseButton);
|
|
}
|
|
|
|
/**
|
|
* Zeigt eine Fehler-Nachricht für den Benutzer an
|
|
* @param message: Eigentliche Nachricht
|
|
* @param title: Titel (Optional)
|
|
* @param timeout: Timout in Millisekunden (optional)
|
|
* @param showCloseButton: Soll ein Schließen-Button angezeigt werden (optional)
|
|
*/
|
|
showErrorMessage(message: string, title: string = "", timeout: number = 4000, showCloseButton: boolean = false): void {
|
|
var self = this;
|
|
self.showMessage(title, message, 2, timeout, showCloseButton);
|
|
}
|
|
|
|
/**
|
|
* Zeigt eine Warnungs-Nachricht für den Benutzer an
|
|
* @param message: Eigentliche Nachricht
|
|
* @param title: Titel (Optional)
|
|
* @param timeout: Timout in Millisekunden (optional)
|
|
* @param showCloseButton: Soll ein Schließen-Button angezeigt werden (optional)
|
|
*/
|
|
showWarningMessage(message: string, title: string = "", timeout: number = 4000, showCloseButton: boolean = false): void {
|
|
var self = this;
|
|
self.showMessage(title, message, 1, timeout, showCloseButton);
|
|
}
|
|
|
|
/**
|
|
* Zeigt eine Info-Nachricht für den Benutzer an
|
|
* @param message: Eigentliche Nachricht
|
|
* @param title: Titel (Optional)
|
|
* @param timeout: Timout in Millisekunden (optional)
|
|
* @param showCloseButton: Soll ein Schließen-Button angezeigt werden (optional)
|
|
*/
|
|
showInfoMessage(message: string, title: string = "", timeout: number = 4000, showCloseButton: boolean = false): void {
|
|
var self = this;
|
|
self.showMessage(title, message, 0, timeout, showCloseButton);
|
|
}
|
|
|
|
/**
|
|
* UI Loading Overlay anzeigen
|
|
*/
|
|
blockMainUi(): void {
|
|
var self = this;
|
|
$(".tmloading").show();
|
|
setTimeout(() => {
|
|
self.unblockMainUi();
|
|
}, 25000);
|
|
}
|
|
|
|
/**
|
|
* UI Loading Overlay ausblenden
|
|
*/
|
|
unblockMainUi(): void {
|
|
$(".tmloading").fadeOut();
|
|
}
|
|
|
|
/**
|
|
*Anzeigen eines Modalen Dialoges
|
|
* showYesNo bestimmt ob "Ja/Nein" oder "Ok/Cancel" angezeigt wird
|
|
* @param text: Anzuzeigender Text?
|
|
* @param showYesNo: als Ja/Nein anzeigen?
|
|
* @param callback: optionaler Callback
|
|
*/
|
|
showModal(text: string, showYesNo: boolean, callback?: any) {
|
|
var self = this;
|
|
$("#modalDialogText").text(text);
|
|
|
|
if (showYesNo) {
|
|
$("#modalDialogOk").text(self._localizer.get("Button_Yes", localizeSource.All));
|
|
$("#modalDialogCancel").text(self._localizer.get("Button_No", localizeSource.All));
|
|
}
|
|
else {
|
|
$("#modalDialogOk").text(self._localizer.get("Button_Ok", localizeSource.All));
|
|
$("#modalDialogCancel").text(self._localizer.get("Button_Cancel", localizeSource.All));
|
|
}
|
|
|
|
this._modalDialogCallback = callback;
|
|
$("#modalDialog").ejDialog("open");
|
|
}
|
|
} |