var filteredValues = [];
var currentFilterBoxes = [];
var filteredProducts = [];
var filterPage = 0;
var productsPerPage = 12;
var lastProductPosition = 0;
var loadTrigger = 5000;
var configurableProducts = [];
function loadFilters() {
currentFilterBoxes = AjaxJSONSync("GET", "/UIData/filterBoxes/all");
paintFilters(currentFilterBoxes);
}
function paintFilters(filterBoxes) {
let suffix = "";
if (currentVisibility == 1)
suffix = "Small";
let flgPainted = false;
$("#filterBoxes" + suffix).empty();
$("#currentFilters" + suffix).empty();
for (i in filterBoxes) {
let filterBox = filterBoxes[i];
for (v in filterBox.values) {
let item = filterBox.values[v];
if (filteredValues.indexOf(item.value) > -1) {
let h = getFilterBoxItemHTML(item, filterBox.filterBehavior, filterBox.id);
$("#currentFilters" + suffix).append(h);
}
}
if ((filterBoxes[i].values.length > 1) || (filteredValues.length == 0)) {
let h = getFilterBoxHTML(filterBoxes[i]);
flgPainted = flgPainted || (h.trim() != "");
$("#filterBoxes" + suffix).append(h);
}
}
if ((filteredValues == undefined) || (filteredValues.length == 0)) {
document.getElementById("chooseFilter").style.display = "inline";
}
else {
document.getElementById("chooseFilter").style.display = "none";
}
extraFiltersExist = flgPainted;
if (flgPainted == false) {
document.getElementById("nomorefilter" + suffix).style.display = "block";
document.getElementById("addFilterButtonSmall").style.display = "none";
showProducts();
return;
}
else {
document.getElementById("nomorefilter" + suffix).style.display = "none";
if (document.getElementById("filterContainerSmall").style.display == "none") {
document.getElementById("addFilterButtonSmall").style.display = "inline";
}
else {
document.getElementById("addFilterButtonSmall").style.display = "none";
}
}
document.getElementById("filterBoxesSmall").scrollTop = 0;
setProductContainerHeight();
}
function setProductContainerHeight() {
let vh100 = window.innerHeight;
let suffix = "";
if (currentVisibility == 1)
suffix = "Small";
document.getElementById("contentContainer" + suffix).style.height = (vh100 - 75) + "px";
let newHeight = 0;
if (document.getElementById("currentFilter" + suffix).style.display != "none") {
newHeight = document.getElementById("currentFilter" + suffix).offsetHeight;
if (newHeight == 0)
newHeight = 45;
}
newHeight += 75;
let newTop = newHeight;
document.getElementById("productContainer" + suffix).style.height = (vh100 - newHeight) + "px";
document.getElementById("productContainer" + suffix).style.top = newTop + "px";
if (suffix == "Small") {
document.getElementById("filterContainer" + suffix).style.height = document.getElementById("productContainer" + suffix).style.height
document.getElementById("filterContainer" + suffix).style.top = document.getElementById("productContainer" + suffix).style.top;
if (document.getElementById("nomorefilterSmall").style.display != "none") {
newHeight += document.getElementById("nomorefilterSmall").offsetHeight;
}
newHeight += document.getElementById("showProducts").offsetHeight;
document.getElementById("filterBoxes" + suffix).style.height = (vh100 - newHeight - 20) + "px";
}
else {
let boxHeight = 120;
if (document.getElementById("nomorefilter").style.display != "none") {
boxHeight += document.getElementById("nomorefilter").offsetHeight;
}
document.getElementById("filterBoxes").style.height = (vh100 - boxHeight) + "px";
}
}
function setProductContainerHeightOld() {
let suffix = "";
if (currentVisibility == 1)
suffix = "Small";
let newHeight = 0;
if (document.getElementById("currentFilter" + suffix).style.display != "none") {
newHeight = document.getElementById("currentFilter" + suffix).offsetHeight;
if (newHeight == 0)
newHeight = 45;
}
newHeight += 75;
let newTop = newHeight;
document.getElementById("productContainer" + suffix).style.height = "calc(100vh - " + newHeight + "px)";
document.getElementById("productContainer" + suffix).style.top = newTop + "px";
if (suffix == "Small") {
document.getElementById("filterContainer" + suffix).style.height = document.getElementById("productContainer" + suffix).style.height
document.getElementById("filterContainer" + suffix).style.top = document.getElementById("productContainer" + suffix).style.top;
if (document.getElementById("nomorefilterSmall").style.display != "none") {
newHeight += document.getElementById("nomorefilterSmall").offsetHeight;
}
newHeight += document.getElementById("showProducts").offsetHeight;
document.getElementById("filterBoxes" + suffix).style.height = "calc(100vh - " + newHeight + "px)";;
}
else {
let boxHeight = 120;
if (document.getElementById("nomorefilter").style.display != "none") {
boxHeight += document.getElementById("nomorefilter").offsetHeight;
}
document.getElementById("filterBoxes").style.height = "calc(100vh - " + boxHeight + "px)";
}
}
function getFilterBoxItemHTML(item, filterBehavior, attributeId) {
let html = "";
if (filteredValues.indexOf(item.value) > -1) {
html += "
" + item.label;
html += "×";
html += "
";
}
else {
html += "
";
html += " ";
html += "";
html += "
";
}
return html;
}
function getUnitPrice(unitPriceInCent, strikethrough = false) {
let HTML = "";
if (strikethrough)
HTML += "";
else
HTML += "";
HTML += " " + (unitPriceInCent / 100).toFixed(2);
HTML += "";
return HTML;
}
function getProductCardHTML(product) {
console.log(product);
if (product.fileName == null)
product.fileName = "default.jpg";
let imageUrl = "/images/products/" + product.fileName;
let HTML = "";
HTML += "
";
HTML += (product.originalUnitPriceInCent > 0 ? "OUTLET" : "");
HTML += "";
HTML += "
";
HTML += "";
HTML += "";
if ((product.configuration == undefined) || (product.configuration == null) || (product.configuration == ""))
HTML += "";
else {
HTML += "";
}
HTML += "
";
HTML += "
";
if (product.priceType == 1)
HTML += "vanaf ";
HTML += getUnitPrice(product.unitPriceInCent,false);
if (product.originalUnitPriceInCent > 0) {
HTML += " " + getUnitPrice(product.originalUnitPriceInCent, true);
//let discountPercentage = Math.floor((product.unitPriceInCent - product.originalUnitPriceInCent) / (product.unitPriceInCent) * 100);
//HTML += "(" + discountPercentage + "%)";
}
HTML += "
";
HTML += "
" + product.label + "
";
HTML += "
";
HTML += " ";
return HTML;
}
function getFilterBoxHTML(filterBox) {
let visibleItemsHtml = "";
let invisibleItemsHtml = "";
for (v in filterBox.values) {
let item = filterBox.values[v];
if (filteredValues.indexOf(item.value) > -1)
continue;
itemHtml = getFilterBoxItemHTML(item, filterBox.filterBehavior, filterBox.id);
if (item.visible) {
visibleItemsHtml += itemHtml;
}
else {
invisibleItemsHtml += itemHtml;
}
}
let html = "";
if (visibleItemsHtml != "") {
html += "
" + filterBox.title + "
";
html += visibleItemsHtml;
if (invisibleItemsHtml != "") {
let moreId = "more_" + filterBox.id;
html += "