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 { Tab } from "@syncfusion/ej2-navigations"; import * as Utility from "../../Core/Utility"; import { FormValidation } from "../../Core/Forms" import * as Models from "../../Common/Models"; import { Switch } from '@syncfusion/ej2-buttons'; import { NumericTextBox } from "@syncfusion/ej2-inputs"; import AppUser = Events.AppUser; class EditProfileAppUserModule { private _moduleName = "EditProfileAppUserModule"; private _component = "#appUserProfileContainer"; 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("#frmProfileAppUser")).attr("action"); var data = $(self.prefix("#frmProfileAppUser")).serialize(); $.post(action, data) .done(result => { if (result.success) { self._uiManager.pageTitleClear(self._component); self._eventManager.unSubscribeAll(self._moduleName); self._eventManager.publish(AppUser.profileSuccess, result.data); } 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("#frmProfileAppUser"), () => { 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(AppUser.profileCancel); }); //#region switches let puppyAllowed = new Switch( { checked: $(self.prefix("#PuppyAllowed")).prop("checked") } ); puppyAllowed.appendTo("#PuppyAllowed"); let difficultAllowed = new Switch( { checked: $(self.prefix("#DifficultAllowed")).prop("checked") } ); difficultAllowed.appendTo("#DifficultAllowed"); let notAvailable = new Switch( { checked: $(self.prefix("#NotAvailable")).prop("checked") } ); notAvailable.appendTo("#NotAvailable"); //#endregion let radius = new NumericTextBox({ value: Globalize.parseNumber($(self.prefix("#Radius")).val()), decimals: 2, step: 1, min: 0, max: 100, format: "n2", change: (e: any) => { $(self.prefix("#Radius")).val(Globalize.formatNumber(e.value, { minimumFractionDigits: 2 })); } }); radius.appendTo(self.prefix("#RadiusHelper")); //#region Prices let priceWalk = new NumericTextBox({ value: Globalize.parseNumber($(self.prefix("#PriceWalk")).val()), decimals: 2, step: 1, min: 0, max: 1000000, format: "n2", change: (e: any) => { $(self.prefix("#PriceWalk")).val(Globalize.formatNumber(e.value, { minimumFractionDigits: 2 })); } }); priceWalk.appendTo(self.prefix("#PriceWalkHelper")); let priceDay = new NumericTextBox({ value: Globalize.parseNumber($(self.prefix("#PriceDay")).val()), decimals: 2, step: 1, min: 0, max: 1000000, format: "n2", change: (e: any) => { $(self.prefix("#PriceDay")).val(Globalize.formatNumber(e.value, { minimumFractionDigits: 2 })); } }); priceDay.appendTo(self.prefix("#PriceDayHelper")); let priceSitting = new NumericTextBox({ value: Globalize.parseNumber($(self.prefix("#PriceSitting")).val()), decimals: 2, step: 1, min: 0, max: 1000000, format: "n2", change: (e: any) => { $(self.prefix("#PriceSitting")).val(Globalize.formatNumber(e.value, { minimumFractionDigits: 2 })); } }); priceSitting.appendTo(self.prefix("#PriceSittingHelper")); //#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) { editProfileAppUserModule.activate(); } else { setTimeout(() => { this.init() }, 10); } } } let editProfileAppUserModule = new EditProfileAppUserModule(); editProfileAppUserModule.init();