112 lines
3.4 KiB
TypeScript
112 lines
3.4 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"
|
|
|
|
|
|
class ShopProductsBannerDetailsModule {
|
|
private _moduleName = "ShopProductsBannerDetailsModule";
|
|
private _component = "#shopBannerDetailsContainer";
|
|
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}`;
|
|
}
|
|
|
|
/**
|
|
* Zum Warenkorb hinzfügen
|
|
*/
|
|
private addToCart(productId: number): void {
|
|
var self = this;
|
|
$.ajax({
|
|
url: <string>$(self.prefix("#jsAddToCartUrl")).val(),
|
|
data: <any>{ productId: productId },
|
|
dataType: "HTML",
|
|
type: "GET",
|
|
success(data) {
|
|
self._uiManager.showModule("AddBannerToCartModule", data);
|
|
},
|
|
error() {
|
|
|
|
},
|
|
complete() {
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 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.backDetails);
|
|
});
|
|
|
|
$(self.prefix("#btnAddToCart")).off("click").on("click", function() {
|
|
var productId = $(this).data("productid");
|
|
self.addToCart(productId);
|
|
});
|
|
|
|
self._eventManager.subscribe(Events.Shop.addToCartCancel, self._moduleName, function () {
|
|
self._uiManager.hideModule("AddBannerToCartModule");
|
|
});
|
|
|
|
self._eventManager.subscribe(Events.Shop.addToCartSuccess, self._moduleName, function () {
|
|
self._uiManager.hideModule("AddBannerToCartModule");
|
|
self._uiManager.pageTitleClear(self._component);
|
|
self._eventManager.unSubscribeAll(self._moduleName);
|
|
self._eventManager.publish(Events.Shop.backDetails);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 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) {
|
|
shopProductsBannerDetailsModule.activate();
|
|
} else {
|
|
setTimeout(() => { this.init(); }, 10);
|
|
}
|
|
}
|
|
}
|
|
|
|
let shopProductsBannerDetailsModule = new ShopProductsBannerDetailsModule();
|
|
shopProductsBannerDetailsModule.init(); |