225 lines
6.1 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 ShopShowCartModule {
private _moduleName = "ShopShowCartModule";
private _component = "#cartContainer";
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}`;
}
/**
* Übersicht anzeigen
*/
private overview(): void {
var self = this;
//self._uiManager.blockMainUi();
$.ajax({
url: <string>$(self.prefix("#jsCartOverviewUrl")).val(),
data: <any>{ },
dataType: "HTML",
type: "GET",
success(data) {
$(self.prefix("#cartDetail")).html(data);
$(self.prefix("#cartDetail")).show();
},
error() {
},
complete() {
//self._uiManager.unblockMainUi();
}
});
}
/**
* Adresse anzeigen
*/
private address(): void {
var self = this;
//self._uiManager.blockMainUi();
$.ajax({
url: <string>$(self.prefix("#jsCheckoutAddressUrl")).val(),
data: <any>{ },
dataType: "HTML",
type: "GET",
success(data) {
$(self.prefix("#cartDetail")).html(data);
$(self.prefix("#cartDetail")).show();
},
error() {
},
complete() {
//self._uiManager.unblockMainUi();
}
});
}
/**
* Zahlungsmethoden anzeigen
*/
private payment(): void {
var self = this;
//self._uiManager.blockMainUi();
$.ajax({
url: <string>$(self.prefix("#jsCheckoutPaymentUrl")).val(),
data: <any>{ },
dataType: "HTML",
type: "GET",
success(data) {
$(self.prefix("#cartDetail")).html(data);
$(self.prefix("#cartDetail")).show();
},
error() {
},
complete() {
//self._uiManager.unblockMainUi();
}
});
}
/**
* zusammnefassung der Bestellung anzeigen
*/
private order(): void {
var self = this;
//self._uiManager.blockMainUi();
$.ajax({
url: <string>$(self.prefix("#jsCheckoutOrderUrl")).val(),
data: <any>{ },
dataType: "HTML",
type: "GET",
success(data) {
$(self.prefix("#cartDetail")).html(data);
$(self.prefix("#cartDetail")).show();
},
error() {
},
complete() {
//self._uiManager.unblockMainUi();
}
});
}
/**
* Bestätigung anzeigen
*/
private confirmation(): void {
var self = this;
//self._uiManager.blockMainUi();
$.ajax({
url: <string>$(self.prefix("#jsCheckoutConfirmationUrl")).val(),
data: <any>{ },
dataType: "HTML",
type: "GET",
success(data) {
$(self.prefix("#cartDetail")).html(data);
$(self.prefix("#cartDetail")).show();
},
error() {
},
complete() {
//self._uiManager.unblockMainUi();
}
});
}
/**
* Bindungen erstellen
*/
private setupBindings(): void {
var self = this;
self._eventManager.subscribe(Events.Shop.showOverview, self._moduleName, function () {
$(self.prefix("#cartDetail")).fadeOut("slow", () => {
self.overview();
});
});
self._eventManager.subscribe(Events.Shop.showAddress, self._moduleName, function () {
$(self.prefix("#cartDetail")).fadeOut("slow", () => {
self.address();
});
});
self._eventManager.subscribe(Events.Shop.showPayment, self._moduleName, function () {
$(self.prefix("#cartDetail")).fadeOut("slow", () => {
self.payment();
});
});
self._eventManager.subscribe(Events.Shop.showOrder, self._moduleName, function () {
$(self.prefix("#cartDetail")).fadeOut("slow", () => {
self.order();
});
});
self._eventManager.subscribe(Events.Shop.showConfirmation, self._moduleName, function () {
$(self.prefix("#cartDetail")).fadeOut("slow", () => {
self.confirmation();
});
});
}
/**
* Aktivieren des Moduls
*/
public activate(): void {
var self = this;
$.setupValidator();
$.reinitializeValidator();
this.setupBindings();
if ($(self.prefix("#jsShowConfirmation")).val().toString().toLowerCase() === "false") {
self.overview();
} else {
self.confirmation();
}
//self._uiManager.pageTitleAdd(self._component, self.prefix("#pageTitleAdd"));
$.randomAutocompleteValue();
}
/**
* Initialisieren des Moduls
*/
public init(): void {
if (this._global.appInitialized) {
shopShowCartModule.activate();
} else {
setTimeout(() => { this.init(); }, 10);
}
}
}
let shopShowCartModule = new ShopShowCartModule();
shopShowCartModule.init();