function OdometerCounterStack(initialCount, overflowResets) {
|
this._counters = [];
|
|
|
|
this.add = function () {
|
this._counters.push(0);
|
return this._counters.length;
|
};
|
|
this.get = function (index_) {
|
return this._counters[index_];
|
};
|
|
this.increment = function (n) {
|
if (this._counters.length === 0) {
|
return false;// nothing to increment
|
}
|
|
if (typeof n !== 'number' || n <= 0 || Math.floor(n) !== n) {
|
n = 10;
|
}
|
|
var i;
|
var carry = 1;
|
|
// Loop from the rightmost (least significant) counter to the leftmost (most significant)
|
for (i = this._counters.length - 1; i >= 0 && carry > 0; i--) {
|
this._counters[i] += carry;
|
|
if (this._counters[i] >= n) {
|
this._counters[i] -= n;
|
carry = 1;
|
} else {
|
carry = 0; // No carry needed from this position, so stop propagating
|
}
|
}
|
|
// If after the loop, 'carry' is still 1, it means the most significant counter overflowed.
|
// We need to add a new counter at the beginning (most significant position).
|
if (carry > 0) {
|
if (overflowResets) {
|
for (i = 0; i < this._counters.length; i++) {
|
this._counters[i] = 0;
|
}
|
}
|
else {
|
this._counters.unshift(carry); // Add new counter at index 0, initialized with the carry value
|
}
|
return false;// return false since increment failed and it overflowed
|
}
|
return true; // return true since increment completed sucessfully
|
};
|
|
|
|
if (typeof initialCount !== 'number' || initialCount < 0) {
|
initialCount = 0;
|
}
|
for (var i = 0; i < initialCount; i++) {
|
this.add();
|
}
|
}
|
|
function accumulateNumbersInString(text, increaseNumericValue) {
|
// Regular expression to find all occurrences of numbers (integers or decimals)
|
// -?\d+ matches an optional minus sign followed by one or more digits.
|
// (\.\d+)? matches an optional decimal point followed by one or more digits (for decimals).
|
// The 'g' flag ensures all matches are found.
|
var numbers = text.match(/-?\d+(\.\d+)?/g);
|
|
var totalSum = 0; // Initialize sum to 0
|
|
if (numbers && numbers.length > 0) {
|
// Loop through the array of found number strings
|
// IE7 does not support Array.prototype.forEach or Array.prototype.map,
|
// so a traditional for loop is used.
|
for (var i = 0; i < numbers.length; i++) {
|
// Convert the string representation of the number to a floating-point number
|
// parseFloat is supported in IE7.
|
var numericValue = parseFloat(numbers[i]);
|
|
// Add the numeric value to the total sum
|
// Check for NaN to avoid adding invalid numbers (though regex should prevent most)
|
if (!isNaN(numericValue)) {
|
totalSum += numericValue;
|
if (increaseNumericValue) totalSum += 1;
|
}
|
}
|
}
|
|
return totalSum;
|
}
|
|
|
function ModuleConfiguratorUi(module_, kataPageId_) {
|
var _this = this;
|
var isTestPage = false;
|
|
this.dynEquipmentCache = {};
|
this.artPropByArtCache = {};
|
this.equipmentArtNumbersOnPage = [];
|
|
// this.replacePlaceholders = function(toReplaceIn, counterStack_, placeholders_) {
|
// var result = toReplaceIn;
|
// var reverseIndex = placeholders_.length - 1;
|
// for (var index = 0; index < placeholders_.length; ++index) {
|
// //replace all
|
// var toReplace = placeholders_[index];
|
// var newValue = counterStack_.get(reverseIndex);
|
// reverseIndex = (reverseIndex - 1) % placeholders_.length;// reduce or wrap around
|
|
// while (result.indexOf(toReplace) !== -1) {
|
// result = result.replace(toReplace, newValue);
|
// }
|
// }
|
// return result;
|
// };
|
|
// this.checkNameWithCounters = function (nameWithPlaceholders_, nameToCheck_, placeholders_) {
|
// if (nameWithPlaceholders_ == nameToCheck_) return true;
|
|
// if (!containsAnyStringFromArray(placeholders_, nameWithPlaceholders_)) {
|
// return false;
|
// }
|
|
// // init counter stack
|
// var counterStack = new CounterStack();
|
// for (var index = 0; index < placeholders_.length; ++index) {
|
// counterStack.addCounter();
|
// }
|
|
// var totalIncrements = accumulateNumbersInString(nameToCheck_);
|
// for (var incrementIndex = 0; incrementIndex < totalIncrements; ++incrementIndex) {
|
// counterStack.increment();
|
// }
|
|
// for (var index = 0; index < placeholders_.length; ++index) {
|
// //replace all
|
// var toReplace = placeholders_[index];
|
// var newValue = counterStack.get(index);
|
// while (nameWithPlaceholders_.indexOf(toReplace) !== -1) {
|
// nameWithPlaceholders_ = nameWithPlaceholders_.replace(toReplace, newValue);
|
// }
|
// }
|
// if (nameWithPlaceholders_ == nameToCheck_) {
|
// return true;
|
// }
|
// return false;
|
// };
|
|
this.AdjustValueToDimScaleAndDigits = function (value_) {
|
var digits = dh_dimdigits_get();
|
var scale = dh_dimscale_get();
|
return (scale * parseFloat(value_)).toFixed(digits);
|
}
|
this.removeDimScale = function (value_) {
|
var scale = 1 / dh_dimscale_get();
|
return scale * value_;
|
}
|
|
this.getText = function (id_) {
|
var txt = dh_text_info(id_);
|
if (txt.length < 1) {
|
txt = dh_text_info(id_, dh_manufacturer_get() + "-global");
|
if (txt.length < 1) {
|
txt = dh_text_global(id_);
|
}
|
}
|
if (txt !== "") {
|
return txt;
|
}
|
return id_;
|
};
|
this.parseValue = function (value_, valueParser_) {
|
var result = value_;
|
if (valueParser_ === "int") {
|
result = parseInt(value_).toFixed(0);
|
} else if (valueParser_ === "float") {
|
result = _this.AdjustValueToDimScaleAndDigits(value_);
|
}
|
return result
|
};
|
|
this.floatEqual = function (left, right, tolerance_) {
|
var tolerance = 0.01;
|
if (tolerance_) {
|
tolerance = tolerance_;
|
}
|
return Math.abs(left - right) < tolerance;
|
};
|
|
this.stopOtherEvents = function (event) {
|
if (event.preventDefault) {
|
event.preventDefault();
|
}
|
else {
|
event.returnValue = false;
|
}
|
if (event.stopPropagation) {
|
event.stopPropagation();
|
}
|
else {
|
event.cancelBubble = true;
|
}
|
};
|
this.changeValue = function (groupName_, valueName_, type_, value_) {
|
var value = value_;
|
if (type_ == "float") {
|
value = this.removeDimScale(value_);
|
}
|
|
var setData = [{
|
name: groupName_,
|
modifications: [{
|
target: valueName_,
|
type: type_,
|
value: value
|
}]
|
}];
|
window.ConfiguratorApi.SetApiData(setData);
|
_this.refresh();
|
};
|
|
this.createPlaceButtons = function (manufacturer_) {
|
var container = $('<div class="configurator-place-buttons-container"></div>');
|
if (module_.Articles) {
|
for (var index = 0; index < module_.Articles.length; ++index) {
|
var article = module_.Articles[index][0];
|
if (article) {
|
var articleText = article.artText.length > 0 ? article.artText + " " : "";
|
var placeButtonText = articleText + this.getText("webcab.PlaceObject");
|
var configPlaceButtonText = this.cfg.placeButtonText;
|
if(configPlaceButtonText && configPlaceButtonText.length > 0){
|
placeButtonText = this.getText(configPlaceButtonText);
|
}
|
|
var placeButton = $('<button class="place-object configurator-form-button">' + placeButtonText + '</button>');
|
placeButton.on("click", function () {
|
if (window.Article != undefined) {
|
var articleObject = new Article(article, ArticleType.NORMAL, _this, "", []);
|
ArticleListBuilder.insertArticle(articleObject);
|
setTimeout(function () {
|
_this.refresh();
|
}, 1000);
|
}
|
else { // fallback ie7 usecase without generic catalog. Will not work in furnplan_web... can be fixed by inclusion of relevant dependencies in html file.
|
FurnplanCommunicationService.sendCommand("DHTodo", ["0", {manu: manufacturer_, kataManu: manufacturer_, params: [article.ArtNr, "", "", ""]}]);
|
_this.refresh();
|
}
|
});
|
container.append(placeButton);
|
}
|
}
|
}
|
return container;
|
};
|
|
this.createInputLabelContainer = function (label_, labelSuffix_) {
|
var label = document.createElement("label");
|
label.className = "label";
|
label.innerHTML = label_;
|
|
var labelSuffix = document.createElement("label");
|
labelSuffix.className = "suffix-label";
|
labelSuffix.innerHTML = labelSuffix_ != undefined ? labelSuffix_ : "";
|
|
var labelContainer = document.createElement("span");
|
labelContainer.className = "label-container";
|
labelContainer.appendChild(label);
|
labelContainer.appendChild(labelSuffix);
|
|
return labelContainer;
|
};
|
|
this.createFormElementNumberInput = function (groupName_, valueName_, label_, min_, max_, value_, step_, valueParser_) {
|
var min = _this.parseValue(min_, valueParser_);
|
var max = _this.parseValue(max_, valueParser_);
|
var value = _this.parseValue(value_, valueParser_);
|
|
var minLabel = document.createElement("label");
|
minLabel.className = "label";
|
minLabel.innerHTML = min;
|
|
var minLabelSuffix = document.createElement("label");
|
minLabelSuffix.className = "min-max-label-suffix";
|
|
var minLabelContainer = document.createElement("span");
|
minLabelContainer.appendChild(minLabel);
|
minLabelContainer.appendChild(minLabelSuffix);
|
|
var maxLabel = document.createElement("label");
|
maxLabel.className = "label";
|
maxLabel.innerHTML = max;
|
|
var maxLabelSuffix = document.createElement("label");
|
maxLabelSuffix.className = "min-max-label-suffix";
|
|
var maxLabelContainer = document.createElement("span");
|
maxLabelContainer.appendChild(maxLabel);
|
maxLabelContainer.appendChild(maxLabelSuffix);
|
|
var dash = document.createElement("label");
|
dash.className = "dash-label";
|
dash.innerText = " - ";
|
|
var dashContainer = document.createElement("span");
|
dashContainer.className = "dash-label-container";
|
dashContainer.appendChild(dash);
|
|
var minMaxContainer = document.createElement("span");
|
minMaxContainer.className = "min-max-container";
|
minMaxContainer.appendChild(minLabelContainer);
|
minMaxContainer.appendChild(dashContainer);
|
minMaxContainer.appendChild(maxLabelContainer);
|
|
var labelContainer = _this.createInputLabelContainer(label_, "");
|
var labelLine = document.createElement("div");
|
labelLine.className = "label-line";
|
labelLine.appendChild(labelContainer);
|
labelLine.appendChild(minMaxContainer);
|
|
var disableIncrease = false, disableDecrease = false;
|
if (valueParser_ === "int") {
|
disableDecrease = parseInt(value) == parseInt(min_);
|
disableIncrease = parseInt(value) == parseInt(max_);
|
} else if (valueParser_ === "float") {
|
disableDecrease = _this.floatEqual(parseFloat(value), parseFloat(min_));
|
disableIncrease = _this.floatEqual(parseFloat(value), parseFloat(max_));
|
}
|
|
var increaseButton = document.createElement("button");
|
increaseButton.className = disableIncrease ? "button increase disabled" : "button increase";
|
increaseButton.innerHTML = "+";
|
increaseButton.tabIndex = "-1";
|
increaseButton.attachEvent("onfocus", function (event) {
|
_this.stopOtherEvents(event);
|
});
|
if (disableIncrease == false) {
|
increaseButton.attachEvent("onclick", function () {
|
var element = document.getElementById(inputId);
|
if (element) {
|
if (valueParser_ === "int") {
|
element.value = parseInt(element.value) + step_;
|
}
|
else if (valueParser_ === "float") {
|
element.value = parseFloat(element.value) + step_;
|
}
|
_this.changeValue(groupName_, valueName_, valueParser_, element.value);
|
}
|
});
|
}
|
var decreaseButton = document.createElement("button");
|
decreaseButton.className = disableDecrease ? "button decrease disabled" : "button decrease";
|
decreaseButton.innerHTML = "-";
|
decreaseButton.tabIndex = "-1";
|
decreaseButton.attachEvent("onfocus", function (event) {
|
_this.stopOtherEvents(event);
|
});
|
if (disableDecrease == false) {
|
decreaseButton.attachEvent("onclick", function () {
|
var element = document.getElementById(inputId);
|
if (element) {
|
element.value = parseInt(element.value) - step_;
|
_this.changeValue(groupName_, valueName_, valueParser_, element.value);
|
}
|
});
|
}
|
|
var inputId = "input-" + groupName_ + "-" + valueName_;
|
var input = document.createElement("input");
|
input.id = inputId;
|
input.className = "input";
|
input.value = value;
|
input.attachEvent("onchange", function () {
|
var element = document.getElementById(inputId);
|
if (element && element.value) {
|
element.value = element.value.replace(",", ".");
|
}
|
_this.changeValue(groupName_, valueName_, valueParser_, element.value);
|
});
|
input.attachEvent("onkeydown", function (event) {
|
if (event.keyCode === 13) {
|
_this.stopOtherEvents(event);
|
input.focus();
|
input.blur();
|
}
|
});
|
|
var inputContainer = document.createElement("div");
|
inputContainer.className = "input-container";
|
inputContainer.appendChild(input);
|
inputContainer.appendChild(increaseButton);
|
inputContainer.appendChild(decreaseButton);
|
|
var container = document.createElement("div");
|
container.className = "configurator-input-ui";
|
container.appendChild(labelLine);
|
container.appendChild(inputContainer);
|
|
return $(container);
|
};
|
this.createFormElementCheckbox = function (groupName_, valueName_, label_, state_, changeable_) {
|
var checkbox = $('<input type="checkbox" class="checkbox input">')
|
if (state_) {
|
checkbox.prop('checked', true);
|
}
|
if (changeable_ === 0) {
|
checkbox.prop('disabled', true);
|
}
|
checkbox.on("change", function () {
|
_this.changeValue(groupName_, valueName_, "int", checkbox.prop('checked'));
|
});
|
|
var container = $('<div class="configurator-input-ui"></div>');
|
var labelContainer = _this.createInputLabelContainer(label_, "");
|
container.append(checkbox);
|
container.append(labelContainer);
|
|
return $(container);
|
};
|
this.createFormElementButton = function (groupName_, valueName_, label_) {
|
var buttonElement = document.createElement("button");
|
buttonElement.className = "configurator-form-button";
|
buttonElement.innerHTML = label_;
|
buttonElement.attachEvent("onclick", function () {
|
_this.changeValue(groupName_, valueName_, "button", 1);
|
});
|
|
var container = document.createElement("div");
|
container.className = "configurator-input-ui";
|
container.appendChild(buttonElement);
|
return container;
|
};
|
|
var open = [];
|
this.createContainerToggle = function (groupData_, containerToToggle_, children_) {
|
// containerToToggle_.append($('<div style="width: 250px; overflow: scroll;">data: ' + children_.name + ': ' + children_.text + '</div>'));
|
|
if (children_.text == undefined) {
|
containerToToggle_.addClass("open");
|
containerToToggle_.addClass("no-toggle");
|
return containerToToggle_;
|
}
|
// containerToToggle_.append($('<div style="width: 100px; overflow: scroll;">data: ' + children_.text + '</div>'));
|
|
var toggleButton = $('<button class="configurator-form-button toggle-button">' + children_.text + '</button>');
|
toggleButton.on("click", function () {
|
toggleButton.toggleClass("open");
|
containerToToggle_.toggleClass("open");
|
|
if (containerToToggle_.hasClass("open")) {
|
open.push(children_.name);
|
}
|
else {
|
open.splice(open.indexOf(children_.name), 1);
|
}
|
});
|
|
if (open.indexOf(children_.name) != -1) {
|
toggleButton.addClass("open");
|
containerToToggle_.addClass("open");
|
}
|
|
var outerContainer = $('<div></div>');
|
outerContainer.append(toggleButton);
|
outerContainer.append(containerToToggle_);
|
return outerContainer;
|
}
|
this.createFormListElements = function (groupData_, elementData_, elementCfg_) {
|
var container = $('<fieldset class="listcontainer"></fieldset>');
|
|
// container.append($('<div>'+groupData_.name+'</div></br>'));
|
|
if (elementCfg_ === undefined) {
|
// container.append($('<div>no element cfg</div></br>'));
|
var valueNames = Object.keys(elementData_);
|
for (var valueIdx = 0; valueIdx < valueNames.length; valueIdx++) {
|
var valueName = valueNames[valueIdx];
|
if (valueName == "name" || valueName == "lo-owned" || valueName == "instance-ident" || valueName == "type") continue;
|
if (valueName == "order-factor" || valueName == "skip-on-get-api-data" || valueName == "owner") continue;
|
container.append(this.createElement(groupData_.name, elementData_, valueName));
|
}
|
return this.createContainerToggle(groupData_, container, elementData_);
|
}
|
// container.append($('<div>element cfg</div></br>'));
|
|
|
var valueNames = Object.keys(elementData_);
|
var placeholders = ["|>counter-0<|", "|>counter-1<|"];
|
var counterStack = new OdometerCounterStack(placeholders.length, true);
|
|
var maxIncrements = 1;
|
for (var valueIdx = 0; valueIdx < valueNames.length; valueIdx++) {
|
var valueName = valueNames[valueIdx];
|
|
var incrementsInName = accumulateNumbersInString(valueName, true);
|
if (maxIncrements < incrementsInName) {
|
maxIncrements = incrementsInName;
|
}
|
}
|
|
var continueLoop = true;
|
var adjustedCfg = [], names = [];
|
while (continueLoop) {
|
for (var cfgIndex = 0; cfgIndex < elementCfg_.length; ++cfgIndex) {
|
var cfgElement = elementCfg_[cfgIndex];
|
var adjusted = cfgElement.name;
|
for (var index = 0; index < placeholders.length; ++index) {
|
var toReplace = placeholders[index];
|
while (adjusted.indexOf(toReplace) !== -1) {
|
adjusted = adjusted.replace(toReplace, counterStack.get(index));
|
}
|
}
|
|
if (names.indexOf(adjusted) > -1) continue;//skip duplicates
|
adjustedCfg.push({
|
name: adjusted,
|
formElements: cfgElement.formElements
|
});
|
names.push(adjusted);
|
}
|
continueLoop = counterStack.increment(maxIncrements);//escape once stack overflows and all necessary elements have been created
|
}
|
// container.append($('<div>adjustedCfg: '+adjustedCfg.length+'</div></br>'));
|
// container.append($('<div style="width: 250px; overflow: scroll;">valueNames('+valueNames.length+'): '+JSON.stringify(valueNames)+'</div></br>'));
|
// for (var index = 0; index < valueNames.length; ++index) {
|
// container.append($('</br><div>- '+valueNames[index]+'!</div>'));
|
// }
|
|
for (var adjustedValueIndex = 0; adjustedValueIndex < adjustedCfg.length; adjustedValueIndex++) {
|
var adjustedCfgElement = adjustedCfg[adjustedValueIndex];
|
|
// container.append($('<div style="width: 250px; overflow: scroll;">valueNames: '+JSON.stringify(valueNames)+'</div></br>'));
|
|
if (valueNames.indexOf(adjustedCfgElement.name) > -1) {
|
// container.append($('</br><div>-appended ('+adjustedCfgElement.name+'):</div>'));
|
container.append(this.createElement(groupData_.name, elementData_, adjustedCfgElement.name, adjustedCfgElement.formElements));
|
}
|
else {
|
// container.append($('</br><div>-did not append '+adjustedCfgElement.name+'!</div>'));
|
}
|
}
|
|
return this.createContainerToggle(groupData_, container, elementData_);
|
};
|
this.createFormElementOptionSelection = function (groupName_, valueName_, label_, elementData_) {
|
var options = elementData_.options;
|
var selected = elementData_.active;
|
var additional = elementData_.additional ? elementData_.additional : {};
|
var placeholder = elementData_.placeholder;
|
var optionsTexts = elementData_["options-texts"];
|
var findOptionsText = function (option) {
|
if (optionsTexts == undefined) {
|
return "";
|
}
|
for (var index = 0; index < optionsTexts.length; ++index) {
|
var optionsText = optionsTexts[index];
|
if (optionsText.option == option) {
|
return optionsText.txt;
|
}
|
}
|
};
|
|
|
var optionSelection = $('<select>');
|
if (placeholder != undefined) {
|
if (selected.length < 1) {
|
optionSelection.append($('<option disabled value="' + placeholder + '">' + placeholder + '</option>'));
|
optionSelection.val(placeholder);
|
}
|
}
|
else if (additional["allow-empty-selection"]) {
|
optionSelection.append($('<option value="">' + _this.getText("155") + '</option>'));
|
}
|
|
for (var optionIdx = 0; optionIdx < options.length; optionIdx++) {
|
var optionName = options[optionIdx];
|
var txt = findOptionsText(optionName);
|
var txtHtml = txt.length < 1 ? _this.getText(optionName) : txt;
|
optionSelection.append($('<option value="' + optionName + '">' + txtHtml + '</option>'));
|
}
|
|
optionSelection.on("change", function () {
|
_this.changeValue(groupName_, valueName_, "string", optionSelection.val());
|
});
|
optionSelection.val(selected);
|
|
var container = $('<div class="configurator-input-ui"></div>');
|
var labelContainer = _this.createInputLabelContainer(label_, "");
|
container.append(labelContainer);
|
container.append(optionSelection);
|
return $(container);
|
};
|
|
this.createFormElementString = function (groupName_, valueName_, placeholder_, value_, changeable_) {
|
var classname = "input";
|
if (value_.length < 1) classname += " placeholder";
|
|
if (changeable_) {
|
var inputId = "input-" + groupName_ + "-" + valueName_;
|
var inputElement = $('<input type="text" id="' + inputId + '" class="' + classname + '" value="' + value_ + '">');
|
inputElement.on("change", function () {
|
var element = document.getElementById(inputId);
|
if (element && element.value) {
|
element.value = element.value.replace(",", ".");
|
}
|
_this.changeValue(groupName_, valueName_, "string", element.value);
|
});
|
inputElement.on("focus", function () {
|
document.getElementById(inputId).className = "input";
|
});
|
inputElement.on("blur", function () {
|
var el = document.getElementById(inputId);
|
if (el.value.length < 1) el.className = "input placeholder";
|
});
|
var container = $('<div class="string-input-container"></div>');
|
container.append(inputElement);
|
container.append($('<div class="string-input-container-placeholder">' + placeholder_ + '</div>'));
|
return container;
|
}
|
|
return $('<div class="string-input-container">' + placeholder_ + '</div>');
|
};
|
|
|
this.createElement = function (groupName_, groupData_, valueName_, elementCfg_) {
|
var elementData = groupData_[valueName_];
|
var elementLabel = this.getText(elementData.text || valueName_);
|
if (elementData.type === "int" || elementData.type === "float") {
|
return this.createFormElementNumberInput(groupData_.name, valueName_, elementLabel, elementData.min, elementData.max, elementData.value, 1.0, elementData.type);
|
}
|
else if (elementData.type === "button") {
|
return this.createFormElementButton(groupData_.name, valueName_, elementLabel);
|
}
|
else if (elementData.type === "list") {
|
return this.createFormListElements(groupData_, elementData, elementCfg_);
|
}
|
else if (elementData.type === "checkbox") {
|
return this.createFormElementCheckbox(groupData_.name, valueName_, elementLabel, elementData.state, elementData.changeable);
|
}
|
else if (elementData.type === "option-selection") {
|
return this.createFormElementOptionSelection(groupData_.name, valueName_, elementLabel, elementData);
|
}
|
else if (elementData.type === "string") {
|
return this.createFormElementString(groupData_.name, valueName_, elementLabel, elementData.value, elementData.changeable);
|
}
|
};
|
this.createFormElements = function (apiData_) {
|
var formContainer = $('<div class="form-container"></div>');
|
var groupNames = Object.keys(apiData_);
|
var placementButtonsPositions = apiData_["placement-buttons-positions"];
|
|
var formElementsDefinition = this.cfg.formElements;
|
if (typeof formElementsDefinition === "string")
|
{
|
formElementsDefinition = window.ConfiguratorApi.GetManufacturerConfig(kataPageId_);
|
if (formElementsDefinition == undefined)
|
{
|
return this.createFormElementsTestPage(apiData_);
|
}
|
}
|
|
|
for (var groupIdx = 0; groupIdx < groupNames.length; groupIdx++) {
|
var groupName = groupNames[groupIdx];
|
var groupData = apiData_[groupName];
|
var valueNames = Object.keys(groupData);
|
|
formElementsDefinition.forEach(function (element) {
|
for (var valueIdx = 0; valueIdx < valueNames.length; valueIdx++) {
|
var valueName = valueNames[valueIdx];
|
if (valueName == element.name) {
|
formContainer.append(_this.createElement(groupName, groupData, valueName, element.formElements));
|
}
|
}
|
});
|
|
if (placementButtonsPositions.indexOf(groupName) !== -1) {
|
//is in list
|
formContainer.append(this.createPlaceButtons(dh_manufacturer_get()));
|
}
|
}
|
|
return formContainer;
|
};
|
this.createFormElementsTestPage = function (apiData_) {
|
var formContainer = $('<div class="form-container"></div>');
|
var groupNames = Object.keys(apiData_);
|
|
for (var groupIdx = 0; groupIdx < groupNames.length; groupIdx++) {
|
var groupName = groupNames[groupIdx];
|
// var title = document.createElement("h1");
|
// title.innerText = groupName;
|
// formContainer.append(title);
|
var groupData = apiData_[groupName];
|
|
var groupContainer = $('<div class="group-container"></div>');
|
|
var valueNames = Object.keys(groupData);
|
|
for (var valueIdx = 0; valueIdx < valueNames.length; valueIdx++) {
|
var valueName = valueNames[valueIdx];
|
groupContainer.append(_this.createElement(groupName, groupData, valueName));
|
}
|
formContainer.append(groupContainer);
|
}
|
return formContainer;
|
};
|
}
|
|
ModuleConfiguratorUi.prototype.buildComponents = function (apiData_) {
|
var container = $('<div class="ui"></div>');
|
if (this.isTestPage) {
|
container.append(this.createFormElementsTestPage(apiData_));
|
}
|
else {
|
container.append(this.createFormElements(apiData_));
|
if (apiData_["placement-buttons-positions"].length < 1) {
|
container.append(this.createPlaceButtons(dh_manufacturer_get()));
|
}
|
}
|
return container;
|
};
|
|
ModuleConfiguratorUi.prototype.onUpdateUiEvent = function () {
|
var apiData = window.ConfiguratorApi.GetApiData(true, true, false);
|
var container = $("#configurator-container");
|
container.empty();
|
container.append(this.buildComponents(apiData, false));
|
};
|
|
ModuleConfiguratorUi.prototype.refresh = function () {
|
var apiData = window.ConfiguratorApi.GetApiData(false, false, false);
|
var container = $("#configurator-container");
|
container.empty();
|
container.append(this.buildComponents(apiData, false));
|
};
|
|
ModuleConfiguratorUi.prototype.build = function () {
|
var apiData = window.ConfiguratorApi.GetApiData(false, false, false);
|
|
var container = $('<div id="configurator-container" class="configurator-ui"></div>');
|
container.append(this.buildComponents(apiData, false));
|
|
var _this = this;
|
AppObj.EventManager.addEvent('55665533', function () {
|
_this.onUpdateUiEvent();
|
}, true);
|
|
var outerContainer = $('<div class="outer-configurator-ui-container"></div>');
|
outerContainer.append(container);
|
|
if (this.isTestPage) {
|
var outerContainer = $("#outer-configurator-ui-container");
|
outerContainer.append(container);
|
}
|
return outerContainer;
|
}
|