106 lines
3.2 KiB
TypeScript
106 lines
3.2 KiB
TypeScript
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 Forms from "../../Core/Forms";
|
|
import FormValidation = Forms.FormValidation;
|
|
|
|
|
|
class ChangePasswordModule {
|
|
private _moduleName = "ChangePasswordModule";
|
|
private _component = "#changePasswordContainer";
|
|
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("#frmChangePassword")).attr("action");
|
|
var data = $(self.prefix("#frmChangePassword")).serialize();
|
|
$.post(action, data)
|
|
.done(result => {
|
|
if (result.success) {
|
|
self._uiManager.showSuccessMessage(self._localizationMananger.get("Password_Change_Success"));
|
|
$(self.prefix("#frmChangePassword")).trigger("reset");
|
|
}
|
|
else {
|
|
self._uiManager.showErrorMessage(self._localizationMananger.get("Password_Change_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("#btnChangePassword")).off("click").on("click", function () {
|
|
FormValidation.getInstance().validateForm(self.prefix("#frmChangePassword"), () => {
|
|
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) {
|
|
changePasswordModule.activate();
|
|
} else {
|
|
setTimeout(() => { this.init(); }, 10);
|
|
}
|
|
}
|
|
}
|
|
|
|
let changePasswordModule = new ChangePasswordModule();
|
|
changePasswordModule.init(); |