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 { Switch } from '@syncfusion/ej2-buttons'; import * as Models from "../../Common/Models"; class EditShopSettingsModule { private _moduleName = "EditShopSettingsModule"; private _component = "#shopSettingsEditContainer"; 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("#frmEditShopSettings")).attr("action"); var data = $(self.prefix("#frmEditShopSettings")).serialize(); $.post(action, data) .done(result => { if (result.success) { self._uiManager.showSuccessMessage(self._localizationMananger.get("Common_Save_Success")); } 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("#frmEditShopSettings"), () => { self.save(); }, () => { $.highlightErrors(); Utility.showErrorTab(); }); }); let paymentOnInvoice = new Switch( { checked: $(self.prefix("#PaymentOnInvoice")).prop("checked") } ); paymentOnInvoice.appendTo("#PaymentOnInvoice"); let payPalEnabled = new Switch( { checked: $(self.prefix("#PayPalEnabled")).prop("checked") } ); payPalEnabled.appendTo("#PayPalEnabled"); let klarnaEnabled = new Switch( { checked: $(self.prefix("#KlarnaEnabled")).prop("checked") } ); klarnaEnabled.appendTo("#KlarnaEnabled"); $('[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) { editShopSettingsModule.activate(); } else { setTimeout(() => { this.init() }, 10); } } } let editShopSettingsModule = new EditShopSettingsModule(); editShopSettingsModule.init();