before reduce optimization
This commit is contained in:
@@ -4,26 +4,29 @@ import * as I from "../types/types";
|
|||||||
import * as UI from "./ui";
|
import * as UI from "./ui";
|
||||||
import * as Events from "./events";
|
import * as Events from "./events";
|
||||||
|
|
||||||
export function addItem(inSeatObj: I.JSCSelectedSeat) {
|
type buyerType = (string | undefined)[][] | undefined;
|
||||||
const color = `#${XMLHelper.getVenuePricescalePropertyByPricescaleID("color", inSeatObj.data.seatsObj.id[0])}`;
|
type buyerTypeArr = (string | undefined)[];
|
||||||
const category = XMLHelper.getVenuePricescalePropertyByPricescaleID("desc", inSeatObj.data.seatsObj.id[0]);
|
|
||||||
const seat = config.state.layoutRows[inSeatObj.id][5];
|
|
||||||
const row = config.state.layoutRows[inSeatObj.id][4];
|
|
||||||
const sectionID = config.state.layoutRows[inSeatObj.id][3];
|
|
||||||
const sectionDesc = XMLHelper.getSectionDescBySectionID(sectionID);
|
|
||||||
const seatStr = `${sectionDesc}<br/>Reihe ${row} Platz ${seat}`;
|
|
||||||
const buyerTypes: (string | undefined)[][] | undefined = getBuyerTypesByPricescaleID(inSeatObj.data.seatsObj.id[0]);
|
|
||||||
const cartId = `cartItem-${inSeatObj.id}`;
|
|
||||||
const dropdownBuyerTypesSelector = `#${cartId} .dropdownBuyerTypes`;
|
|
||||||
|
|
||||||
appendHTML(cartId, color, category, seatStr);
|
export function addItem(inSeatObj: I.JSCSelectedSeat): void {
|
||||||
addDropdownBuyerTypesOptions(buyerTypes, dropdownBuyerTypesSelector);
|
const color: string = `#${XMLHelper.getVenuePricescalePropertyByPricescaleID("color", inSeatObj.data.seatsObj.id[0])}`;
|
||||||
|
const category: string | undefined = XMLHelper.getVenuePricescalePropertyByPricescaleID("desc", inSeatObj.data.seatsObj.id[0]);
|
||||||
|
const seat: string = config.state.layoutRows[inSeatObj.id][5];
|
||||||
|
const row: string = config.state.layoutRows[inSeatObj.id][4];
|
||||||
|
const sectionID: string = config.state.layoutRows[inSeatObj.id][3];
|
||||||
|
const sectionDesc: string | undefined = XMLHelper.getSectionDescBySectionID(sectionID);
|
||||||
|
const seatStr: string | undefined = `${sectionDesc}<br/>Reihe ${row} Platz ${seat}`;
|
||||||
|
const buyerTypes: buyerType = getBuyerTypesByPricescaleID(inSeatObj.data.seatsObj.id[0]);
|
||||||
|
const cartID: string = `cartItem-${inSeatObj.id}`;
|
||||||
|
const dropdownBuyerTypesSelector: string = `#${cartID} .dropdownBuyerTypes`;
|
||||||
|
|
||||||
|
appendHTML(cartID, color, category, seatStr);
|
||||||
|
addDropdownBuyerTypeOptions(buyerTypes, dropdownBuyerTypesSelector);
|
||||||
Events.addCartDropdownBuyerTypes(dropdownBuyerTypesSelector, inSeatObj);
|
Events.addCartDropdownBuyerTypes(dropdownBuyerTypesSelector, inSeatObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendHTML(inCartId: string, inColor: string, inCategory: string | undefined, inSeatStr: string) {
|
function appendHTML(inCartID: string, inColor: string, inCategory: string | undefined, inSeatStr: string): void {
|
||||||
jQuery("#cartItemHTML .fl-html").append(`
|
jQuery("#cartItemHTML .fl-html").append(`
|
||||||
<div class="cartItem" id="${inCartId}">
|
<div class="cartItem" id="${inCartID}">
|
||||||
<div class="cartItemColoredSquare" style="background: ${inColor};"></div>
|
<div class="cartItemColoredSquare" style="background: ${inColor};"></div>
|
||||||
<div class="cartItemCategory">${inCategory}</div>
|
<div class="cartItemCategory">${inCategory}</div>
|
||||||
<h5 class="cartItemSeat">${inSeatStr}</h5>
|
<h5 class="cartItemSeat">${inSeatStr}</h5>
|
||||||
@@ -32,26 +35,29 @@ function appendHTML(inCartId: string, inColor: string, inCategory: string | unde
|
|||||||
}
|
}
|
||||||
|
|
||||||
// todo: generalize dropdown fill options
|
// todo: generalize dropdown fill options
|
||||||
function addDropdownBuyerTypesOptions(inBuyerTypes: (string | undefined)[][] | undefined, inSelector: string) {
|
function addDropdownBuyerTypeOptions(inBuyerTypes: buyerType, inSelector: string) {
|
||||||
if (!inBuyerTypes)
|
if (!inBuyerTypes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const dropdownBuyerTypes = jQuery(inSelector).get(0);
|
const dropdownBuyerTypes: HTMLElement = jQuery(inSelector).get(0);
|
||||||
|
|
||||||
inBuyerTypes.forEach(arr => {
|
inBuyerTypes.forEach(arr => {
|
||||||
if (!arr[0])
|
if (arr[0])
|
||||||
return;
|
appendOption(dropdownBuyerTypes, arr)
|
||||||
|
|
||||||
let opt = document.createElement('option');
|
|
||||||
opt.value = arr[0];
|
|
||||||
opt.innerHTML = `${arr[2]} €${arr[1]}`;
|
|
||||||
dropdownBuyerTypes.appendChild(opt);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function appendOption(inDropdownBuyerTypes: HTMLElement, inArr: buyerTypeArr) {
|
||||||
|
let opt: HTMLOptionElement = document.createElement('option');
|
||||||
|
opt.value = <string>inArr[0];
|
||||||
|
opt.innerHTML = `${inArr[2]} €${inArr[1]}`;
|
||||||
|
inDropdownBuyerTypes.appendChild(opt);
|
||||||
|
}
|
||||||
|
|
||||||
function getBuyerTypesByPricescaleID(inPricescaleID: string) {
|
function getBuyerTypesByPricescaleID(inPricescaleID: string) {
|
||||||
const venueXML = config.state.inVenueXML!;
|
const venueXML: I.VenueXML = config.state.inVenueXML!;
|
||||||
const venuePricescaleArr = venueXML.price_structure[0].pricescale;
|
const venuePricescaleArr: I.Pricescale5[] = venueXML.price_structure[0].pricescale;
|
||||||
|
|
||||||
const buyerTypesArr = venuePricescaleArr.find(obj => {
|
const buyerTypesArr = venuePricescaleArr.find(obj => {
|
||||||
return obj.id[0] === inPricescaleID;
|
return obj.id[0] === inPricescaleID;
|
||||||
})?.buyer_type;
|
})?.buyer_type;
|
||||||
@@ -59,7 +65,7 @@ function getBuyerTypesByPricescaleID(inPricescaleID: string) {
|
|||||||
if (!buyerTypesArr)
|
if (!buyerTypesArr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const buyerTypes: (string | undefined)[][] = buyerTypesArr.map(arr => {
|
const buyerTypes: buyerType = buyerTypesArr.map(arr => {
|
||||||
const buyerTypeDesc = venueXML.venue[0].buyer_types[0].buyer_type.find(obj => {
|
const buyerTypeDesc = venueXML.venue[0].buyer_types[0].buyer_type.find(obj => {
|
||||||
return obj.id[0] === arr.id[0] ? obj.desc[0] : undefined;
|
return obj.id[0] === arr.id[0] ? obj.desc[0] : undefined;
|
||||||
})?.desc[0];
|
})?.desc[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user