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 { NumericTextBox } from "@syncfusion/ej2-inputs"; class CreateTransactionFeeModule { private _moduleName = "CreateTransactionFeeModule"; private _component = "#transactionFeeCreateContainer"; private _global: Global; private _eventManager: EventManager; private _uiManager: Ui; private _localizationMananger: LocalizationManager; private _percentNumeric: NumericTextBox; private _fixedNumeric: NumericTextBox; 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("#frmCreateTransactionFee")).attr("action"); var data = $(self.prefix("#frmCreateTransactionFee")).serialize(); $.post(action, data) .done(result => { if (result.success) { self._uiManager.pageTitleClear(self._component); self._eventManager.unSubscribeAll(self._moduleName); self._eventManager.publish(Events.TransactionFee.createSuccess); } else { $(self._component).replaceWith(result.html); $.highlightErrors(); Utility.showErrorTab(); 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("#btnSave")).off("click").on("click", function () { FormValidation.getInstance().validateForm(self.prefix("#frmCreateTransactionFee"), () => { self.save(); }, () => { $.highlightErrors(); Utility.showErrorTab(); }); }); $(self.prefix("#btnCancel")).off("click").on("click", function () { self._uiManager.pageTitleClear(self._component); self._eventManager.unSubscribeAll(self._moduleName); self._eventManager.publish(Events.TransactionFee.createCancel); }); //#region Numeric self._percentNumeric = new NumericTextBox({ value: Globalize.parseNumber($(self.prefix("#Percent")).val()), decimals: 2, step: 1, min: 0.0, max: 100.0, format: "n2", change: (e: any) => { $(self.prefix("#Percent")).val(Globalize.formatNumber(e.value, { minimumFractionDigits: 2 })); } }); self._percentNumeric.appendTo(self.prefix("#PercentHelper")); self._fixedNumeric = new NumericTextBox({ value: Globalize.parseNumber($(self.prefix("#Fixed")).val()), decimals: 2, step: 1, min: 0.0, max: 100000.0, format: "n2", change: (e: any) => { $(self.prefix("#Fixed")).val(Globalize.formatNumber(e.value, { minimumFractionDigits: 2 })); } }); self._fixedNumeric.appendTo(self.prefix("#FixedHelper")); //#endregion //#region Switches //#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) { createTransactionFeeModule.activate(); } else { setTimeout(() => { this.init() }, 10); } } } let createTransactionFeeModule = new CreateTransactionFeeModule(); createTransactionFeeModule.init();