dh_ackergaul
vor 3 Tagen bb80cdf5a6157ca1f3a276e12e9faae9a4739cb7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
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;
}