PageSourceSearch

https://www.kaosalonpartner.no/_ui/addons/salonacceleratoraddon/responsive/common/js/acc.orderform.js

js kaosalonpartner.no collected 2026-10-08 23:30:31 UTC 20,365 bytes, 425 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 > span'),
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            console.log(sessionStorage.getItem("checkedProducts"));
172            ACC.orderform.setStateOrderFormButton();
173        },
174
175        fetchOrPopulateSessionStorageObj: function (item) {
176            var storageObj = JSON.parse(sessionStorage.getItem(item));
177            if (storageObj == null || storageObj == undefined) {
178                sessionStorage.setItem(item, JSON.stringify([]))
179                storageObj = new Array();
180            }
181            return storageObj
182        },
183
184        makeUserSelectionAfterPagination: function () {
185            var clickedProductIds = JSON.parse(sessionStorage.getItem("checkedProducts"));
186            if (clickedProductIds != null) {
187                $(ACC.orderform.$skuIDCheckbox).each(function () {
188                    if (clickedProductIds.indexOf(this.value) != -1)
189                        $(this).prop("checked", true);
190                })
191            }
192        },
193
194        fillQuantityValueForPagination: function (userQtyInputSelection) {
195            var qtyInputs = JSON.parse(sessionStorage.getItem("qtyInputs"));
196            var prevParentId, prevVariantLoop, parentTable = {};
197            if (qtyInputs != null && qtyInputs.length > 0) {
198                userQtyInputSelection.each(function (obj) {
199                    var filteredObjects = ACC.orderform.filterMatchingQtyInputs(qtyInput
199s, JSON.parse($(this).attr('data-product-selection')));
200                    if (filteredObjects != null && filteredObjects.length > 0) {
201                        var qty = filteredObjects[0].qty;
202                        var resetSummary = false;
203                        $(this).attr('value', qty);
204                        if (this.hasAttribute('data-variant-id')) {
205
206                            if(prevVariantLoop === $(this).parents('table').data('variant-loop')){
207                                resetSummary = true;
208                            }
209
210                            ACC.productorderform.calculateVariantTotal($(this), qty);
211                            if(prevParentId === $(this).data('parent-id') && prevVariantLoop === $(this).parents('table').data('variant-loop')){
212                                ACC.productorderform.updateSelectedVariantGridTotal(this,0,false, resetSummary);
213                            }
214                            else {
215                                ACC.productorderform.updateSelectedVariantGridTotal(this,0,true, resetSummary);
216                            }
217                            prevParentId = $(this).data('parent-id');
218                            parentTable = $(this).parents('table');
219                            prevVariantLoop = parentTable.data('variant-loop');
220                        }
221                    }
222                });
223                ACC.orderform.$addToCartBtn.removeAttr("disabled");
224            }
225            ACC.orderform.resetPriceCounters();
226        },
227
228        getProductsIdsFromSessionStorage: function () {
229            var clickedProductIds = ACC.orderform.fetchOrPopulateSessionStorageObj("checkedProducts");
230            if (clickedProductIds != null && clickedProductIds != "") {
231                return clickedProductIds.join(",");
232            }
233            return [];
234        },
235
236        removeProductIdFromSessionStorage: function (productId) {
237            var clickedProductIds = JSON.parse(sessionStorage.getItem("checkedProducts"));
238            var ifProductExist = clickedProductIds.indexOf(productId);
239            if (ifProductExist != -1) {
240                clickedProductIds.splice(ifProductExist, 1);
241            }
242            sessionStorage.setItem("checkedProducts", JSON.stringify(clickedProductIds));
243        },
244
245        // Add product ids search enable checkbox handler
246        bindToToggleProductIds: function (addProductIdsCheckBox) {
247            addProductIdsCheckBox.on("change", function (event) {
248                var checked = $(this).prop("checked");
249                ACC.orderform.replaceSearchLabel(checked);
250                // move the added product id tags back into the input
251                var joinedProductIds = $.map(
252                    ACC.orderform.$selectedProductIdsContainer.find(".product-id-tag-box .product-id"),
253                    function (index) {
254                        return $(index).text()
255                    }
256                ).join(", ");
257                if (joinedProductIds !== "") {
258                    ACC.orderform.$productIdsInput.val(joinedProductIds);
259                }
260                // clear product id tags
261                ACC.orderform.$selectedProductIdsContainer.empty();
262            });
263        },
264
265        // Add product id event handler
266        appendProductIdsForSearch: function () {
267            ACC.orderform.stripOutInvalidChars();
268            var productIds = ACC.orderform.$productIdsInput.val().split(",");
269            //  clean product ids
270            productIds = $.map(productIds, function (productId, index) {
271                return ($.trim(productId));
272            });
273            productIds = $.unique(productIds);
274            var presentProductIds = ACC.orderform.fetchOrPopulateSessionStorageObj("checkedProducts");
275
276            // create the tags by using a template
277            $.each(productIds, function (index, productId) {
278                var $existingProductId = ACC.orderform.$selectedProductIdsContainer.find("#product-id-" + productId);
279                if (productId !== '' && $existingProductId.length == 0) {
280                    // Render the product id tag boxes using the template
281                    ACC.orderform.$productIdTagBoxTemplate
282                        .tmpl({productId: productId, index: index})
283                        .appendTo(ACC.orderform.$selectedProductIdsContainer);
284                }
285                if (presentProductIds.indexOf(productId) == -1) {
286                    presentProductIds.push(productId);
287                }
288            });
289            sessionStorage.setItem("checkedProducts", JSON.stringify(presentProductIds));
290            // clear the input field
291            ACC.orderform.$productIdsInput.val('');
292            ACC.orderform.$productIdsInput.focus();
293        },
294
295
296        bindAddToCartClick: function (addToCartBtn) {
297            addToCartBtn.click(function () {
298                $.ajax({
299                    url: ACC.productorderform.$addToCartOrderForm.attr("action"),
300                    type: 'POST',
301                    dataType: 'json',
302                    contentType: 'application/json',
303                    data: ACC.orderform.getJSONDataForAddToCart(),
304                    async: false,
305                    success: function (response) {
306                        $(window).off('beforeunload', ACC.productorderform.beforeUnloadHandler);
307                        ACC.product.displayAddToCartPopup(response);
308                        ACC.orderform.cleanUserQtySelection(ACC.orderform.$userQtyInputSelection);
309                    },
310                    error: function (jqXHR, textStatus, errorThrown) {
311                        // log the error to the console
312                        console.log("The following error occured: " + textStatus, errorThrown);
313                    }
314                });
315            });
316        },
317
318        getJSONDataForAddToCart: function () {
319            var qtyInputs = ACC.orderform.fetchOrPopulateSessionStorageObj("qtyInputs");
320            var skusAsJSON = [];
321            for (var i = 0; i < qtyInputs.length; i++) {
322                if (parseInt(qtyInputs[i].qty) > 0) {
323                    skusAsJSON.push({"product": {"code": qtyInputs[i].product}, "quantity": qtyInputs[i].qty});
324                }
325            }
326            return JSON.stringify({"cartEntries": skusAsJSON});
327        },
328
329
330        bindToRemoveProductId: function (removeProductIdButton) {
331            ACC.orderform.$selectedProductIdsContainer.on("click", removeProductIdButton, function (event) {
332                event.preventDefault();
333                var valueToRemove = $(event.target).parents('.js-remove-product-id');
334                ACC.orderform.removeProductIdFromSessionStorage($(valueToRemove).children('.product-id').text());
335                $(valueToRemove).remove();
336
337                ACC.orderform.$selectedProductIdsContainer.empty();
338                ACC.orderform.$enableProductIdsCheckBox.attr("checked", true);
339                ACC.orderform.$productIdsInput.val(ACC.orderform.getProductsIdsFromSessionStorage());
340                ACC.orderform.$advSearchButton.click();
341            });
342        },
343
344        cleanUserQtySelection: function (userQtyInputSelection) {
345            var qtyInputs = ACC.orderform.fetchOrPopulateSessionStorageObj("qtyInputs");
346            if (qtyInputs != null && qtyInputs.length > 0) {
347                userQtyInputSelection.each(function () {
348                    $(this).prop('value', 0);
349                    ACC.orderform.$addToCartBtn.attr('disabled', 'disabled');
350                    ACC.orderform.setTotalItemPrice($(this), 0, 0);
351
352                })
353            }
354            ACC.productorderform.cleanValues();
355            ACC.productorderform.resetSelectedVariant();
356            ACC.orderform.$totalPrice.html(ACC.productorderform.formatTotalsCurrency('0.00'));
357            ACC.orderform.$totalItemsCount.text('0');
358            ACC.orderform.$totalPriceValue.val(0);
359            ACC.orderform.cleanupQtyInputFromSessionStorage();
360        },
361
362        replaceSearchLabel: function (productIdsChecked) {
363            var currentLabel = ACC.orderform.$searchCurrentLabel.html();
364            var searchByIdsLabel = $("#searchByIdsLabel").val();
365            var searchByKeywordLabel = $("#searchByKeywordLabel").val();
366
367            if (productIdsChecked) {
368                currentLabel = currentLabel.replace(searchByKeywordLabel, searchByIdsLabel);
369            } else {
370                currentLabel = currentLabel.replace(searchByIdsLabel, searchByKeywordLabel);
371            }
372            ACC.orderform.$searchCurrentLabel.html(currentLabel);
373        },
374
375        stripOutInvalidChars: function () {
376            ACC.orderform.$productIdsInput.val(ACC.orderform.$productIdsInput.val().replace(/[^a-z0-9 ,.\-_]/ig, ''));
377        },
378
379        cleanupQtyInputFromSessionStorage: function () {
380            sessionStorage.removeItem("qtyInputs");
381            sessionStorage.removeItem("totalPrice");
382            sessionStorage.removeItem("totalPriceVal");
383            sessionStorage.removeItem("totalItems");
384        },
385
386        resetPriceCounters: function () {
387            ACC.orderform.$totalItemsCount.text(sessionStorage.totalItems);
388            ACC.orderform.$totalPrice.html(sessionStorage.totalPrice || ACC.productorderform.formatTotalsCurrency('0.00'));
389            ACC.orderform.$totalPriceValue.val(sessionStorage.totalPriceVal || 0);
390
391            //sub-total
392            ACC.orderform.fillTotalItemPrice();
393        },
394
395        setTotalItemPrice: function (item, quantity, price) {
396            if(!item.data('variant-id')) {
397                var htmlContent = (quantity > 0) ? ACC.productorderform.formatTotalsCurrency(price * quantity) : '';
398                item.parent().next('.item-total').html(htmlContent);
399            }
400        },
401
402        fillTotalItemPrice: function () {
403            if (sessionStorage.qtyInputs !== undefined){
404                var qtyInputsJson = JSON.parse(sessionStorage.qtyInputs);
405                var $product = {};
406
407                for (var i = 0; i < qtyInputsJson.length; i++) {
408                    if (qtyInputsJson[i].qty > 0) {
409                        $product = $('.' + qtyInputsJson[i].product);
410                        var totalPrice = ACC.productorderform.formatTotalsCurrency($product.siblings('.price').data('variant-price') *  qtyInputsJson[i].qty);
411                        $product.parent().siblings('.item-total').html(totalPrice);
412                    }
413                }
414            }
415        },
416
417        filterMatchingQtyInputs: function (qtyInputs, dataValueObj) {
418            var filteredObjects = $.grep(qtyInputs, function (obj) {
419                return dataValueObj.product == obj.product;
420            });
421            return filteredObjects;
422        }
423    };
424}
425

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.