PageSourceSearch

https://www.knoenerullmann.de/_ui/addons/b2bacceleratoraddon/responsive/common/js/acc.orderform.js

js knoenerullmann.de collected 2026-10-07 04:34:47 UTC 20,528 bytes, 428 lines download raw bytes

1var ACC = ACC || {}; // make sure ACC is available
2
3if ($("#orderFormContainer").length > 0) {
4    ACC.orderform = {
5        _autoload: [
6            "bindAll"
7        ],
8
9        $selectedProductIdsContainer: $("#js-selected-product-ids"),
10        $productIdsInput: $("#js-product-ids"),
11        $enableProductIdsCheckBox: $("#js-enable-product-ids"),
12        $productIdTagBoxTemplate: $("#product-id-tag-box-template"),
13        $removeProductIdButton: $(".js-remove-product-id"),
14        $advSearchButton: $(".adv_search_button"),
15        $orderFormToggle: $(".js-show-order-form-grid-wrapper"),
16        $searchCurrentLabel: $(".searchInput label"),
17        $createOrderFormButton: $(".js-create-order-form-button"),
18        $createOrderFormCheckbox: $(".js-checkbox-sku-id, .js-checkbox-base-product"),
19        $baseProductCheckBox: $(".js-checkbox-base-product"),
20        $skuIDCheckbox: $(".js-checkbox-sku-id"),
21        $skuQuantityOrderInput: $(".sku-quantity"),
22        $addToCartBtn: $('#js-add-to-cart-order-form-btn-top, #js-add-to-cart-order-form-btn-bottom'),
23        $orderForm:$("#isCreateOrderForm"),
24        $userQtyInputSelection: $("input[data-product-selection]"),
25        $totalPrice : $('.js-total-price'),
26        $totalItemsCount : $('.js-total-items-count'),
27        $totalPriceValue: $('.js-total-price-value'),
28        $advancedSearchForm: $('#advancedSearchForm'),
29
30        /*
31         * Register all the event handlers.
32         */
33        bindAll: function () {
34            ACC.orderform.bindToToggleProductIds(ACC.orderform.$enableProductIdsCheckBox);
35            ACC.orderform.bindToRemoveProductId(ACC.orderform.$removeProductIdButton);
36            ACC.orderform.bindToAdvSearchButton(ACC.orderform.$advSearchButton);
37            ACC.orderform.bindOrderFormToggle(ACC.orderform.$orderFormToggle);
38            ACC.orderform.bindToCreateOrderFormButton(ACC.orderform.$createOrderFormButton);
39            ACC.orderform.bindToBaseProductCheckBox(ACC.orderform.$baseProductCheckBox);
40            ACC.orderform.bindToSkuIDCheckBox(ACC.orderform.$skuIDCheckbox);
41            ACC.orderform.bindAddToCartClick(ACC.orderform.$addToCartBtn);
42
43            if (ACC.orderform.$enableProductIdsCheckBox.prop("checked")) {
44                ACC.orderform.replaceSearchLabel(true);
45                ACC.orderform.appendProductIdsForSearch();
46            }
47
48            if ($("#search-create-order-form").prop("checked")) {
49                ACC.orderform.makeUserSelectionAfterPagination();
50                ACC.orderform.setStateOrderFormButton();
51            } else {
52                ACC.orderform.fillQuantityValueForPagination(ACC.orderform.$userQtyInputSelection);
53            }
54
55            ACC.orderform.$advancedSearchForm.find("input[name='CSRFToken']").remove();
56        },
57
58        bindOrderFormToggle: function(orderFormToggle) {
59            orderFormToggle.click(function (event) {
60                var $this = $(this);
61                $(this).toggleClass('open');
62                var orderFormGridWrapper = $(this).parents('.js-item-list-item').next('.js-order-form-grid-wrapper');
63                orderFormGridWrapper.slideToggle("slow", function() {
64                    if(!$this.data('calc')) {
65                        var scrollingContent = orderFormGridWrapper.children('#cartOrderGridForm').addClass('visible');
66                        ACC.productorderform.coreTableScrollActions(scrollingContent);
67                        $this.data('calc',true);
68                    }
69                });
70            });
71        },
72
73        bindToAdvSearchButton: function (advSearchButton) {
74            advSearchButton.click(function (event) {
75                if (ACC.orderform.$enableProductIdsCheckBox.prop("checked")) {
76                    //Append the new product id's to search in sku only mode!
77                    if (ACC.orderform.$productIdsInput.val() != "") {
78                        ACC.orderform.appendProductIdsForSearch();
79                    }
80                    ACC.orderform.$productIdsInput.val(ACC.orderform.getProductsIdsFromSessionStorage());
81                }
82                ACC.orderform.stripOutInvalidChars();
83                if (ACC.orderform.$orderForm.val()) {
84                    sessionStorage.clear();
85                } else {
86                    ACC.orderform.cleanupQtyInputFromSessionStorage();
87                }
88            });
89        },
90
91        bindToCreateOrderFormButton: function (createOrderFormButton) {
92            createOrderFormButton.click(function (event) {
93                ACC.orderform.stripOutInvalidChars();
94                ACC.orderform.$productIdsInput.val(ACC.orderform.getProductsIdsFromSessionStorage());
95                ACC.orderform.$orderForm.val(true);
96                sessionStorage.removeItem("checkedProducts");
97                ACC.orderform.$selectedProductIdsContainer.empty();
98                ACC.orderform.$enableProductIdsCheckBox.attr("checked", false);
99                ACC.orderform.$advSearchButton.click();
100            });
101        },
102
103        bindToBaseProductCheckBox: function (baseProductCheckBox) {
104            baseProductCheckBox.click(function (event) {
105                var baseProduct = this;
106                $(ACC.orderform.$skuIDCheckbox).each(function () {
107                    if ($(this).attr("base-product-code") && $(this).attr("base-product-code") == baseProduct.value) {
108                        $(this).prop("checked", baseProduct.checked);
109                        ACC.orderform.addProductIdsToSessionStorage(this);
110                    }
111                })
112            });
113        },
114
115        bindToSkuIDCheckBox: function (skuIDCheckbox) {
116            skuIDCheckbox.click(function (event) {
117                ACC.orderform.addProductIdsToSessionStorage(this);
118            });
119        },
120
121
122        addToSkuQtyInput: function (_this) {
123            // if there are no items to add, disable addToCartBtn, otherwise, enable it
124            if (ACC.orderform.$totalItemsCount.length != 0 && ACC.orderform.$totalItemsCount.text() == 0) {
125                ACC.orderform.$addToCartBtn.attr('disabled', 'disabled');
126            } else {
127                ACC.orderform.$addToCartBtn.removeAttr('disabled');
128            }
129            var qtyInputs = ACC.orderform.fetchOrPopulateSessionStorageObj("qtyInputs");
130            var qtyInputJson = JSON.parse($(_this).attr("data-product-selection"));
131            var filteredObjects = ACC.orderform.filterMatchingQtyInputs(qtyInput
131s, qtyInputJson);
132            for (var i = 0; i < filteredObjects.length; i++) {
133                qtyInputs.splice(qtyInputs.indexOf(filteredObjects[i]), 1);
134            }
135            qtyInputJson['qty'] = _this.value;
136            qtyInputs.push(qtyInputJson);
137            sessionStorage.setItem("qtyInputs", JSON.stringify(qtyInputs));
138
139            ACC.orderform.setTotalItemPrice($(_this), _this.value, $(_this).siblings('.price').data('variant-price'));
140        },
141
142        setStateOrderFormButton: function () {
143            ACC.orderform.$createOrderFormButton.attr('disabled', 'disabled');
144            var checkedProducts = ACC.orderform.getProductsIdsFromSessionStorage();
145
146            if(checkedProducts.length > 0){
147                ACC.orderform.$createOrderFormButton.removeAttr("disabled");
148            }
149            else {
150                ACC.orderform.$createOrderFormButton.attr('disabled', 'disabled');
151            }
152        },
153
154        addProductIdsToSessionStorage: function (checkbox) {
155            var clickedProductIds = JSON.parse(sessionStorage.getItem("checkedProducts"));
156            if (clickedProductIds == null || clickedProductIds == undefined) {
157                sessionStorage.setItem("checkedProducts", JSON.stringify([]))
158                clickedProductIds = new Array();
159            }
160
161            var ifProductExist = clickedProductIds.indexOf(checkbox.value);
162
163            if (checkbox.checked) {
164                if (ifProductExist == -1)
165                    clickedProductIds.push(checkbox.value);
166            } else {
167                if (ifProductExist != -1)
168                    clickedProductIds.splice(ifProductExist, 1);
169            }
170            sessionStorage.setItem("checkedProducts", JSON.stringify(clickedProductIds));
171            ACC.orderform.setStateOrderFormButton();
172        },
173
174        fetchOrPopulateSessionStorageObj: function (item) {
175            var storageObj = JSON.parse(sessionStorage.getItem(item));
176            if (storageObj == null || storageObj == undefined) {
177                sessionStorage.setItem(item, JSON.stringify([]))
178                storageObj = new Array();
179            }
180            return storageObj
181        },
182
183        makeUserSelectionAfterPagination: function () {
184            var clickedProductIds = JSON.parse(sessionStorage.getItem("checkedProducts"));
185            if (clickedProductIds != null) {
186                $(ACC.orderform.$skuIDCheckbox).each(function () {
187                    if (clickedProductIds.indexOf(this.value) != -1)
188                        $(this).prop("checked", true);
189                })
190            }
191        },
192
193        fillQuantityValueForPagination: function (userQtyInputSelection) {
194            var qtyInputs = JSON.parse(sessionStorage.getItem("qtyInputs"));
195            var prevParentId, prevVariantLoop, parentTable = {};
196            if (qtyInputs != null && qtyInputs.length > 0) {
197                userQtyInputSelection.each(function (obj) {
198                    var filteredObjects = ACC.orderform.filterMatchingQtyInputs(qtyInput
198s, JSON.parse($(this).attr('data-product-selection')));
199                    if (filteredObjects != null && filteredObjects.length > 0) {
200                        var qty = filteredObjects[0].qty;
201                        var resetSummary = false;
202                        $(this).attr('value', qty);
203                        if (this.hasAttribute('data-variant-id')) {
204
205                            if(prevVariantLoop === $(this).parents('table').data('variant-loop')){
206                                resetSummary = true;
207                            }
208
209                            ACC.productorderform.calculateVariantTotal($(this), qty);
210                            if(prevParentId === $(this).data('parent-id') && prevVariantLoop === $(this).parents('table').data('variant-loop')){
211                                ACC.productorderform.updateSelectedVariantGridTotal(this,0,false, resetSummary);
212                            }
213                            else {
214                                ACC.productorderform.updateSelectedVariantGridTotal(this,0,true, resetSummary);
215                            }
216                            prevParentId = $(this).data('parent-id');
217                            parentTable = $(this).parents('table');
218                            prevVariantLoop = parentTable.data('variant-loop');
219                        }
220                    }
221                });
222                ACC.orderform.$addToCartBtn.removeAttr("disabled");
223            }
224            ACC.orderform.resetPriceCounters();
225        },
226
227        getProductsIdsFromSessionStorage: function () {
228            var clickedProductIds = ACC.orderform.fetchOrPopulateSessionStorageObj("checkedProducts");
229            if (clickedProductIds != null && clickedProductIds != "") {
230                return clickedProductIds.join(",");
231            }
232            return [];
233        },
234
235        removeProductIdFromSessionStorage: function (productId) {
236            var clickedProductIds = JSON.parse(sessionStorage.getItem("checkedProducts"));
237            var ifProductExist = clickedProductIds.indexOf(productId);
238            if (ifProductExist != -1) {
239                clickedProductIds.splice(ifProductExist, 1);
240            }
241            sessionStorage.setItem("checkedProducts", JSON.stringify(clickedProductIds));
242        },
243
244        // Add product ids search enable checkbox handler
245        bindToToggleProductIds: function (addProductIdsCheckBox) {
246            addProductIdsCheckBox.on("change", function (event) {
247                var checked = $(this).prop("checked");
248                ACC.orderform.replaceSearchLabel(checked);
249                // move the added product id tags back into the input
250                var joinedProductIds = $.map(
251                    ACC.orderform.$selectedProductIdsContainer.find(".product-id-tag-box .product-id"),
252                    function (index) {
253                        return $(index).text()
254                    }
255                ).join(", ");
256                if (joinedProductIds !== "") {
257                    ACC.orderform.$productIdsInput.val(joinedProductIds);
258                }
259                // clear product id tags
260                ACC.orderform.$selectedProductIdsContainer.empty();
261            });
262        },
263
264        // Add product id event handler
265        appendProductIdsForSearch: function () {
266            ACC.orderform.stripOutInvalidChars();
267            var productIds = ACC.orderform.$productIdsInput.val().split(",");
268            //  clean product ids
269            productIds = $.map(productIds, function (productId, index) {
270                return ($.trim(productId));
271            });
272            productIds = $.unique(productIds);
273            var presentProductIds = ACC.orderform.fetchOrPopulateSessionStorageObj("checkedProducts");
274
275            // create the tags by using a template
276            $.each(productIds, function (index, productId) {
277                var $existingProductId = ACC.orderform.$selectedProductIdsContainer.find("#product-id-" + productId);
278                if (productId !== '' && $existingProductId.length == 0) {
279                    // Render the product id tag boxes using the template
280                    ACC.orderform.$productIdTagBoxTemplate
281                        .tmpl({productId: productId, index: index})
282                        .appendTo(ACC.orderform.$selectedProductIdsContainer);
283                }
284                if (presentProductIds.indexOf(productId) == -1) {
285                    presentProductIds.push(productId);
286                }
287            });
288            sessionStorage.setItem("checkedProducts", JSON.stringify(presentProductIds));
289            // clear the input field
290            ACC.orderform.$productIdsInput.val('');
291            ACC.orderform.$productIdsInput.focus();
292        },
293
294
295        bindAddToCartClick: function (addToCartBtn) {
296            addToCartBtn.click(function () {
297                $.ajax({
298                    url: ACC.productorderform.$addToCartOrderForm.attr("action"),
299                    type: 'POST',
300                    dataType: 'json',
301                    contentType: 'application/json',
302                    data: ACC.orderform.getJSONDataForAddToCart(),
303                    async: false,
304                    success: function (response) {
305                        $(window).off('beforeunload', ACC.productorderform.beforeUnloadHandler);
306                        ACC.product.displayAddToCartPopup(response);
307                        ACC.orderform.cleanUserQtySelection(ACC.orderform.$userQtyInputSelection);
308                    },
309                    error: function (jqXHR, textStatus, errorThrown) {
310                        // log the error to the console
311                        console.log("The following error occured: " + textStatus, errorThrown);
312                    }
313                });
314            });
315        },
316
317        getJSONDataForAddToCart: function () {
318            var qtyInputs = ACC.orderform.fetchOrPopulateSessionStorageObj("qtyInputs");
319            var skusAsJSON = [];
320            for (var i = 0; i < qtyInputs.length; i++) {
321                if (parseInt(qtyInputs[i].qty) > 0) {
322                    skusAsJSON.push({"product": {"code": qtyInputs[i].product}, "quantity": qtyInputs[i].qty});
323                }
324            }
325            return JSON.stringify({"cartEntries": skusAsJSON});
326        },
327
328
329        bindToRemoveProductId: function (removeProductIdButton) {
330            ACC.orderform.$selectedProductIdsContainer.on("click", removeProductIdButton, function (event) {
331                event.preventDefault();
332                var valueToRemove = $(event.target).parents('.js-remove-product-id');
333                ACC.orderform.removeProductIdFromSessionStorage($(valueToRemove).children('.product-id').text());
334                $(valueToRemove).remove();
335
336                ACC.orderform.$selectedProductIdsContainer.empty();
337                ACC.orderform.$enableProductIdsCheckBox.attr("checked", true);
338                ACC.orderform.$productIdsInput.val(ACC.orderform.getProductsIdsFromSessionStorage());
339                ACC.orderform.$advSearchButton.click();
340            });
341        },
342
343        cleanUserQtySelection: function (userQtyInputSelection) {
344            var qtyInputs = ACC.orderform.fetchOrPopulateSessionStorageObj("qtyInputs");
345            if (qtyInputs != null && qtyInputs.length > 0) {
346                userQtyInputSelection.each(function () {
347                    $(this).prop('value', 0);
348                    ACC.orderform.$addToCartBtn.attr('disabled', 'disabled');
349                    ACC.orderform.setTotalItemPrice($(this), 0, 0);
350
351                })
352            }
353            ACC.productorderform.cleanValues();
354            ACC.productorderform.resetSelectedVariant();
355            ACC.orderform.$totalPrice.html(ACC.productorderform.formatTotalsCurrency('0.00'));
356            ACC.orderform.$totalItemsCount.text('0');
357            ACC.orderform.$totalPriceValue.val(0);
358            ACC.orderform.cleanupQtyInputFromSessionStorage();
359        },
360
361        replaceSearchLabel: function (productIdsChecked) {
362        	var currentLabelHtml = ACC.orderform.$searchCurrentLabel.html();
363        	var searchByIdsLabelHtml = ACC.common.encodeHtml($("#searchByIdsLabel").val());
364        	var searchByKeywordLabelHtml  = ACC.common.encodeHtml($("#searchByKeywordLabel").val());
365        	 
366        	if (productIdsChecked) {
367        		currentLabelHtml = currentLabelHtml.replace(searchByKeywordLabelHtml, searchByIdsLabelHtml);
368        	} else {
369        		currentLabelHtml = currentLabelHtml.replace(searchByIdsLabelHtml, searchByKeywordLabelHtml);
370        	}
371        	ACC.orderform.$searchCurrentLabel.html(currentLabelHtml);
372        },
373
374        stripOutInvalidChars: function () {
375            ACC.orderform.$productIdsInput.val(ACC.orderform.$productIdsInput.val().replace(/[^a-z0-9 ,.\-_]/ig, ''));
376        },
377
378        cleanupQtyInputFromSessionStorage: function () {
379            sessionStorage.removeItem("qtyInputs");
380            sessionStorage.removeItem("totalPrice");
381            sessionStorage.removeItem("totalPriceVal");
382            sessionStorage.removeItem("totalItems");
383        },
384
385        resetPriceCounters: function () {
386            ACC.orderform.$totalItemsCount.text(sessionStorage.totalItems);
387            if (sessionStorage.totalPrice !== undefined) {
388            	ACC.orderform.$totalPrice.html((ACC.sanitizer.sanitize(sessionStorage.totalPrice)));
389            } else {
390            	ACC.orderform.$totalPrice.html(ACC.productorderform.formatTotalsCurrency('0.00'));
391            }
392            ACC.orderform.$totalPriceValue.val(sessionStorage.totalPriceVal || 0);
393
394            //sub-total
395            ACC.orderform.fillTotalItemPrice();
396        },
397
398        setTotalItemPrice: function (item, quantity, price) {
399            if(!item.data('variant-id')) {
400                var htmlContent = (quantity > 0) ? ACC.productorderform.formatTotalsCurrency(price * quantity) : '';
401                item.parent().next('.item__total').text(htmlContent);
402            }
403        },
404
405        fillTotalItemPrice: function () {
406            if (sessionStorage.qtyInputs !== undefined){
407                var qtyInputsJson = JSON.parse(sessionStorage.qtyInputs);
408                var $product = {};
409
410                for (var i = 0; i < qtyInputsJson.length; i++) {
411                    if (qtyInputsJson[i].qty > 0) {
412                        $product = $('.' + qtyInputsJson[i].product);
413                        var totalPrice = ACC.productorderform.formatTotalsCurrency($product.siblings('.price').data('variant-price') *  qtyInputsJson[i].qty);
414                        $product.parent().siblings('.item__total').text(totalPrice);
415                    }
416                }
417            }
418        },
419
420        filterMatchingQtyInputs: function (qtyInputs, dataValueObj) {
421            var filteredObjects = $.grep(qtyInputs, function (obj) {
422                return dataValueObj.product == obj.product;
423            });
424            return filteredObjects;
425        }
426    };
427}
428

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.