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 Localization from "../../Core/Localization"; import * as Forms from "../../Core/Forms"; import FormValidation = Forms.FormValidation; class SetPasswordModule { private _moduleName = "SetPasswordModule"; private _component = "#setPasswordContainer"; 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}`; } /** * Speichern */ private save(): void { var self = this; self._uiManager.blockMainUi(); var action = $(self.prefix("#frmSetPassword")).attr("action"); var data = $(self.prefix("#frmSetPassword")).serialize(); $.post(action, data) .done(result => { if (result.success) { self._uiManager.showSuccessMessage(self._localizationMananger.get("Password_Set_Success")); $(self.prefix("#frmSetPassword")).trigger("reset"); } else { self._uiManager.showErrorMessage(self._localizationMananger.get("Password_Set_NoSuccess")); $(self._component).replaceWith(result.html); $.highlightErrors(); self.activate(); } }) .fail(result => { self._uiManager.showErrorMessage(self._localizationMananger.get("Common_Save_NoSuccess")); }) .always(result => { self._uiManager.unblockMainUi(); }); } /** * Bindungen erstellen */ private setupBindings(): void { var self = this; $(self.prefix("#btnSetPassword")).off("click").on("click", function () { FormValidation.getInstance().validateForm(self.prefix("#frmSetPassword"), () => { self.save(); }, () => { $.highlightErrors(); }); }); } /** * Aktivieren des Moduls */ public activate(): void { var self = this; $.setupValidator(); $.reinitializeValidator(); this.setupBindings(); $.randomAutocompleteValue(); } /** * Initialisieren des Moduls */ public init(): void { if (this._global.appInitialized) { setPasswordModule.activate(); } else { setTimeout(() => { this.init() }, 10); } } } let setPasswordModule = new SetPasswordModule(); setPasswordModule.init();