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 { FormValidation } from "../../Core/Forms"; import * as Utility from "../../Core/Utility"; class ShopCheckoutPaymentModule { private _moduleName = "ShopCheckoutPaymentModule"; private _component = "#checkoutPaymentContainer"; private _global: Global; private _eventManager: EventManager; private _uiManager: Ui; private _localizationMananger: LocalizationManager; private _data: any; 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("#frmCheckoutPayment")).attr("action"); var data = $(self.prefix("#frmCheckoutPayment")).serialize(); $.post(action, data) .done(result => { if (result.success) { self._uiManager.pageTitleClear(self._component); self._eventManager.unSubscribeAll(self._moduleName); self._eventManager.publish(Events.Shop.showOrder); } else { $(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("#btnBack")).off("click").on("click", function() { self._uiManager.pageTitleClear(self._component); self._eventManager.unSubscribeAll(self._moduleName); self._eventManager.publish(Events.Shop.showAddress); }); $(self.prefix("#btnNext")).off("click").on("click", function() { FormValidation.getInstance().validateForm(self.prefix("#frmCheckoutPayment"), () => { self.save(); }, () => { $.highlightErrors(); Utility.showErrorTab(); }); }); $(self.prefix(".checkout-radio")).off("change").on("change", function() { $(self.prefix("#PaymentType")).val($(this).val()); }); $('[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) { shopCheckoutPaymentModule.activate(); } else { setTimeout(() => { this.init(); }, 10); } } } let shopCheckoutPaymentModule = new ShopCheckoutPaymentModule(); shopCheckoutPaymentModule.init();