PageSourceSearch

https://www.borderstates.com/_ui/responsive/common/js/acc.myList.js

js borderstates.com collected 2026-10-03 21:44:18 UTC 63,421 bytes, 1,418 lines download raw bytes

1var listImportFiles = [];
2
3ACC.myList = {
4
5    _autoload: [
6        ["bindMyListNav", $(".js-mylist-nav").length != 0],
7        ["bindWishlistListDraggable", $(".wishlist-item").length],
8        ["bindWishlistItemDraggable", $(".mylist-item").length],
9        ["bindShowListDetail", $(".js-myListDetail-selected").length],
10        ["bindAddListDialog", $("#createWishlistname").length],
11        ["bindAddAllToCartMyList", $(".addAllToCart_myList").length],
12        "bindLazyLoadPriceStockCall",
13        "bindProductPlusMinusSelectors",
14        "bindListDetailAction",
15        "bindEditListName",
16        "bindExportList",
17        ["bindImportList", $("#importCSVListFile").length]
18    ],
19    bindListDetailAction: function() {
20        $(document).on("click",'.js-share-wish-list' ,function(){
21            var listName = $(".js-oldValueEditPanel").val();
22            $.ajax({
23                type: 'POST',
24                url: ACC.config.encodedContextPath + '/wishlist/share-wishlist',
25                data: {
26                    wishlistName: listName
27                },
28                success: function (data, status) {
29
30                },
31            });
32
33        });
34
35        $(document).on("click",'.js-myListRemove' ,function(){
36            $(this).closest('.bse-menu-item').each(function () {
37                var data = [];
38                data.push($(this).find("input[name='productCodePost']").val());
39                ACC.myList.deletelistsDetails(data);
40            });
41
42        });
43        $(document).on("click",'.js-myListAddToCart' ,function(){
44            var cartEntries = [];
45            $(this).closest('.bse-menu-item').each(function () {
46                var obj = {};
47                obj.product = {};
48                obj.product.code = $(this).find("input[name='productCodePost']").val();
49                obj.product.name = $(this).find("input[name='productNamePost']").val();
50                obj.product.price = $(this).find("input[name='productPostPrice']").val();
51                // var checkbox = $('input[type="checkbox"][data-mylist-selected=' + obj.product.code +']').is(':checked');
52                if(!cartEntries.some(p => p.product.code ===  obj.product.code)) {
53                    obj.product.unit = $(this).find("input[name='uomCode']").val();
54                    var uomConversion = $(this).find("input[name='conversionFactor']") && $(this).find("input[name='conversionFactor']").val() > 0 ? $(this).find("input[name='conversionFactor']").val() : 1;
55                    var qty =  parseInt($(this).find(".quantity_text-" + obj.product.code).val());
56                    obj.quantity =  parseInt(uomConversion * qty);
57                    cartEntries.push(obj);
58                }
59            });
60            ACC.myList.addToCartMyList(cartEntries);
61
62
63        });
64    },
65    bindEditListName: function() {
66        $(document).on('click', '.editList', function () {
67            var container = $(this).closest(".wishlist-container");
68            container.find(".editList").hide();
69            container.find(".saveCancel").show();
70
71            container.find(".wishlist-link").hide();
72            container.find(".privacy-level-display").hide();
73            container.find("input").show();
74            container.find("select").show();
75        });
76        $(document).on('click', '.saveEdit', function () {
77            var nameControl = $(this).closest(".wishlist-container").find("input:visible");
78
79            var listId = $(".js-selectedListId").val();
80            var privacyLevel = $(".js-privacy-level").val();
81            var wishlistNewName = nameControl.val();
82
83            $.ajax({
84                type: 'POST',
85                url: ACC.config.encodedContextPath + '/wishlist/editWishlist',
86                data: {
87                    wishlistNewName: wishlistNewName,
88                    wishlistId:listId,
89                    privacyLevel:privacyLevel
90                },
91                success: function (data, status) {
92                    if (data.Status == "Updated"){
93                        ACC.myList.updateListName();
94                        var privacyLevelText = $(".js-privacy-level :selected").text();
95                        $(".privacy-level-display").text(privacyLevelText);
96                        $(".wishlist-item[id='" + wishlistNewName + "'] .extra-info div").text(privacyLevelText);
97                    } else {
98                        var oldValue = $('.js-oldValueEditPanel').val();
99                        $(".js-myListDetailId").val(oldValue);
100                    }
101                    var poupHeader = (!$(".errorMsgs p." + data.Status + "Header").text().trim()) ? data.Status : $(".errorMsgs p." + data.Status + "Header").text();
102                    ACC.colorbox.open(poupHeader, {
103                        className: "nonResponsive list-modal",
104                        html: "<div class=\"colorbox-content\"><p>" + $(".errorMsgs p." + data.Status.replace(" ","")).text() + "</p></div><div class=\"colorbox-footer\"><button class='btn-small js-edit-list-name-close-popup'>OK</button></div>",
105                        close:"<img tabindex=\"1\" src=\"/_ui/responsive/common/images/X.svg\" />",
106                        maxWidth: "100%",
107                        width: "700px",
108                        maxWidth:"90%",
109                        initialWidth: "360px",
110                    });
111                    $('.js-edit-list-name-close-popup').on("click", ACC.myList.editNameClosePopup);
112                },
113            });
114        });
115        $(document).on('click', '.cancelEditList', function () {
116
117            var container = $(this).closest(".wishlist-container");
118            container.find(".editList").show();
119            container.find(".saveCancel").hide();
120
121            container.find(".wishlist-link").show();
122            container.find("input").hide();
123            container.find("select").hide();
124            container.find(".privacy-level-display").show();
125            var oldValue = $('.js-mylistdetail-container').find('.oldValue').val();
126            $(".js-myListDetailId").val(oldValue);
127        });
128    },
129    editNameClosePopup: function() {
130        $.colorbox.close();
131        var container = $(".wishlist-container");
132        container.find(".editList").show();
133        container.find(".saveCancel").hide();
134
135        container.find(".wishlist-link").show();
136        container.find("input").hide();
137        container.find("select").hide()
138        container.find(".privacy-level-display").show();
139
140    },
141    updateListName: function() {
142        ACC.myList.editNameClosePopup();
143
144        var newValue = $('.js-myListDetailName').val();
145        var oldValue = $('.js-mylistdetail-container').find('.oldValue').val();
146        var listdata = $(".wishlist-item[id='" + oldValue + "']")
147
148        $(listdata).find(".list-name").text(newValue);
149        $(listdata).find(".js-myListDetail-selected").data("mylistname", newValue);
150        $(listdata).attr("id", newValue);
151
152        $(".js-mylist-nav-active").text(newValue);
153        $(".js-listname-display").text(newValue);
154        $('.js-mylistdetail-container').find('.oldValue').val(newValue);
155        var newHref = window.location.href ;
156        var listId = $(".js-selectedListId").val();
157
158        newHref = ACC.myList.updateQueryStringParameter(newHref, "wishLisId", listId )
159        window.history.replaceState(null, document.title, newHref);
160
161        return false;
162
163    },
164    bindAddAllToCartMyList: function () {
165        $(document).on("click", '.addAllToCart_myList', function () {
166            var cartEntries = [];
167            $('.add_to_cart_form').each(function () {
168                if ($(this).attr("disable-addtocart") != "true") {
169                    var obj = {};
170                    obj.product = {};
171                    obj.product.code = $(this).find("input[name='productCodePost']").val();
172                    obj.product.name = $(this).find("input[name='productNamePost']").val();
173                    obj.product.price = $(this).find("input[name='productPostPrice']").val();
174                    // var checkbox = $('input[type="checkbox"][data-mylist-selected=' + obj.product.code +']').is(':checked');
175                    if (!cartEntries.some(p => p.product.code === obj.product.code)) {
176                        obj.product.unit = $(this).find("input[name='uomCode']").val();
177                        var uomConversion = $(this).find("input[name='conversionFactor']") && $(this).find("input[name='conversionFactor']").val() > 0 ? $(this).find("input[name='conversionFactor']").val() : 1;
178                        var qty = parseInt($(this).find(".quantity_text-" + obj.product.code).val());
179                        obj.quantity = parseInt(uomConversion * qty);
180                        cartEntries.push(obj);
181                    }
182                }
183            });
184            ACC.myList.addToCartMyList(cartEntries);
185        });
186    },
187    addToCartMyList: function(cartEntries) {
188
189
190        if(cartEntries.length > 0) {
191            $.ajax({
192                type: 'POST',
193                contentType: 'application/json',
194                url: ACC.config.encodedContextPath + '/cart/addProductsToCart',
195                data: JSON.stringify({"cartEntries": cartEntries}),
196                dataType: 'json',
197                success: function (response) {
198                    if (typeof ACC.minicart.updateMiniCartDisplay == 'function') {
199                        ACC.minicart.updateMiniCartDisplay();
200                    }
201                    // ACC.myList.deselectMyListCheckbox();
202
203                    // let message = `${response.addedToCart} item(s) have been added to your cart.`;
204                    if (response.errors !== 0) {
205                        message = `${message}  We were unable to add ${response.errors} item(s) to your cart.`;
206
207                        ACC.colorbox.open("Add Items to Cart", {
208                            html: message,
209                            width: "560px",
210                            maxHeight: "95%",
211                            fixed:true,
212                            onComplete: function () {
213                            },
214                        });
215                    } else{
216                        cartEntries.forEach(function(entry) {
217                            var productCode = entry.product.code
218                            $(".js-mylist-item#" +productCode).find(".js-myListAddToCart").html("<span>&#10003;</span> Added to cart");
219                        });
220
221                    }
222
223                    // TODO: GTM Add to Cart Call
224                    //cartEntries.forEach(function(entry) {
225                    //    ACC.gtm.addToCart_gtm(entry.product.code, entry.product.name, entry.product.price, entry.quantity);
226                    //});
227
228                },
229                error: function () {
230                    console.log("error log: Add to cart failed");
231                }
232            });
233        }
234    },
235    bindAddListDialog: function() {
236        $(document).on("click",'#addlistsubmit', function (event) {
237            saveWish(event);
238        });
239        $(document).on("click",'.js-list-created-ok', function (event) {
240            window.location.replace(ACC.config.encodedContextPath + "/wishlist/get");
241        });
242        $(document).on("click",'.deleteSingleList', function () {
243            var listId = $(".js-selectedListId").val();
244            ACC.myList.deleteList(listId);
245        });
246        $("#createWishlistname").on('click', function () {
247            var proceedWithListCreation = true;
248            if( $('.js-update_myList').val() !== undefined && !$('.js-update_myList').is('[disabled=disabled]')){
249                var warningMessage = 'Changes you made are not saved, continue?';
250                if (!confirm(warningMessage)) {
251                    proceedWithListCreation =  false
252                }
253            }
254            if (proceedWithListCreation) {
255
256                $(window).resize(function () {
257                    ACC.colorbox.resize();
258                    $('#cboxLoadedContent').width('90%');
259                    $('#cboxLoadedContent').css('padding', '15px 5% 30px 5%');
260                });
261
262                var page = "wishListPage";
263                ACC.colorbox.open("Create a List", {
264                    className: "nonResponsive list-modal",
265                    href: ".create-list-modal",
266                    inline: true,
267                    close:"<img tabindex=\"1\" src=\"/_ui/responsive/common/images/X.svg\" />",
268                    maxWidth: "100%",
269                    width: "700px",
270                    maxWidth:"90%",
271                    initialWidth: "360px",
272                    fixed: true,
273                    onComplete: function () {
274                        $("input#listname").focus();
275                        $.colorbox.resize()
276                    },
277                    onClosed: function () {
278                        $("input#listname").val("");
279                        $(".help-block.invalid-character").hide();
280                        $(".help-block.empty-input").hide();
281                        $(".help-block.already-exists").hide();
282                        $("input#listname").removeAttr("style");
283                    },
284                });
285
286                $(document).on("click",'.js-cancelCreateList', function (e) {
287                    e.preventDefault();
288                    $.colorbox.close();
289                });
290            }
291
292        });
293    },
294    bindShowListDetail: function() {
295        $(".js-myListDetail-selected").each(function (){
296            let text = $(this).find(".list-name").text().substring(0,50);
297            if($(this).find(".list-name").text().length > 50){
298                $(this).find(".list-name").html(text).append("...");
299            }
300        });
301
302        //add active state on first item on load
303        $(document).ready(function() {
304            var currentList = $(".js-myListDetailId").val();
305            if (currentList == "")
306            {
307                $(".bse-dropdown-nav .wishlist-item:first-of-type").addClass("active");
308
309            } else {
310                var listdata = $(".wishlist-item[id='" + currentList + "']");
311                listdata.addClass("active");
312            }
313
314            var currActiveTitle = $(".wishlist-item.active .list-name").html();
315            //get name and plop it into mobile slot
316            $(".js-mylist-nav-active").text(currActiveTitle);
317        });
318
319        $(".js-myListDetail-selected").on('click', function (e) {
320            var loadNewContent = true;
321            if( $('.js-update_myList').val() !== undefined && !$('.js-update_myList').is('[disabled=disabled]')){
322                var warningMessage = 'Changes you made are not saved, continue?';
323                if (!confirm(warningMessage)) {
324                    loadNewContent =  false
325                }
326            }
327            if (loadNewContent) {
328                $(".js-mylist-details").addClass("hide");
329                $(".load-container").addClass("show");
330
331                //close mobile accordian
332                $(".js-mylist-nav").removeClass("nav-open");
333
334                //rip active class off sibling
335                $(".bse-dropdown-nav .wishlist-item").removeClass("active");
336
337                //add active to clicked item
338                $(this).parent().parent().addClass("active");
339
340                var currActiveTitle = $(".wishlist-item.active .list-name").html()
341                //get name and plop it into mobile slot
342                $(".js-mylist-nav-active").text(currActiveTitle);
343                //replace active in mobile
344
345                //TODO add a spinner before calling the backend, located at the end of bsestorefront\web\webroot\WEB-INF\tags\responsive\myList\myListDetail.tag
346               // var listName = $(this).data("mylistname");
347                var listId = $(this).data("mylistid");
348                $.ajax({
349                    type: 'get',
350                    url: ACC.config.encodedContextPath + '/wishlist/getDetail',
351                    data: {
352                        listId: listId,
353                    },
354                    success: function (data, status) {
355                        $(".js-mylistdetail-container").html(data);
356                        ACC.myList.bindWishlistItemDraggable();
357                        ACC.myList.bindLazyLoadPriceStockCall();
358                        $('html, body').animate({
359                            scrollTop: 0
360                        }, 200);
361                        ACC.myList.enableListExport();
362                        ACC.myList.enableAddAllToCart();
363                        var newHref = window.location.href ;
364                        newHref = ACC.myList.updateQueryStringParameter(newHref, "wishLisId", listId )
365                        window.history.replaceState(null, document.title, newHref);
366                    },
367                });
368            }
369        });
370    },
371    bindMyListNav: function () {
372        $(".js-mylist-nav").click(function(){
373            $(this).toggleClass("nav-open");
374        });
375    },
376    bindWishlistListDraggable:function (){
377        var currentlyScrolling = false;
378
379        var SCROLL_AREA_HEIGHT = 40;
380        $(document).ready(function() {
381            if ($(window).width() > 1024) {
382                $('.bse-dropdown-nav').sortable({
383                    scroll: true,
384                    opacity: 0.8,
385                    axis: "y",
386                    containment: ".my-list-container",
387                    scroll: true,
388                    scrollSensitivity: 80,
389                    scrollSpeed: 3,
390                    sort: function(event, ui) {
391
392                        if (currentlyScrolling) {
393                            return;
394                        }
395
396                        var windowHeight = $(window).height();
397                        var mouseYPosition = event.clientY;
398
399                        if (mouseYPosition < SCROLL_AREA_HEIGHT) {
400                            currentlyScrolling = true;
401
402                            $('html, body').animate({
403                                    scrollTop: "-=" + windowHeight / 2 + "px"
404                                },
405                                400,
406                                function() {
407                                    currentlyScrolling = false;
408                                });
409                        } else if (mouseYPosition > (windowHeight - SCROLL_AREA_HEIGHT)) {
410
411                            currentlyScrolling = true;
412
413                            $('html, body').animate({
414                                    scrollTop: "+=" + windowHeight / 2 + "px"
415                                },
416                                400,
417                                function() {
418                                    currentlyScrolling = false;
419                                });
420                        }
421                    },
422                    stop: function( event, ui ) {
423                        var idsInOrder = $(".bse-dropdown-nav").sortable("toArray");
424
425
426                        $.ajax({
427                            type: 'POST',
428                            url: ACC.config.encodedContextPath + '/wishlist/reorder-lists',
429                            data: {
430                                listNames: idsInOrder.toString()
431                            },
432                            success: function () {
433
434                            },
435                            error: function () {
436                                console.log("ReOrder list FAILED")
437                            }
438                        });
439
440                    }
441                });
442            }
443        });
444    },
445    bindWishlistItemDraggable:function (){
446        var currentlyScrolling = false;
447
448        var SCROLL_AREA_HEIGHT = 40;
449        $(document).ready(function() {
450            if ($(window).width() > 1024) {
451                $('#myList-product-table').sortable({
452                    scroll: true,
453                    opacity: 0.8,
454                    axis: "y",
455                    scroll: true,
456                    containment: ".my-list-container",
457                    scrollSensitivity: 80,
458                    scrollSpeed: 3,
459                    sort: function(event, ui) {
460
461                        if (currentlyScrolling) {
462                            return;
463                        }
464
465                        var windowHeight = $(window).height();
466                        var mouseYPosition = event.clientY;
467
468                        if (mouseYPosition < SCROLL_AREA_HEIGHT) {
469                            currentlyScrolling = true;
470
471                            $('html, body').animate({
472                                    scrollTop: "-=" + windowHeight / 2 + "px"
473                                },
474                                400,
475                                function() {
476                                    currentlyScrolling = false;
477                                });
478                        } else if (mouseYPosition > (windowHeight - SCROLL_AREA_HEIGHT)) {
479
480                            currentlyScrolling = true;
481
482                            $('html, body').animate({
483                                    scrollTop: "+=" + windowHeight / 2 + "px"
484                                },
485                                400,
486                                function() {
487                                    currentlyScrolling = false;
488                                });
489                        }
490                    },
491                    stop: function( event, ui ) {
492
493                        var productIDs = $("#myList-product-table").sortable("toArray");
494                        var listName = $(".js-myListDetailName").val();
495
496                        $.ajax({
497                            type: 'POST',
498                            url: ACC.config.encodedContextPath + '/wishlist/reorder-list-entries',
499                            data: {
500                                wishlistNames: listName,
501                                productCodes: productIDs.toString()
502                            },
503                            success: function () {
504                               // console.log("ReOrder list completed")
505                            },
506                            error: function () {
507                                console.log("ReOrder list FAILED")
508                            }
509                        });
510                    }
511                });
512            }
513        });
514    },
515    deleteList: function(listId) {
516        $(window).resize(function () {
517            ACC.colorbox.resize();
518            if ($(window).width() < 639) {
519                $.colorbox.resize({
520                    width: '360px',
521                });
522            }
523            $('#cboxLoadedContent').width('90%');
524            $('#cboxLoadedContent').css('padding', '15px 5% 30px 5%');
525        });
526        var listName = $('.js-myListDetailName').val();
527
528        ACC.colorbox.open("Confirm Delete List", {
529            className: "nonResponsive list-modal",
530            html: "<div class='colorbox-content'>" +
531                "<p>Are you sure you want to delete the list \"" + listName + "\"?</p>" +
532                "</div>" +
533                "<div class='colorbox-footer'>" +
534                "<button class='btn-small btn-secondary js-cancelDeleteList'>Cancel</button> " +
535                "<button class='btn-small btn-primary' id='delList'>Delete</button>" +
536                "</div>",
537            close: "<img tabindex=\"1\" src=\"/_ui/responsive/common/images/X.svg\" />",
538            maxWidth: "100%",
539            width: "700px",
540            maxWidth: "90%",
541            initialWidth: "360px",
542            overlayClose: false,
543            fixed: true
544        });
545        $(document).on("click", '#delList', function (e) {
546
547            $.ajax({
548                type: 'GET',
549                url: ACC.config.encodedContextPath + '/wishlist/removeWishlist',
550                data: {
551                    wishlistId: listId
552                },
553                success: function () {
554                    window.location.replace(ACC.config.encodedContextPath + '/wishlist/get');
555                },
556                error: function () {
557                }
558            });
559
560        });
561
562        $(document).on("click", '.js-cancelDeleteList', function (e) {
563            e.preventDefault();
564            $.colorbox.close();
565        });
566    },
567    bindProductPlusMinusSelectors: function(){
568        $(document).on("click",'.mylist-item .js-qty-selector-plusWL' ,function(){
569
570            var decrement = $(this).parent().parent().find('.cart
570-input').attr('data-min');
571            var $input = $(this).parent().parent().find('.cart-input');
572            var count = parseInt($input.val()) - decrement;
573            if (count > 99999){
574                $input.val(99999);
575                $input.change();
576
577            } else {
578
579
580                var quantityVal;
581                var form = $(this).closest('form');
582                var selectedVal = form.find('select.js-packaging_unit').find('option:selected');
583
584                if (selectedVal.length > 0) {
585                    if (selectedVal.hasClass('defaultuom')) {
586                        quantityVal = parseInt(form.find("input[name='minOrderQuantity']").val());
587                    } else {
588                        quantityVal = 1;
589                    }
590                } else {
591                    quantityVal = parseInt(form.find("input[name='minOrderQuantity']").val());
592                }
593
594                var incrVal = parseInt(form.find("input[name='qty']").val()) + quantityVal;
595                form.find("input[name='qty']").val(incrVal);
596
597                // if (incrVal > quantityVal) {
598                //     form.find('.js-qty-selector-minusWL').removeAttr('disabled');
599                // } else {
600                //     form.find('.js-qty-selector-minusWL').attr('disabled', 'disabled');
601                // }
602                ACC.myList.updateButtonStatus();
603            }
604        });
605
606        $(document).on("click", '.mylist-item .js-qty-selector-minusWL',function(){
607
608            var decrement = $(this).parent().parent().find('.cart-input').attr('data-min');
609            var $input = $(this).parent().parent().find('.cart-input');
610            var count = parseInt($input.val()) - decrement;
611            if (count < 1){
612                $input.val(1);
613                $input.change();
614
615            } else {
616                var quantityVal;
617
618                var form = $(this).closest('form');
619                var selectedVal = form.find('select.js-packaging_unit').find('option:selected');
620
621                if (selectedVal.length > 0) {
622                    if (selectedVal.hasClass('defaultuom')) {
623                        quantityVal = parseInt(form.find("input[name='minOrderQuantity']").val());
624                    } else {
625                        quantityVal = 1;
626                    }
627                } else {
628                    quantityVal = parseInt(form.find("input[name='minOrderQuantity']").val());
629                }
630
631                var decrVal = parseInt(form.find("input[name='qty']").val()) - quantityVal;
632
633                form.find("input[name='qty']").val(decrVal);
634
635                // if (decrVal == quantityVal) {
636                //     form.find('.js-qty-selector-minusWL').attr('disabled', 'disabled');
637                // } else {
638                //     form.find('.js-qty-selector-minusWL').removeAttr('disabled');
639                // }
640                ACC.myList.updateButtonStatus();
641            }
642        });
643    },
644    bindLazyLoadPriceStockCall: function(){
645        if($('#myList-product-table').length){
646            // Get Price stock
647            ACC.myList.initPriceCall();
648
649            $('.js-update_myList').on("click", function () {
650                ACC.myList.updateMyList();
651            });
652            $('.js-unitQuantity').on("change", function () {
653                $(this).closest('.add_to_cart_form').each(function () {
654                    ACC.myList.validateQuantity($(this));
655                });
656                ACC.myList.updateButtonStatus();
657            });
658
659            $('.js-packaging_unit').on("change", function () {
660
661                var selectedUnit = $(this);
662
663                var priceWs = [ ];
664                var stockWs = [ ];
665                selectedUnit.closest('.add_to_cart_form').each(function () {
666                    var sapPriceWsDTO = {};
667                    var sapStockWsDTO = {};
668                    var productCode = $(this).find("input[name='productCodePost']").val();
669                    if (productCode) {
670                        sapPriceWsDTO.productCode = productCode;
671                        sapStockWsDTO.productCode = productCode;
672                        if (!priceWs.some(p => p.productCode === sapPriceWsDTO.productCode)) {
673
674                            var optionVal = $(this).find('option:selected')
675                            $(".conversionFactor-" + productCode).val(optionVal.val());
676                            if(optionVal.val() == 1){
677                                var minQty =  $(this).find("input[name='minOrderQuantity']").val()
678                                $(this).find('.js-unitQuantity').val(minQty);
679                                $(".quantity_text-" + productCode).val(minQty);
680
681                            }else{
682                                $(this).find('.js-unitQuantity').val(1);
683                                $(".quantity_text-" + productCode).val(1);
684
685                            }
686                            sapPriceWsDTO.unit = optionVal.attr('uom');
687
688                            sapStockWsDTO.unit = selectedUnit.find('option:selected').attr('uom')
689                            sapPriceWsDTO.minOrderQuantity = 1;
690                            sapStockWsDTO.minOrderQuantity = 1;
691
692                            ACC.myList.validateQuantity($(this));
693                            priceWs.push(sapPriceWsDTO);
694                            stockWs.push(sapStockWsDTO);
695                        }
696                    }
697                });
698                if($(this).hasClass('js-packaging_unit')) {
699                    $(this).parents(".js-mylist-item").find(".js-myList-Stock-label").html("&#160;");
700                    $(this).parents(".js-mylist-item").find(".js-myList-Price-label").html("&#160;");
701                    ACC.myList.priceCall(priceWs, 1);
702                    ACC.myList.stockCall(stockWs, 1);
703                }
704
705                ACC.myList.updateButtonStatus();
706
707            });
708
709        }
710    },
711    bindExportList: function(){
712        ACC.myList.enableListExport();
713        $(document).on("click", '.js-export_myList', function () {
714            var today = getCurrentDateForListExport();
715            var listName = $(this).parent().prev().find('.js-myListDetailName').val();
716            listName = listName.replace(' ', '_');
717            exportListToCSV('ExportList_' + listName + '_' + today + '.csv', $(this).parent().parent().children('.js-myList-product-table'));
718        });
719        function exportListToCSV(filename, myListProductTableDiv) {
720            var csv = '"BOR Part #","Product Description","Qty","Unit Price","U of M","Mfg part #","Customer Part #","ATP"\n';
721            if (myListProductTableDiv != null) {
722                myListProductTableDiv.children('.js-mylist-item').each(function( index ) {
723                    csv += '"' + $(this).find('.js-bse-part-number').text() + '",';
724                    csv += '"' + $(this).find('.js-bse-description').text().replace(',','').replace('"','') + '",';
725                    csv += '"' + $(this).find('.js-unitQuantity').val() + '",';
726                    var itemPrice = $(this).find('.js-price').text().replace('$', '');
727                    if (itemPrice === "0.00"){
728                        csv += '"",';
729
730                    } else {
731                        csv += '"' + itemPrice + '",';
732                    }
733                    csv += '"' + $(this).find('select.js-packaging_unit option:selected').attr('uom') + '",';
734                    csv += '"' + $(this).find('.js-mfgt-part-number').text() + '",';
735                    csv += '"' + $(this).find('.js-customer-part-number').text() + '",';
736                    // ATP is the last column. Its value comes ONLY from the row's stock
737                    // label -- never from price -- so a blanked ($0.00) price never blanks ATP.
738                    csv += '"' + getAtpValueForExportRow($(this)) + '"';
739                    csv += '\n';
740                });
741            }
742            downloadListCSV(csv, filename);
743        }
744        function getAtpValueForExportRow($row) {
745            // Returns the ATP (Available To Promise) value for a single My List row,
746            // read from that row's already-rendered stock label -- the same way price
747            // is scraped from the DOM. Returns a STRING for direct 
747CSV insertion.
748            //
749            // At export time the export button is gated until stock finishes loading,
750            // so the .js-myList-Stock-label is in exactly one of three final states:
751            //
752            //   In stock      <span class="stock-available-number">150&#160;In Stock</span>
753            //                 (no "not-available" class)            -> return "150" (the bare number)
754            //
755            //   Out of stock  <span class="stock-available-number not-available">Out of stock</span>
756            //                                                       -> return "0"
757            //
758            //   Contact branch -> the label holds no .stock-available-number element.
759            //                 This happens for distribution chain 02/03 / disabled items,
760            //                 AND when price <= 0 (fillMyListProductPriceValue overwrites
761            //                 the label with "Contact branch for pricing and availability").
762            //                                                       -> return "" (blank)
763            //
764            // The blank-on-no-availability behavior is intentional and confirmed: when the
765            // on-screen availability is hidden, the export matches the screen (blank ATP).
766            // This function never reads price directly -- it does NOT reuse the export's own
767            // "0.00 -> blank" price rule; it only mirrors what the stock label displays.
768            // Export is gated (enableListExport) until stock finishes loading, so the
769            // transient loading-spinner state is never read here.
770            var $stockLabel = $row.find('.js-myList-Stock-label');
771            var $stockNumber = $stockLabel.find('.stock-available-number');
772
773            // 1. Contact-branch placeholder: no stock-available-number element at all.
774            if ($stockNumber.length === 0) {
775                return "";
776            }
777            // 2. Out of stock: rendered with the "not-available" modifier class.
778            if ($stockNumber.hasClass('not-available')) {
779                return "0";
780            }
781            // 3. In stock: text reads "150&#160;In Stock"; parseInt stops at the first
782            //    non-digit, yielding the bare ATP quantity.
783            var atp = parseInt($stockNumber.text(), 10);
784            return isNaN(atp) ? "" : String(atp);
785        }
786        function downloadListCSV(csv, filename) {
787            var csvFile;
788            var downloadLink;
789            csvFile = new Blob([csv], {type: "text/csv"});
790            downloadLink = document.createElement("a");
791            downloadLink.download = filename;
792            downloadLink.href = window.URL.createObjectURL(csvFile);
793            downloadLink.style.display = "none";
794            document.body.appendChild(downloadLink);
795            downloadLink.click();
796        }
797        function getCurrentDateForListExport(){
798            var myDate = new Date();
799            var day = "" + myDate.getDate();
800            if(day.length < 2){
801                day = "0"+day;
802            }
803            var month = myDate.getMonth();
804            month = (month+1) + "";
805            if(month.length < 2){
806                month = "0"+month;
807            }
808            var year = myDate.getFullYear();
809            return "" + month + day + year;
810        }
811    },
812    enableListExport: function(){
813        // Only enable export once BOTH price AND stock have finished loading. ATP is
814        // scraped from the rendered stock label, so enabling on price-load alone would
815        // let a user export while stock is still a loading spinner -> blank ATP cells.
816        $('.js-myList-product-table').each(function( index ) {
817            if ($(this).find('.js-myList-Price-label-loading').length == 0
818                && $(this).find('.js-myList-Stock-label-loading').length == 0) {
819                $(this).parent().find('.js-export_myList').removeAttr('disabled');
820            }
821        });
822    },
823    enableAddAllToCart: function(){
824        $('.js-myList-product-table').each(function( index ) {
825            if ($(this).find('.js-myListAddToCart:disabled').length == $(this).find('.js-myListAddToCart').length) {
826                $(this).parent().find('.js-addAllToCart_myList').prop('disabled', true);
827            }
828            else {
829                $(this).parent().find('.js-addAllToCart_myList').prop('disabled', false);
830            }
831        });
832    },
833    updateButtonStatus: function(){
834        var dirtyItem = false;
835
836        $('.add_to_cart_form:visible').each(function () {
837            var packagingUnit = $(this).find('.js-packaging_unit');
838            var selectedUnit = packagingUnit.find('option:selected');
839
840            if (selectedUnit.attr('uom') !== packagingUnit.data('value')) {
841                dirtyItem = true;
842            }
843
844            var itemQty = $(this).find('.js-unitQuantity');
845            if (!isNaN(parseInt(itemQty.val())) && parseInt(itemQty.val()) !== parseInt(itemQty.attr('qty-value'))) {
846                dirtyItem = true;
847            }
848        });
849
850        $(".js-update_myList").attr("disabled", !dirtyItem);
851
852        if (dirtyItem){
853            window.addEventListener("beforeunload", function (e) {
854                if( $('.js-update_myList').val() !== undefined && !$('.js-update_myList').is('[disabled=disabled]')){
855                    var confirmationMessage = 'You’ve made changes to the list. Either return to the list and save the changes or discard the changes.';
856                    (e || window.event).returnValue = confirmationMessage;
857                    return confirmationMessage;
858                }
859            });
860        }
861    },
862    updateMyList: function(){
863        var dirtyProductsId = [];
864        var dirtyProductsQty = [];
865        var dirtyProductsUmo = [];
866
867        $('.add_to_cart_form:visible').each(function () {
868            var packagingUnit = $(this).find('.js-packaging_unit');
869            var selectedUnit = packagingUnit.find('option:selected');
870            var itemQty = $(this).find('.js-unitQuantity');
871
872
873            if(selectedUnit.attr('uom') !== packagingUnit.data('value') ||
874                ( !isNaN(parseInt(itemQty.val())) && parseInt(itemQty.val()) !== itemQty.data('qty'))){
875                $(this).find('.js-unitQuantity').attr('qty-value', itemQty.val());
876                dirtyProductsId.push( $(this).find("input[name='productCodePost']").val());
877                dirtyProductsQty.push(itemQty.val());
878                dirtyProductsUmo.push(selectedUnit.attr('uom'));
879            }
880
881        });
882
883        if(dirtyProductsId.length > 0){
884            $(".js-update_myList").attr("disabled", true);
885            $.ajax({
886                type: 'POST',
887                url: ACC.config.encodedContextPath + '/wishlist/updateWishlistDetails',
888                data: {"productIds": dirtyProductsId.join(), "qtys": dirtyProductsQty.join(), "units": dirtyProductsUmo.join(), "wishlistId": $(".js-selectedListId").val()},
889                success: function (data) {
890
891                    $('.add_to_cart_form:visible').each(function () {
892                        var packagingUnit = $(this).find('.js-packaging_unit');
893                        var selectedUnit = packagingUnit.find('option:selected');
894                        var itemQty = $(this).find('.js-unitQuantity');
895
896                        var prodId = $(this).find("input[name='productCodePost']").val()
897                        if(dirtyProductsId.includes(prodId)){
898                            packagingUnit.data('value',selectedUnit.attr('uom'))
899                            itemQty.data('qty',parseInt(itemQty.val()))
900                        }
901                    });
902                    ACC.myList.updateButtonStatus();
903                    let message = `Saved.`;
904
905                    ACC.colorbox.open("MyList.", {
906                        html: message,
907                        width: "560px",
908                        maxHeight: "95%",
909                        fixed:true,
910                        onComplete: function () {
911                        },
912                    });
913                },
914                error: function () {
915                }
916            });
917        }
918
919    },
920    initPriceCall: function(){
921        var priceWs = [ ];
922        var stockWs = [ ];
923        $('.add_to_cart_form:visible').each(function () {
924            var sapPriceWsDTO = {};
925            var sapStockWsDTO = {};
926            var productCode = $(this).find("input[name='productCodePost']").val();
927            if (productCode) {
928                sapPriceWsDTO.productCode = productCode;
929                sapStockWsDTO.productCode = productCode;
930
931                if (!priceWs.some(p => p.productCode === sapPriceWsDTO.productCode)) {
932                    sapPriceWsDTO.unit = $(this).find('option:selected').attr('uom')
933                    sapStockWsDTO.unit = $(this).find('option:selected').attr('uom')
934                    sapPriceWsDTO.minOrderQuantity = 1;
935                    sapStockWsDTO.minOrderQuantity = 1;
936
937                    priceWs.push(sapPriceWsDTO);
938                    stockWs.push(sapStockWsDTO);
939                }
940            }
941        });
942
943        ACC.myList.priceCall(priceWs, ACC.config.myListPriceChuckSize);
944        ACC.myList.stockCall(stockWs, ACC.config.myListPriceChuckSize);
945    },
946    priceCall: function(priceWs, chunckSize){
947        $(".js-export_myList").attr('disabled', 'true');
948        var chunks = [];
949        var i = 0;
950        var n = priceWs.length;
951        while (i < n) {
952            chunks = priceWs.slice(i, i += chunckSize);
953
954            jQuery.ajaxQueue({
955                type: 'POST',
956                url: ACC.config.encodedContextPath + '/c/priceWs',
957                contentType: 'application/json',
958                data: JSON.stringify(chunks),
959                timeout: ACC.config.myListPriceAjaxtimeout,
960                success: function (response) {
961
962                    ACC.myList.fillMyListProductPriceValue(response);
963                    ACC.myList.enableListExport();
964                    ACC.myList.updateDiscontinuedProducts();
965                    ACC.myList.enableAddAllToCart();
966                },
967                error: function () {
968                    console.log("Error getting price values for products.");
969                }
970            });
971        }
972    },
973    stockCall: function(stockWs, chunckSize){
974        var chunks = [];
975        var s = stockWs.length;
976        var j = 0;
977        while (j < s) {
978            chunks = stockWs.slice(j, j += chunckSize);
979
980            jQuery.ajaxQueue({
981                type: 'POST',
982                url: ACC.config.encodedContextPath + '/c/stockWs',
983                contentType: 'application/json',
984                data: JSON.stringify(chunks),
985                timeout: ACC.config.myListPriceAjaxtimeout,
986                success: function (response) {
987                    ACC.myList.fillMyListProductStockValue(response);
988                    ACC.myList.updateDiscontinuedProducts();
989                    ACC.myList.enableAddAllToCart();
990                    // Stock has loaded for this chunk; re-check whether export can unlock.
991                    ACC.myList.enableListExport();
992                },
993                error: function () {
994                    console.log("Error getting stock values for products.");
995                    // Don't let a stock failure permanently block export. Clear the stock
996                    // loading markers (ATP will simply be blank for the failed rows) and
997                    // re-evaluate the export gate.
998                    $('.js-myList-Stock-label-loading').removeClass('js-myList-Stock-label-loading');
999                    ACC.myList.enableListExport();
1000                }
1001            });
1002        }
1003    },
1004    fillMyListProductPriceValue: function(priceArray){
1005        if(priceArray.length > 0){
1006            $.each(priceArray, function(i, item) {
1007
1008                $('.'+ item.productCode +'-price').each(function () {
1009                    var htmlPrice = ``;
1010                    var floatPrice = parseFloat(item.price.value);
1011                    if (floatPrice <= 0.0 ){
1012                        $(this).parents(".js-mylist-item").find(".js-myListAddToCart").prop("disabled",true);
1013                        $(this).parents(".js-mylist-item").find(".add_to_cart_form").attr("disable-addtocart","true");
1014                        $(this).parents(".js-mylist-item").find(".js-myList-Stock-label").html("<span class=\"stock\"><img src=\"/_ui/responsive/common/images/alert-product.svg\" class=\"icon\" /></span><span class=\"js-noPriceAvailability noPalPlaceHolderText\">Contact branch for pricing and availability</span>   ");
1015                    } else {
1016                        $(this).parents(".js-mylist-item").find(".js-myListAddToCart").prop("disabled",fal
1016se);
1017                        $(this).parents(".js-mylist-item").find(".add_to_cart_form").attr("disable-addtocart","false");
1018                        var prodUnit = $(".unit-"+item.productCode).val();
1019                        htmlPrice = `
1020                            <span class='js-price'>${item.price.formattedValue}</span>&nbsp;/&nbsp;${prodUnit}
1021                            `;
1022                    }
1023                    $(this).html(htmlPrice);
1024                });
1025
1026                //Sorting
1027                $("div").find(`[data-sort-code='${item.productCode}']`).each(function () {
1028                    $(this).attr('data-sort-price', item.price.value);
1029                });
1030            });
1031        } else {
1032            $('.js-myList-Price-label').each(function () {
1033
1034                var htmlPrice = ``;
1035                $(this).html(htmlPrice);
1036                $(this).parents(".js-mylist-item").find(".js-myListAddToCart").prop("disabled",true);
1037                $(this).parents(".js-mylist-item").find(".add_to_cart_form").attr("disable-addtocart","true");
1038            });
1039
1040        }
1041    },
1042    fillMyListProductStockValue: function(stockArray) {
1043        $('.js-myList-Stock-label').each(function () {
1044            var productCode = $(this).parents(".js-mylist-item").attr("id");
1045            var htmlStock = "";
1046            if (stockArray === "" || stockArray.find(x => x.productCode === productCode) ==undefined){
1047                if ($(this).find(".stock").length == 0) {
1048                    htmlStock = `
1049                                        <span class="stock not-available"><img src="/_ui/responsive/common/images/not-available.svg" class="icon"/></span>
1050                                        <span class="stock-available-number not-available">Out of stock</span>
1051                                    `;
1052                }
1053            } else {
1054                var stoceLevel = stockArray.find(x => x.productCode === productCode).stock;
1055                var htmlStock;
1056                if (stoceLevel.stockLevelStatus.code && stoceLevel.stockLevelStatus.code != 'outOfStock' && stoceLevel.stockLevel > 0) {
1057                    htmlStock = `
1058                                    <span class="stock"><img src="/_ui/responsive/common/images/available.svg" class="icon"/></span>
1059                                    <span class="stock-available-number">
1060                                        ${stoceLevel.stockLevel}&#160;In Stock
1061                                    </span>
1062                                    `;
1063                } else {
1064                    htmlStock = `
1065                                        <span class="stock not-available"><img src="/_ui/responsive/common/images/not-available.svg" class="icon"/></span>
1066                                        <span class="stock-available-number not-available">Out of stock</span>
1067                                    `;
1068                }
1069            }
1070            if (htmlStock != "" && $(this).parents(".js-mylist-item").find(".js-noPriceAvailability").length == 0) {
1071                $(this).html(htmlStock);
1072            }
1073        });
1074
1075    },
1076    validateQuantity: function(element) {
1077        var productCode  = element.find("input[name='productCodePost']").val();
1078        var quantityVal;
1079        var packagingUnit = element.find('.js-packaging_unit');
1080        var selectDpVal = packagingUnit.find('option:selected');
1081        if (selectDpVal.val() == 1) {
1082            quantityVal = parseInt(element.find("input[name='minOrderQuantity']").val());
1083        } else {
1084            quantityVal = 1;
1085        }
1086
1087        var curVal = element.find('.js-unitQuantity').val();
1088
1089        var errMsg = $('.minqtycheck').text();
1090        if (curVal > quantityVal) {
1091
1092            var removeQuantity = parseInt(curVal) % quantityVal;
1093            curVal = curVal - removeQuantity;
1094            ACC.myList.updateRowQuantity(element, curVal);
1095
1096            if (removeQuantity != 0) {
1097
1098                element.attr("title", errMsg + " " + quantityVal);
1099                element.tooltip();
1100                element.trigger("mouseover");
1101                setTimeout(function () {
1102                    element.tooltip('destroy');
1103                }, 3000);
1104            }
1105        } else if (curVal == quantityVal) {
1106            ACC.myList.updateRowQuantity(element, quantityVal);
1107
1108        } else {
1109            ACC.myList.updateRowQuantity(element, quantityVal);
1110            element.attr("title", errMsg + " " + quantityVal);
1111            element.tooltip();
1112            element.trigger("mouseover");
1113            setTimeout(function () {
1114                element.tooltip('destroy');
1115            }, 3000);
1116        }
1117    },
1118    updateRowQuantity: function(element, qty) {
1119        var productCode  = element.find("input[name='productCodePost']").val();
1120        element.find('.js-unitQuantity').val(qty);
1121        $(".quantity_text-" + productCode).val(qty);
1122    },
1123    updateDiscontinuedProducts: function(element, qty) {
1124        var htmlDiscontinued = `<div class="js-discontinued-message"><img src="/_ui/responsive/common/images/alert.svg" class="icon"/>
1125                                <span class="stock-available-number not-available">This product has been discontinued.</span></div>
1126                        `;
1127        $('.mylist-item[data-discontinued="true"').each(function () {
1128            if ($(this).find('.js-discontinued-message').length == 0) {
1129                $(this).find('.js-myList-Stock-label').before(htmlDiscontinued);
1130            }
1131            if($(this).find('.stock.not-available').length > 0 || $(this).find('.js-noPriceAvailability').length > 0) {
1132                 $(this).find('.js-myList-Stock-label').addClass("hidden");
1133                 $(this).find('.js-myList-Price-label').addClass("hidden");
1134                 $(this).find(".js-myListAddToCart").prop("disabled",true);
1135                 $(this).find(".add_to_cart_form").attr("disable-addtocart","true");
1136            }
1137            else {
1138                 $(this).find('.js-myList-Stock-label').removeClass("hidden");
1139                 $(this).find('.js-myList-Price-label').removeClass("hidden");
1140                 $(this).find(".js-myListAddToCart").prop("disabled",false);
1141                 $(this).find(".add_to_cart_form").attr("disable-addtocart","false");
1142            }
1143        });
1144    },
1145    createNewList: function(event, page) {
1146
1147        event.preventDefault();
1148        $(".help-block.invalid-character").hide();
1149        $(".help-block.empty-input").hide();
1150        $(".help-block.already-exists").hide();
1151        var listName = $("#listname").val();
1152        if (listName != "") {
1153            if (!listName.match(/^[a-zA-Z0-9-_ ]+$/i)) {
1154                document.getElementById('listname').style.borderColor = "red";
1155                $(".help-block.invalid-character").show();
1156                $.colorbox.resize();
1157            }
1158            else {
1159                $.post(ACC.config.encodedContextPath
1160                    + "/wishlist/create-wishlist",
1161                    {
1162                        wishlistName: $("#listname").val(),
1163                        privacyLevel: $("#privacylevel").val()
1164                    },
1165                    function (data, status) {
1166                        var statusText = data.Status;
1167
1168                        if (page == "wishListPage") {
1169
1170                            if (statusText == "AlreadyExists"){
1171                                document.getElementById('listname').style.borderColor = "red";
1172                                $(".help-block.already-exists").show();
1173                                $.colorbox.resize();
1174                            } else {
1175                                var poupHeader = (!$(".errorMsgs p." + data.Status + "Header").text().trim()) ? data.Status : $(".errorMsgs p." + data.Status + "Header").text();
1176                                ACC.colorbox.open(poupHeader, {
1177                                    className: "nonResponsive list-modal",
1178                                    html: "<div class=\"colorbox-content\"><p>" + $(".errorMsgs p." + data.Status).text() + "</p></div><div class=\"colorbox-footer\"><button class='btn-small btn-primary js-list-created-ok'>OK</button></div>",
1179                                    initialWidth: "380px",
1180                                    close: "<img tabindex=\"1\" src=\"/_ui/responsive/common/images/X.svg\" />",
1181                                    onClosed: function () { window.location.replace(ACC.config.encodedContextPath + '/wishlist/get');} ,
1182                                    maxWidth: "100%",
1183                                    width: "700px",
1184                                    maxWidth: "90%",
1185                                    initialWidth: "360px",
1186                                });
1187                            }
1188                        } else {
1189                            $.get(ACC.config.encodedContextPath + "/wis
1189hlist/getAllWishLists", // url
1190                                function (data, textStatus, jqXHR) { // success
1191                                    // callback
1192
1193                                    var options = '<option value="Please Select">Please Select</option>';
1194
1195                                    for (var i = 0; i < data.length; i++) {
1196                                        options += '<option value="'
1197                                            + data[i]
1198                                            + '">'
1199                                            + data[i]
1200                                            + '</option>';
1201                                    }
1202                                    options += '<option value="newList">Create New List</option>';
1203                                    $(".wishlistname").empty().append(options);
1204                                    if (statusText.includes("already exists")) {
1205                                        $(".errorCreateWishlist").show();
1206                                        $(".errorCreateWishlist").text(statusText);
1207                                    } else {
1208                                        if ($("#cboxClose")) {
1209                                            $("#cboxClose").trigger("click");
1210                                        }
1211                                    }
1212                                });
1213                        }
1214                    });
1215            }
1216        } else {
1217            document.getElementById('listname').style.borderColor = "red";
1218            $(".help-block.empty-input").show();
1219            $.colorbox.resize();
1220        }
1221    },
1222    deletelistsDetails: function(wishlistdetails) {
1223        var listId = $(".js-selectedListId").val();
1224        $.ajax({
1225            type: 'POST',
1226            url: ACC.config.encodedContextPath + '/wishlist/removeWishlistDetails',
1227            data: {
1228                productIds: wishlistdetails.toString(),
1229                wishlistId: listId
1230            },
1231            success: function () {
1232                window.location.replace(ACC.config.encodedContextPath + '/wishlist/get?wishLisId='+ $(".js-selectedListId").val());
1233                //window.location.reload();
1234            },
1235            error: function () {
1236            }
1237        });
1238    },
1239    updateQueryStringParameter: function (uri, key, value) {
1240        var re = new RegExp("([?&])" + key + "=.*?(&|#|$)", "i");
1241        if( value === undefined ) {
1242            if (uri.match(re)) {
1243                return uri.replace(re, '$1$2');
1244            } else {
1245                return uri;
1246            }
1247        } else {
1248            if (uri.match(re)) {
1249                return uri.replace(re, '$1' + key + "=" + value + '$2');
1250            } else {
1251                var hash =  '';
1252                if( uri.indexOf('#') !== -1 ){
1253                    hash = uri.replace(/.*#/, '#');
1254                    uri = uri.replace(/#.*/, '');
1255                }
1256                var separator = uri.indexOf('?') !== -1 ? "&" : "?";
1257                return uri + separator + key + "=" + value + hash;
1258            }
1259        }
1260    },
1261
1262   bindImportList: function () {
1263        var importFile = null;
1264        var div = document.createElement('div');
1265        var isDragAndDropImport = (('draggable' in div) || ('ondragstart' in div && 'ondrop' in div)) && 'FormData' in window && 'FileReader' in window;
1266        if (isDragAndDropImport) {
1267            $(".js-importListWithoutDragAndDrop").addClass("hidden");
1268            var form = $("#importCSVListForm");
1269            form.on( 'drag dragstart dragend dragover dragenter dragleave drop', function( e )
1270            {
1271                e.preventDefault();
1272                e.stopPropagation();
1273            })
1274            .on( 'drop', function( e )
1275            {
1276                listImportFiles = e.originalEvent.dataTransfer.files;
1277                $.each(listImportFiles, function( i, file )
1278                {
1279                    importFile = file;
1280                });
1281                ACC.myList.validateListImport(importFile);
1282            });
1283
1284        } else {
1285            $(".js-importListWithDragAndDrop").addClass("hidden");
1286        }
1287
1288        $(document).on("click", '.js-import_myList', function () {
1289            ACC.myList.importListPopup();
1290        });
1291
1292        $(document).on("click", '.js-importListOpenFileDialog', function () {
1293            $('#importCSVListFile').click();
1294        });
1295
1296        $("#importCSVListFile").change( function() {
1297            listImportFiles = document.getElementById('importCSVListFile').files;
1298            $.each(listImportFiles, function( i, file )
1299            {
1300                importFile = file;
1301            });
1302            ACC.myList.validateListImport(importFile);
1303        });
1304
1305        $('.js-importListButton').click(function ()
1306        {
1307            var importFile = null;
1308            $.each(listImportFiles, function( i, file )
1309            {
1310                importFile = file;
1311            });
1312            var form = document.getElementById('importCSVListForm');
1313            var formData = new window.FormData(form);
1314            formData.append("csvFile", importFile);
1315            $.ajax({
1316                url: "/import/csv/importList",
1317                type: 'POST',
1318                data: formData,
1319                contentType: false,
1320                processData: false,
1321                success: function() {
1322                    $.colorbox.close();
1323                    window.location = "/wishlist/get";
1324                },
1325                error: function(jqXHR) {
1326                    ACC.myList.displayImportListError(jqXHR);
1327                }
1328            });
1329        });
1330
1331        $('.js-importListClear').click(function ()
1332        {
1333            $('.js-importListButton').attr("disabled", true);
1334            $('.js-importListInitial').removeClass('hidden');
1335            $('.js-importListSuccess').addClass('hidden');
1336            $('.js-importListError').addClass('hidden');
1337            $('.js-importListInstructions').removeClass('hidden');
1338            document.getElementById('importCSVListFile').value = [];
1339            $.colorbox.resize();
1340        });
1341    },
1342
1343    validateListImport: function (importedFile) {
1344        var form = document.getElementById('importCSVListForm');
1345        var formData = new window.FormData(form);
1346        formData.append("csvFile", importedFile);
1347        $.ajax({
1348            url: "/import/csv/validateListImport",
1349            type: 'POST',
1350            data: formData,
1351            contentType: false,
1352            processData: false,
1353            success: function() {
1354                $('.js-importListInitial').addClass('hidden');
1355                $('.js-importListError').addClass('hidden');
1356                $('.js-importListSuccess').removeClass('hidden');
1357                $('.js-importListInstructions').addClass('hidden');
1358                $('.js-importListFileName').text(importedFile.name);
1359                $('.js-importListButton').attr("disabled", false);
1360                $.colorbox.resize();
1361            },
1362            error: function(jqXHR) {
1363                ACC.myList.displayImportListError(jqXHR);
1364            }
1365        });
1366    },
1367
1368    displayImportListError: function (jqXHR) {
1369        var firstError = "";
1370        if (jqXHR.status == 400 && jqXHR.responseJSON) {
1371            var errors = jqXHR.responseJSON.split('|');
1372            if (errors.length > 0) {
1373                firstError = errors[0];
1374            }
1375        }
1376        if (firstError != "") {
1377            $('.js-importListErrorMessage').text(firstError);
1378        } else  {
1379            $('.js-importListErrorMessage').text($('.js-importListDefaultErrorMessage').text());
1380        }
1381        $('.js-importListInitial').addClass('hidden');
1382        $('.js-importListSuccess').addClass('hidden');
1383        $('.js-importListError').removeClass('hidden');
1384        $('.js-importListInstructions').removeClass('hidden');
1385        document.getElementById('importCSVListFile').value = [];
1386        $.colorbox.resize();
1387    },
1388
1389    importListPopup: function () {
1390        $.colorbox({
1391            inline: true,
1392            maxWidth: "95%",
1393            width: "570px",
1394            maxHeight: "99%",
1395            className: "purchaseAccountModal",
1396            title: "<h4 class=\"emp-pa-title\">Import List</h4>",
1397            close: "<img tabindex=\"1\" src=\"/_ui/responsive/common/images/list-close.svg\" />",
1398            href: ".importListDOM",
1399            onOpen: function () {
1400                $('.js-importListButton').attr("disabled", true);
1401                $('.js-importListInitial').removeClass('hidden');
1402                $('.js-importListSuccess').addClass('hidden');
1403                $('.js-importListError').addClass('hidden');
1404                $('.js-importListInstructions').removeClass('hidden');
1405                document.getElementById('importCSVListFile').value = [];
1406            }
1407        });
1408    },
1409};
1410
1411function saveWish(event) {
1412    ACC.myList.createNewList(event, "wishListPage");
1413}
1414
1415
1416
1417
1418

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.