import { Global } from "../../Core/Globals" import { EventManager } from "../../Core/Events" import { Ui } from "../../Core/Ui" import * as Events from "../../Core/EventDefinitions" import { LocalizationManager } from "../../Core/Localization" import * as Utility from "../../Core/Utility"; import { FormValidation } from "../../Core/Forms" import * as Models from "../../Common/Models"; class AppUserReportShowRatingModule { private _moduleName = "AppUserReportShowRatingModule"; private _component = "#appUserReportShowRatingContainer"; private _global: Global; private _eventManager: EventManager; private _uiManager: Ui; private _localizationMananger: LocalizationManager; constructor() { this._global = Global.getInstance(); this._eventManager = EventManager.getInstance(); this._uiManager = Ui.getInstance(); this._localizationMananger = LocalizationManager.getInstance(); } /** * Stellt einen Prefix vor einen Selektor * @param selector */ private prefix(selector: string): string { const self = this; if ($(`${self._component} ${selector}`).length > 0) return `${self._component} ${selector}`; return `html ${selector}`; } /** * Update */ private update(): void { var self = appUserReportShowRatingModule; //Hier so weil Callback! let ratingId = $(self.prefix("#ratingId")).val(); let ratingInfo = $(self.prefix("#Info")).val(); self._uiManager.blockMainUi(); $.ajax({ url: $(self.prefix("#jsUpdateUrl")).val(), data: { id: ratingId, info: ratingInfo }, dataType: "JSON", type: "POST", success(result) { if (result.success) { var data = JSON.parse(result.data); var updatedDate = new Date(data.updatedAt); $(self.prefix("#fieldUpdatedAt")).text(Globalize.formatDate(updatedDate, { skeleton: "yyyyMMddHHmmss" })); $(self.prefix("#fieldDeleted")).text(data.deleted); } else { self._uiManager.showErrorMessage(result.errorMessage); } }, error() { }, complete() { self._uiManager.unblockMainUi(); } }); } /** * Löschen */ private delete(): void { var self = appUserReportShowRatingModule; //Hier so weil Callback! let ratingId = $(self.prefix("#ratingId")).val(); self._uiManager.blockMainUi(); $.ajax({ url: $(self.prefix("#jsDeleteUrl")).val(), data: { ratingId: ratingId }, dataType: "JSON", type: "POST", success(result) { if (result.success) { var data = JSON.parse(result.data); var updatedDate = new Date(data.updatedAt); $(self.prefix("#fieldUpdatedAt")).text(Globalize.formatDate(updatedDate, { skeleton: "yyyyMMddHHmmss" })); $(self.prefix("#fieldDeleted")).text(data.deleted); $(self.prefix("#btnSave")).hide(); $(self.prefix("#btnDelete")).hide(); } else { self._uiManager.showErrorMessage(result.errorMessage); } }, error() { }, complete() { self._uiManager.unblockMainUi(); } }); } /** * Bindungen erstellen */ private setupBindings(): void { var self = this; $(self.prefix("#btnClose")).off("click").on("click", function () { self._uiManager.pageTitleClear(self._component); self._eventManager.unSubscribeAll(self._moduleName); self._eventManager.publish(Events.AppUserReport.showCancel); }); $(self.prefix("#btnSave")).off("click").on("click", function () { self._uiManager.showModal("Möchten Sie den Text des Ratings wirklich ändern?", true, self.update); }); $(self.prefix("#btnDelete")).off("click").on("click", function () { self._uiManager.showModal("Möchten Sie dieses Rating wirklich auf gelöscht setzen?", true, self.delete); }); //#region Events //#endregion $('[data-toggle="tooltip"]').tooltip(); } /** * Aktivieren des Moduls */ public activate(): void { var self = this; $.setupValidator(); $.reinitializeValidator(); this.setupBindings(); self._uiManager.pageTitleAdd(self._component, self.prefix("#pageTitleAdd")); $.randomAutocompleteValue(); } /** * Initialisieren des Moduls */ public init(): void { if (this._global.appInitialized) { appUserReportShowRatingModule.activate(); } else { setTimeout(() => { this.init() }, 10); } } } let appUserReportShowRatingModule = new AppUserReportShowRatingModule(); appUserReportShowRatingModule.init();