outsourced inject and seatmap to modules
This commit is contained in:
@@ -6,8 +6,8 @@ import * as Communication from "./modules/communication";
|
|||||||
import * as Parser from './modules/parser';
|
import * as Parser from './modules/parser';
|
||||||
import * as UI from "./modules/ui";
|
import * as UI from "./modules/ui";
|
||||||
import { config } from "./modules/config";
|
import { config } from "./modules/config";
|
||||||
import axios from 'axios';
|
|
||||||
import * as BookingBtn from "./modules/bookingButton";
|
import * as BookingBtn from "./modules/bookingButton";
|
||||||
|
import * as Parent from "./modules/parent";
|
||||||
|
|
||||||
let inputsWithValue: I.InputsWithValue;
|
let inputsWithValue: I.InputsWithValue;
|
||||||
|
|
||||||
@@ -62,95 +62,42 @@ function messageHandler(e: any) {
|
|||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
||||||
switch (data.event) {
|
switch (data.event) {
|
||||||
|
|
||||||
case "child_init_needInputsWithValue": {
|
case "child_init_needInputsWithValue": {
|
||||||
const message: I.Message = {
|
Parent.initNeedInputsWithValue(inputsWithValue);
|
||||||
message: inputsWithValue,
|
|
||||||
from: "parent",
|
|
||||||
event: "parent_init_sendInputsWithValue",
|
|
||||||
date: Date.now()
|
|
||||||
};
|
|
||||||
Communication.sendMessage(message, "iframeSeatmap");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "child_init_needVenueXML": {
|
case "child_init_needVenueXML": {
|
||||||
Communication.sendXML(inputsWithValue["posturl"], "iframeSeatmap", "parent_init_sendVenueXML", "parent");
|
Parent.initNeedVenueXML(inputsWithValue);
|
||||||
config.childHasVenueXML = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "child_needSeatmapXML": {
|
case "child_needSeatmapXML": {
|
||||||
const seatmapUrl: string = `${inputsWithValue["posturlRawDecoded"]}&inclseatmap=Y&seatmap=${data.message}`;
|
Parent.needSeatmapXML(e, inputsWithValue);
|
||||||
Communication.sendXML(seatmapUrl, "iframeSeatmap", "parent_sendSeatmapXML", "parent");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "child_seatmap_ready": {
|
case "child_seatmap_ready": {
|
||||||
jQuery("#containerBookingBtn").show();
|
jQuery("#containerBookingBtn").show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "child_needCheckoutResponse": {
|
case "child_needCheckoutResponse": {
|
||||||
const inUrl: string = data.message.url;
|
Parent.needCheckoutResponse(e, inputsWithValue);
|
||||||
|
|
||||||
axios.get(inUrl, {
|
|
||||||
maxRedirects: 0
|
|
||||||
})
|
|
||||||
.then((inE) => {
|
|
||||||
let isValidSeatSelection: boolean = false;
|
|
||||||
const content: string = inE.data;
|
|
||||||
const parsedHTML: Node[] = jQuery.parseHTML(content);
|
|
||||||
const orderkey: string | undefined = jQuery(parsedHTML).find("#orderkey").val();
|
|
||||||
|
|
||||||
console.log(`orderkey: ${orderkey}`);
|
|
||||||
|
|
||||||
if (orderkey) {
|
|
||||||
isValidSeatSelection = true;
|
|
||||||
const cancelUrl = `${inputsWithValue["ticketPurchaseUrl"]}?user_context=${inputsWithValue["user_context"]}&pid=${inputsWithValue["pid"]}&orderkey=${orderkey}&trxstate=92`;
|
|
||||||
Communication.cancelCheckout(cancelUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
const message: I.Message = {
|
|
||||||
message: {
|
|
||||||
"isValidSeatSelection": isValidSeatSelection,
|
|
||||||
"parsedHTML": parsedHTML,
|
|
||||||
"url": inUrl,
|
|
||||||
},
|
|
||||||
from: "parent",
|
|
||||||
event: "parent_sendCheckoutResponse",
|
|
||||||
date: Date.now()
|
|
||||||
};
|
|
||||||
Communication.sendMessage(message, "iframeSeatmap");
|
|
||||||
})
|
|
||||||
.catch(function (error) {
|
|
||||||
console.log("error in child_needCheckoutResponse");
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "child_hide_dialog_titlebar": {
|
case "child_hide_dialog_titlebar": {
|
||||||
jQuery(".ui-dialog-titlebar").hide();
|
jQuery(".ui-dialog-titlebar").hide();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "child_show_dialog_titlebar": {
|
case "child_show_dialog_titlebar": {
|
||||||
jQuery(".ui-dialog-titlebar").show();
|
jQuery(".ui-dialog-titlebar").show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "child_click_checkout": {
|
case "child_click_checkout": {
|
||||||
const inUrl: string = data.message.url;
|
Parent.clickCheckout(e);
|
||||||
window.location.href = inUrl;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "child_closeDialog": {
|
case "child_closeDialog": {
|
||||||
jQuery(".ui-dialog-titlebar-close").click();
|
jQuery(".ui-dialog-titlebar-close").click();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
97
client/src/modules/child.ts
Normal file
97
client/src/modules/child.ts
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
import * as Communication from "./communication";
|
||||||
|
import * as UI from "./ui";
|
||||||
|
import { config } from "./config";
|
||||||
|
import Utils from "./utils";
|
||||||
|
import * as Parser from './parser';
|
||||||
|
import * as I from "../types/types";
|
||||||
|
import * as JSC from "./jsc";
|
||||||
|
import * as Legend from "./legend";
|
||||||
|
import * as Events from "./events";
|
||||||
|
import * as Trims from "./trims";
|
||||||
|
import * as XMLHelper from "./xmlhelper";
|
||||||
|
import * as Panzoom from "./panzoom";
|
||||||
|
import * as jBoxHelper from "./jBoxHelper";
|
||||||
|
import * as Cart from "./cart";
|
||||||
|
import * as CartButtons from "./cartButtons";
|
||||||
|
|
||||||
|
export function initVenue() {
|
||||||
|
UI.controlLoftloader("show");
|
||||||
|
Communication.sendEventToParent("child_init_needInputsWithValue");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initSendVenueXML(inE: any) {
|
||||||
|
const data: I.Message = JSON.parse(inE.data);
|
||||||
|
config.state.inVenueXML = data.message.map_response;
|
||||||
|
const venueXML = config.state.inVenueXML!;
|
||||||
|
|
||||||
|
// Generate pricescale css classes
|
||||||
|
const css = UI.generatePricescaleCSS();
|
||||||
|
Utils.inject(css, "cssCustom", "body");
|
||||||
|
|
||||||
|
// Fill event info
|
||||||
|
const eventInfo = Parser.getEventInfo();
|
||||||
|
UI.setEventInfo(eventInfo);
|
||||||
|
|
||||||
|
// Fill select dropdown
|
||||||
|
const seatmapListing: I.Seatmap[] = venueXML.seatmap_config[0].seatmap;
|
||||||
|
UI.setOptionSelect(seatmapListing, "dropdownSeatmap");
|
||||||
|
|
||||||
|
// Display first seatmapXML
|
||||||
|
const id: string = seatmapListing[0].id[0];
|
||||||
|
jQuery("#dropdownSeatmap").val(id);
|
||||||
|
Communication.needSeatmapXML(id);
|
||||||
|
|
||||||
|
console.log(css);
|
||||||
|
console.log(seatmapListing);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initSendInputsWithValue(inE: any) {
|
||||||
|
const data: I.Message = JSON.parse(inE.data);
|
||||||
|
config.state.inputsWithValue = data.message;
|
||||||
|
UI.changeVenueImage();
|
||||||
|
Communication.sendEventToParent("child_init_needVenueXML");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function sendSeatmapXML(inE: any) {
|
||||||
|
const data: I.Message = JSON.parse(inE.data);
|
||||||
|
config.state.seatmapXML = data.message.map_response;
|
||||||
|
const map: string[] = JSC.generateMap();
|
||||||
|
const rowsNaming: string[] = JSC.getRowsNaming();
|
||||||
|
const seats: I.JSCSeats = JSC.getSeats();
|
||||||
|
const legend: I.JSCLegend = JSC.generateLegend("#JSCLegendInner");
|
||||||
|
|
||||||
|
JSC.addSeatmap("#containerSeatmapInner", map, rowsNaming, seats, legend);
|
||||||
|
JSC.setUnavailableSeats();
|
||||||
|
JSC.selectSeatsInCart();
|
||||||
|
Legend.convertLegendToDropdown("dropdownLegend");
|
||||||
|
Events.dropdownLegendOnChange("#dropdownLegend");
|
||||||
|
Trims.addTrims();
|
||||||
|
XMLHelper.processSMAP();
|
||||||
|
config.state.panzoom = Panzoom.addPanzoom("#containerSeatmapInner", ".panzoomZoomIn", ".panzoomZoomOut", "#panzoomResetZoom");
|
||||||
|
UI.controlLoftloader("hide");
|
||||||
|
jBoxHelper.createSeatTooltips();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sendCheckoutResponse(inE: any) {
|
||||||
|
const data: I.Message = JSON.parse(inE.data);
|
||||||
|
config.state.isValidSeatSelection = data.message.isValidSeatSelection;
|
||||||
|
|
||||||
|
console.log(data.message);
|
||||||
|
|
||||||
|
if (!config.state.isValidSeatSelection) {
|
||||||
|
jBoxHelper.showJBoxNotice(`Auswahl nicht möglich: Bitte lassen Sie keinen einzelnen Platz frei.`);
|
||||||
|
CartButtons.showHideBtnCartLoading("hide");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Cart.removeCartItems();
|
||||||
|
Cart.generateCartItems();
|
||||||
|
const url = Cart.generateCheckoutUrl();
|
||||||
|
Events.addRedirectCheckout(url);
|
||||||
|
UI.fadeInCartModal();
|
||||||
|
CartButtons.showHideBtnCartLoading("hide");
|
||||||
|
}
|
||||||
|
|
||||||
|
config.state.cartChanged = false;
|
||||||
|
}
|
||||||
@@ -35,9 +35,9 @@ export function sendXML(inUrl: string, inTo: string, inEvent: string, inFrom: st
|
|||||||
}
|
}
|
||||||
sendMessage(message, inTo);
|
sendMessage(message, inTo);
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendEventToChild(inEvent: string): void {
|
export function sendEventToChild(inEvent: string): void {
|
||||||
@@ -76,11 +76,11 @@ export function cancelCheckout(inUrl: string): void {
|
|||||||
fetch(inUrl, {
|
fetch(inUrl, {
|
||||||
redirect: "manual"
|
redirect: "manual"
|
||||||
})
|
})
|
||||||
.then(() => console.log(`${inUrl} canceled`))
|
.then(() => console.log(`${inUrl} canceled`))
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
console.log("error");
|
console.log("error");
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isValidSeatSelection(): void {
|
export function isValidSeatSelection(): void {
|
||||||
@@ -113,11 +113,11 @@ function getXMLPromise(inUrl: string): Promise<unknown> {
|
|||||||
xml2jsParser(AxiosResponse.data,
|
xml2jsParser(AxiosResponse.data,
|
||||||
{ normalizeTags: true, normalize: true, mergeAttrs: true },
|
{ normalizeTags: true, normalize: true, mergeAttrs: true },
|
||||||
(err: any, result: any) => {
|
(err: any, result: any) => {
|
||||||
if (err)
|
if (err)
|
||||||
reject(err);
|
reject(err);
|
||||||
else
|
else
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|||||||
71
client/src/modules/parent.ts
Normal file
71
client/src/modules/parent.ts
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import { config } from "./config";
|
||||||
|
import axios from 'axios';
|
||||||
|
import * as Communication from "./communication";
|
||||||
|
import * as I from "../types/types";
|
||||||
|
|
||||||
|
export function needCheckoutResponse(inE: any, inInputsWithValue: I.InputsWithValue) {
|
||||||
|
const data: I.Message = JSON.parse(inE.data);
|
||||||
|
const inUrl: string = data.message.url;
|
||||||
|
|
||||||
|
axios.get(inUrl, {
|
||||||
|
maxRedirects: 0
|
||||||
|
})
|
||||||
|
.then((inE) => {
|
||||||
|
type orderkey = string | number | string[] | undefined;
|
||||||
|
let isValidSeatSelection: boolean = false;
|
||||||
|
const content: string = inE.data;
|
||||||
|
const parsedHTML: Node[] = jQuery.parseHTML(content);
|
||||||
|
const orderkey: orderkey = jQuery(parsedHTML).find("#orderkey").val();
|
||||||
|
|
||||||
|
console.log(`orderkey: ${orderkey}`);
|
||||||
|
|
||||||
|
if (orderkey) {
|
||||||
|
isValidSeatSelection = true;
|
||||||
|
const cancelUrl = `${inInputsWithValue["ticketPurchaseUrl"]}?user_context=${inInputsWithValue["user_context"]}&pid=${inInputsWithValue["pid"]}&orderkey=${orderkey}&trxstate=92`;
|
||||||
|
Communication.cancelCheckout(cancelUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
const message: I.Message = {
|
||||||
|
message: {
|
||||||
|
"isValidSeatSelection": isValidSeatSelection,
|
||||||
|
"parsedHTML": parsedHTML,
|
||||||
|
"url": inUrl,
|
||||||
|
},
|
||||||
|
from: "parent",
|
||||||
|
event: "parent_sendCheckoutResponse",
|
||||||
|
date: Date.now()
|
||||||
|
};
|
||||||
|
Communication.sendMessage(message, "iframeSeatmap");
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log("error in child_needCheckoutResponse");
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initNeedInputsWithValue(inInputsWithValue: I.InputsWithValue) {
|
||||||
|
const message: I.Message = {
|
||||||
|
message: inInputsWithValue,
|
||||||
|
from: "parent",
|
||||||
|
event: "parent_init_sendInputsWithValue",
|
||||||
|
date: Date.now()
|
||||||
|
};
|
||||||
|
Communication.sendMessage(message, "iframeSeatmap");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initNeedVenueXML(inInputsWithValue: I.InputsWithValue) {
|
||||||
|
Communication.sendXML(inInputsWithValue["posturl"], "iframeSeatmap", "parent_init_sendVenueXML", "parent");
|
||||||
|
config.childHasVenueXML = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function needSeatmapXML(inE: any, inInputsWithValue: I.InputsWithValue) {
|
||||||
|
const data: I.Message = JSON.parse(inE.data);
|
||||||
|
const seatmapUrl: string = `${inInputsWithValue["posturlRawDecoded"]}&inclseatmap=Y&seatmap=${data.message}`;
|
||||||
|
Communication.sendXML(seatmapUrl, "iframeSeatmap", "parent_sendSeatmapXML", "parent");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clickCheckout(inE: any) {
|
||||||
|
const data: I.Message = JSON.parse(inE.data);
|
||||||
|
const inUrl: string = data.message.url;
|
||||||
|
window.location.href = inUrl;
|
||||||
|
}
|
||||||
@@ -1,21 +1,13 @@
|
|||||||
import jQuery = require("jquery");
|
import jQuery = require("jquery");
|
||||||
import * as XMLHelper from "./modules/xmlhelper";
|
|
||||||
import * as Communication from "./modules/communication";
|
import * as Communication from "./modules/communication";
|
||||||
import * as I from "./types/types";
|
import * as I from "./types/types";
|
||||||
import * as UI from "./modules/ui";
|
|
||||||
import * as JSC from "./modules/jsc";
|
|
||||||
import { config } from "./modules/config";
|
import { config } from "./modules/config";
|
||||||
import Utils from "./modules/utils";
|
import Utils from "./modules/utils";
|
||||||
import * as Events from "./modules/events";
|
import * as Events from "./modules/events";
|
||||||
require("jbox/dist/jBox.all.css");
|
require("jbox/dist/jBox.all.css");
|
||||||
import * as Cart from "./modules/cart";
|
import * as Cart from "./modules/cart";
|
||||||
import * as Trims from "./modules/trims";
|
|
||||||
import * as Legend from "./modules/legend";
|
|
||||||
import * as BookingBtn from "./modules/bookingButton";
|
import * as BookingBtn from "./modules/bookingButton";
|
||||||
import * as Panzoom from "./modules/panzoom";
|
import * as Child from './modules/child';
|
||||||
import * as CartButtons from "./modules/cartButtons";
|
|
||||||
import * as jBoxHelper from "./modules/jBoxHelper";
|
|
||||||
import * as Parser from './modules/parser';
|
|
||||||
|
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
// Inject JSC (jQuery Seat Charts)
|
// Inject JSC (jQuery Seat Charts)
|
||||||
@@ -68,90 +60,26 @@ function messageHandler(inE: any) {
|
|||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
||||||
switch (data.event) {
|
switch (data.event) {
|
||||||
|
|
||||||
case "parent_init_venue": {
|
case "parent_init_venue": {
|
||||||
UI.controlLoftloader("show");
|
Child.initVenue();
|
||||||
Communication.sendEventToParent("child_init_needInputsWithValue");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "parent_init_sendVenueXML": {
|
case "parent_init_sendVenueXML": {
|
||||||
config.state.inVenueXML = data.message.map_response;
|
Child.initSendVenueXML(inE);
|
||||||
const venueXML = config.state.inVenueXML!;
|
|
||||||
|
|
||||||
// Generate pricescale css classes
|
|
||||||
const css = UI.generatePricescaleCSS();
|
|
||||||
Utils.inject(css, "cssCustom", "body");
|
|
||||||
|
|
||||||
// Fill event info
|
|
||||||
const eventInfo = Parser.getEventInfo();
|
|
||||||
UI.setEventInfo(eventInfo);
|
|
||||||
|
|
||||||
// Fill select dropdown
|
|
||||||
const seatmapListing: I.Seatmap[] = venueXML.seatmap_config[0].seatmap;
|
|
||||||
UI.setOptionSelect(seatmapListing, "dropdownSeatmap");
|
|
||||||
|
|
||||||
// Display first seatmapXML
|
|
||||||
const id: string = seatmapListing[0].id[0];
|
|
||||||
jQuery("#dropdownSeatmap").val(id);
|
|
||||||
Communication.needSeatmapXML(id);
|
|
||||||
|
|
||||||
console.log(css);
|
|
||||||
console.log(seatmapListing);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "parent_init_sendInputsWithValue": {
|
case "parent_init_sendInputsWithValue": {
|
||||||
config.state.inputsWithValue = data.message;
|
Child.initSendInputsWithValue(inE);
|
||||||
UI.changeVenueImage();
|
|
||||||
Communication.sendEventToParent("child_init_needVenueXML");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "parent_sendSeatmapXML": {
|
case "parent_sendSeatmapXML": {
|
||||||
config.state.seatmapXML = data.message.map_response;
|
Child.sendSeatmapXML(inE);
|
||||||
const map: string[] = JSC.generateMap();
|
|
||||||
const rowsNaming: string[] = JSC.getRowsNaming();
|
|
||||||
const seats: I.JSCSeats = JSC.getSeats();
|
|
||||||
const legend: I.JSCLegend = JSC.generateLegend("#JSCLegendInner");
|
|
||||||
|
|
||||||
JSC.addSeatmap("#containerSeatmapInner", map, rowsNaming, seats, legend);
|
|
||||||
JSC.setUnavailableSeats();
|
|
||||||
JSC.selectSeatsInCart();
|
|
||||||
Legend.convertLegendToDropdown("dropdownLegend");
|
|
||||||
Events.dropdownLegendOnChange("#dropdownLegend");
|
|
||||||
Trims.addTrims();
|
|
||||||
XMLHelper.processSMAP();
|
|
||||||
config.state.panzoom = Panzoom.addPanzoom("#containerSeatmapInner", ".panzoomZoomIn", ".panzoomZoomOut", "#panzoomResetZoom");
|
|
||||||
UI.controlLoftloader("hide");
|
|
||||||
jBoxHelper.createSeatTooltips();
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "parent_sendCheckoutResponse": {
|
||||||
case "parent_sendCheckoutResponse": {
|
Child.sendCheckoutResponse(inE);
|
||||||
config.state.isValidSeatSelection = data.message.isValidSeatSelection;
|
|
||||||
|
|
||||||
console.log(data.message);
|
|
||||||
|
|
||||||
if (!config.state.isValidSeatSelection) {
|
|
||||||
jBoxHelper.showJBoxNotice(`Auswahl nicht möglich: Bitte lassen Sie keinen einzelnen Platz frei.`);
|
|
||||||
CartButtons.showHideBtnCartLoading("hide");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Cart.removeCartItems();
|
|
||||||
Cart.generateCartItems();
|
|
||||||
const url = Cart.generateCheckoutUrl();
|
|
||||||
Events.addRedirectCheckout(url);
|
|
||||||
UI.fadeInCartModal();
|
|
||||||
CartButtons.showHideBtnCartLoading("hide");
|
|
||||||
}
|
|
||||||
|
|
||||||
config.state.cartChanged = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user