1//THIS FILE IS FOR FUNCTIONALITY 2 3//Create namespace for app-level properties and methods 4window.App || (window.App = { CartItems: null }); 5var path = window.location.pathname; 6var IsSPRTagging = JSON.parse(SPRTagging.toLowerCase()); 7 8// "Macro" for document.getElementById 9function My$(e) { 10 return document.getElementById(e); 11} 12 13// Format the price above to USD using the locale, style, and currency. 14const USDollar = new Intl.NumberFormat('en-US', { 15 style: 'currency', 16 currency: 'USD', 17}); 18 19$(".SelectedProjectID").change(function () { 20 let selected = $(this).find(':selected').val(); 21 //var spilt = selected.split('~'); 22 let sku = $(this).data("sku"); 23 if (sku != undefined) { 24 $(`[id^="hdnProjectId_${sku}"]`).val(selected); 25 } 26}); 27 28$(".SelectedProjectIDItem").change(function () { 29 let selected = $(this).find(':selected').val(); 30 //var spilt = selected.split('~'); 31 let sku = $(this).data("sku"); 32 if (sku != undefined) { 33 $(`[id^="Items_${sku}__ProjectID_ProjectIDKey"]`).val(selected); 34 } 35}); 36 37$(".cartbtn").click(function (event) { 38 39 event.preventDefault(); // Prevent default form submission if applicable 40 41 /* 42 Required Parameters from DOM (Document Object Model) 43 1. SKU 44 2. Unit of Measure 45 3. Quantity 46 4. Line Commment 47 5. Project Id 48 6. HardSub SKU 49 */ 50 let CartItems = []; 51 let sku = $(this).data("sku"); 52 let uom = $(`[id^="hdnItemUOM_${sku}"]`).val() || ''; /* get Unit of Measure, it may not exist */ 53 let qty = $(`[id^="txtItemQty_${sku}"]`).val(); /* get Line Comment, it may not exist */ 54 if (IsSPRTagging) { 55 SPRCartType = $(this).data("type") ?? ""; 56 } 57 58 // validate the qty 59 qty = parseInt(qty); 60 if (isNaN(qty) || qty == 0) { 61 alert("Please enter a valid quantity."); 62 return false; 63 } 64 65 let comment = $(`[id^="txtItemComment_${sku}"]`).val() || ''; /* get Line Comment, it may not exist */ 66 //get the ItemPrice 67 let itemPrice = $(`[id^="hdnItemPrice_${sku}"]`).val() || ''; /* get the ItemPrice, it may not exist */ 68 69 //get the project id & desc 70 let pId = $(`[id^="hdnProjectId_${sku}"]`).val() || ''; /* get Project Id for the Respective Item, it may not exist */ 71 72 let hardSubNo = $(`[id^="hdnHardSubNo_${sku}"]`).val() || ''; /* get the HardSub SKU, it may not exist */ 73 74 let CartItem = { 75 sku: sku, 76 qty: parseInt(qty), 77 price: parseFloat(itemPrice), 78 uom: uom, 79 lineComment: comment, 80 projectID: pId, 81 HardSubSKU: hardSubNo /* This field is not part of the CartItem Class - It is used for the Hardsub notification message for Accessories in the JavaScript AddToCart function below */ 82 }; 83 84 CartItems.push(CartItem); 85 86 //Do not show accessory popup on the home page 87 let ShowAccessories = false; 88 if (location.pathname != "/") { 89 if (location.pathname.indexOf("/home") != 0) { 90 ShowAccessories = true; 91 } 92 } 93 94 AddToCart(CartItems, ShowAccessories); 95}); 96 97let AddToCart = async function (CartItems, ShowAccessories) { 98 99 if (CartItems.length == 0) { return; } 100 101 try { 102 // Disable the entire page (replace with specific selectors if needed) 103 $("body").css("pointer-events", "none"); // Using CSS 104 105 // Optionally, display a loading indicator 106 $("#loadingIndicator").show(); 107 108 const response = await $.ajax({ 109 type: "POST", 110 url: "/ajax/ajaxcart?handler=AddItems", 111 data: JSON.stringify(CartItems), 112 headers: { 113 "XSRF-TOKEN": $('input:hidden[name="__RequestVerificationToken"]').val() 114 } 115 }); 116 117 // Re-enable the page 118 $("body").css("pointer-events", "auto"); 119 120 // Optionally, hide the loading indicator 121 $("#loadingIndicator").hide(); 122 123 if (ShowAccessories) { 124 let mainSKU = CartItems[0].sku; 125 let hardSubSKU = CartItems[0].HardSubSKU; 126 if (hardSubSKU != "") { 127 mainSKU = hardSubSKU; 128 } 129 AccessoryPopup(mainSKU); 130 } 131 132 let notificationDuration = 3000; 133 let message = "Your cart has been updated."; 134 let substitution_nmessage = ''; 135 for (const item of CartItems) { 136 const sku = item.sku; 137 const hardSubSKU = item.HardSubSKU; 138 139 if (hardSubSKU) { 140 notificationDuration = 5000; 141 substitution_nmessage += `${sku} has been substituted with ${hardSubSKU}.\n`; 142 } 143 } 144 145 if (substitution_nmessage) { 146 message = substitution_nmessage; 147 } 148 149 $(".cartsummarypopup").html(response); 150 151 // Check the Error Message from Response 152 // Create a temporary element to hold the HTML - the div holds the message 153 let tempElement = $("<div>").html(response); 154 155 // Find the hidden input element by ID within the temporary element 156 let BCErrorhiddenInput = tempElement.find("#BCError"); 157 158 // Get the value attribute of the hidden input 159 let errorMessage = BCErrorhiddenInput.val(); 160 161 if (pageName.toLowerCase == "cart") { 162 location.reload(); 163 } 164 // document.getElementById("cartNavbarPopup").click(); 165 166 let notification_status = "success"; 167 if (errorMessage.length > 0) { 168 message = errorMessage; 169 notification_status = "danger"; 170 notificationDuration = 5000; 171 } 172 else { 173 if (IsSPRTagging) { 174 let productshiddenInput = tempElement.find("#SPRTaggingProductArray"); 175 let products = JSON.parse(productshiddenInput.val()); 176 createDigitalDataEventLayer(products, "addToCart", SPRCartType); 177 } 178 } 179 180 //notification 181 let config = { 182 positionY: "top", 183 positionX: "center" 184 }; 185 186 mkNotifications(config); 187 let options = { 188 status: notification_status, 189 icon: { 190 class: 'fa fa-shopping-cart' 191 }, 192 sound: false, 193 duration: notificationDuration 194 }; 195 196 mkNoti( 197 "Cart", 198 message, 199 options 200 ); 201 202 } catch (error) { 203 204 // Re-enable the page 205 $("body").css("pointer-events", "auto"); 206 207 // Optionally, hide the loading indicator 208 $("#loadingIndicator").hide(); 209 210 console.error("An error occurred:", error); 211 //throw error; 212 } 213} 214 215function UpdateCartSummary() { 216 $.ajax({ 217 type: "POST",
218 url: "/ajax/ajaxcart?handler=Cartsummary&path=" + location.pathname, 219 beforeSend: function (xhr) { 220 xhr.setRequestHeader("XSRF-TOKEN", 221 $('input:hidden[name="__RequestVerificationToken"]').val()); 222 }, 223 success: function (response) { 224 $(".cartsummarypopup").html(response); 225 }, 226 failure: function (response) { 227 alert(response); 228 } 229 }); 230} 231 232function remove(span) { 233 let itemid = $(span).data('id'); 234 let data = { ItemID: itemid }; 235 $.ajax({ 236 type: "POST", 237 url: "/ajax/ajaxcart?handler=DeleteCartItem&ItemID=" + itemid, 238 data: JSON.stringify(data), 239 beforeSend: function (xhr) { 240 xhr.setRequestHeader("XSRF-TOKEN", 241 $('input:hidden[name="__RequestVerificationToken"]').val()); 242 }, 243 contentType: "application/x-www-form-urlencoded", 244 success: function (response) { 245 $(".cartsummarypopup").html(response); 246 247 // Check the Error Message from Response 248 // Create a temporary element to hold the HTML 249 let tempElement = $("<div>").html(response); 250 251 // Find the hidden input element by ID within the temporary element 252 let BCErrorhiddenInput = tempElement.find("#BCError"); 253 254 // Get the value attribute of the hidden input 255 let errorMessage = BCErrorhiddenInput.val(); 256 257 if (path.toLocaleLowerCase() == "/cart/" && 258 errorMessage.trim().includes("Resource not found for the segment")) { 259 location.reload(); 260 } 261 262 let notificationDuration = 5000; 263 let message = ""; 264 let notification_status = "success"; 265 if (errorMessage.length > 0) { 266 message = errorMessage; 267 notification_status = "danger"; 268 } 269 else { 270 if (IsSPRTagging) { 271 let productshiddenInput = tempElement.find("#SPRTaggingProductArray"); 272 let products = JSON.parse(productshiddenInput.val()); 273 createDigitalDataEventLayer(products, "removeFromCart", "cart"); 274 } 275 } 276 277 if (message.length > 0) { 278 //notification 279 let config = { 280 positionY: "top", 281 positionX: "center" 282 }; 283 284 mkNotifications(config); 285 let options = { 286 status: notification_status, 287 icon: { 288 class: 'fa fa-shopping-cart' 289 }, 290 sound: false, 291 duration: notificationDuration 292 }; 293 294 mkNoti( 295 "Cart", 296 message, 297 options 298 ); 299 } 300 301 if (path.toLocaleLowerCase() == "/cart/" && message.length == 0) { 302 $("#tr_" + itemid).remove(); 303 if ($(".cartproduct").length == 0) { 304 $(".cartpanel").hide(); 305 var htmlstring = "<div class=\"mt-5 d-sm-block d-none text-center\"><span>Your Shopping Cart is Empty</span></div>"; 306 $("#emptydiv").html(htmlstring); 307 } 308 $("#TotalPrice").text($("#cart-total-price").text()); 309 } 310 document.getElementById("cartNavbarPopup").click(); 311 }, 312 failure: function (response) { 313 } 314 }); 315} 316 317// Search page Filters - Start 318 319// for Category and Brand filter for both Multi-Select and not Multi-Select 320$(".Criteria").click(function () { 321 let boolMultiSelectParametrics = (document.getElementById("hdnMultiSelectParametrics").value.toLowerCase() == "true"); 322 let url = new URL(location.href); 323 let param = ""; 324 let boolIsMulti = $(this).data('ismulti').toLowerCase() == "true"; 325 let strGroupName = ($(this).data('gname') != undefined ? $(this).data('gname').toLowerCase() : this.parentElement.parentElement.querySelector(".f-header").innerText.toLowerCase()); 326 let GroupName = ($(this).data('gname') != undefined ? $(this).data('gname') : this.parentElement.parentElement.querySelector(".f-header").innerText); 327 let refine = JSON.parse(url.searchParams.get('refine')) ?? []; 328 // is search category
329 let catfilter = ""; 330 if (boolMultiSelectParametrics && boolIsMulti && this.className.indexOf("btn") == -1) { 331 return; 332 } 333 url.searchParams.delete("p"); 334 335 if (appliedfilter.IsSearchtoCategory) { 336 for (var i = 0; i < appliedfilter.CategoryFilters.length; i++) { 337 catfilter += appliedfilter.CategoryFilters[i].CategoryID + ","; 338 } 339 catfilter = catfilter.replace(/,(\s+)?$/, ''); 340 } 341 342 if (strGroupName == "category") { 343 344 if (boolMultiSelectParametrics && boolIsMulti) { 345 // loop for multiple select - Start 346 url.searchParams.delete("cat"); 347 let filterslist = this.parentElement.querySelector(".filters").children; 348 for (let i = 0; i < filterslist.length; i++) { 349 let li = filterslist[i]; 350 if (li.className.trim() == "Criteria" || li.className.trim() == "Criteria catlimore") { 351 let isChecked = li.querySelector(".custom-control-input").checked; 352 if (isChecked) { 353 let catid = li.dataset["filterid"]; 354 param += catid + ","; 355 } 356 } 357 } 358 param = param.substring(0, param.length - 1); 359 // loop for multiple select - End 360 } 361 else { 362 param = $(this).data('filterid'); 363 if (IsSPRTagging) { 364 let obj = {}; 365 obj.type = GroupName; 366 obj.value = $(this).find(".desc").text().trim().split("(")[0].trim(); 367 refine.push(obj); 368 } 369 } 370 if (param != "") { 371 url.searchParams.set('cat', param); 372 if (refine.length > 0) { 373 url.searchParams.set('refine', JSON.stringify(refine)); 374 } 375 } 376 //location.replace(url); 377 location.href = url; 378 } 379 else if (strGroupName == "brand") { 380 if (boolMultiSelectParametrics && boolIsMulti) { 381 // loop for multiple select - Start 382 url.searchParams.delete("br"); 383 let filterslist = this.parentElement.querySelector(".filters").children; 384 for (let i = 0; i < filterslist.length; i++) { 385 let li = filterslist[i]; 386 if (li.className.trim() == "Criteria" || li.className.trim() == "Criteria brlimore") { 387 let isChecked = li.querySelector(".custom-control-input").checked; 388 if (isChecked) { 389 url.searchParams.append('br', li.dataset["filterid"]); 390 } 391 } 392 } 393 param = param.substring(0, param.length - 1); 394 // loop for multiple select - End 395 } 396 else { 397 url.searchParams.delete("br"); 398 param = $(this).data('filterid'); 399 if (IsSPRTagging) { 400 let obj = {}; 401 obj.type = GroupName; 402 obj.value = $(this).find(".desc").text().trim().split("(")[0].trim(); 403 refine.push(obj); 404 } 405 } 406 //if (param != "") { 407 // url.searchParams.set('br', param); 408 //} 409 if (catfilter != "") { 410 url.searchParams.set('cs', true); 411 url.searchParams.set('cat', catfilter); 412 if (refine.length > 0) { 413 url.searchParams.set('refine', JSON.stringify(refine)); 414 } 415 } 416 location.href = url; 417 } 418 else if (strGroupName == "manufacturer") { 419 if (boolMultiSelectParametrics && boolIsMulti) { 420 // loop for multiple select - Start 421 url.searchParams.delete("mf"); 422 let filterslist = this.parentElement.querySelector(".filters").children; 423 for (let i = 0; i < filterslist.length; i++) { 424 let li = filterslist[i]; 425 if (li.className.trim() == "Criteria" || li.className.trim() == "Criteria brlimore") { 426 let isChecked = li.querySelector(".custom-control-input").checked; 427 if (isChecked) { 428 let manufacturer = li.dataset["filterid"]; 429 param += manufacturer + ","; 430 } 431 } 432 } 433 param = param.substring(0, param.length - 1); 434 // loop for multiple select - End 435 } 436 else { 437 url.searchParams.delete("mf"); 438 param = $(this).data('filterid'); 439 if (IsSPRTagging) { 440 let obj = {}; 441 obj.type = GroupName; 442 obj.value = $(this).find(".desc").text().trim().split("(")[0].trim(); 443 refine.push(obj); 444 } 445 } 446 if (refine.length > 0) { 447 url.searchParams.set('refine', JSON.stringify(refine)); 448 } 449 if (param != "") { 450 url.searchParams.set('mf', param); 451 } 452 if (catfilter != "") { 453 url.searchParams.set('cs', true); 454 url.searchParams.set('cat', catfilter); 455 } 456 location.href = url; 457 } 458}); 459// Search page Filters - End 460 461function RemoveURLParameter(url, parameter) { 462 //prefer to use l.search if you have a location/link object 463 let urlparts = url.split('?'); 464 if (urlparts.length >= 2) { 465 466 let prefix = encodeURIComponent(parameter) + '='; 467 let pars = urlparts[1].split(/[&;]/g); 468 469 //reverse iteration as may be destructive 470 for (let i = pars.length; i-- > 0;) { 471 //idiom for string.startsWith 472 if (pars[i].lastIndexOf(prefix, 0) !== -1) { 473 pars.splice(i, 1); 474 } 475 } 476 477 return urlparts[0] + (pars.length > 0 ? '?' + pars.join('&') : ''); 478 } 479 return url; 480} 481 482// Favorite List page - Start 483$(".copylist").click(function () { 484 let id = $(this).data('id'); 485 let name = $(this).data('name'); 486 let type = $(this).data('type'); 487 488 $(".btn-copy-list").attr("value", id); 489 document.getElementById("modeldesc").innerText = name + " - " + type; 490}); 491 492//$(".showfavorites").click(function () { 493$(document).on("click", ".showfavorites", function () { 494 495 let sku = $(this).data('sku'); 496 let lineComment = $(`[id^="txtItemComment_${sku}"]`).val() || ''; /* get Line Comment, it may not exist */ 497 498 let listid = $(this).data('listid'); //if list > 0 we add an item to the favorite list 499 if (listid == undefined) { 500 listid = "00000000-0000-0000-0000-000000000000"; //Do not add an item, just show the list 501 } 502 503 let favtype = "None"; 504 let list_name = "";
505 let create = $(this).data('create'); //if list > 0 we add an item to the favorite list 506 if (create == undefined) { 507 create = false; //Do not create new list 508 } else if (create) { 509 list_name = $(`[id^="AddFavListName"]`).val(); 510 favtype = $('#SelectedPopupFavListType :selected').text(); 511 if (list_name == "") { 512 return; 513 } 514 } 515 516 let add = $(this).data('add'); //if list > 0 we add an item to the favorite list 517 if (add == undefined) { 518 add = false; //Do not create new list 519 } 520 521 let favListObj = {}; 522 favListObj.favoriteListId = listid; 523 favListObj.name = list_name; 524 favListObj.type = favtype; 525 favListObj.create = create; 526 527 let favItemObj = {}; 528 favItemObj.itemNo = sku; 529 favItemObj.uom = $(this).data('uom'); 530 favItemObj.comment = lineComment; 531 favItemObj.add = add; 532 533 let favItemArray = []; 534 favItemArray.push(favItemObj); 535 536 favListObj.favoriteItems = favItemArray; 537 538 $.ajax({ 539 type: "POST", 540 url: "/ajax/ajaxcommon?handler=ShowFavorites", 541 data: JSON.stringify(favListObj), 542 beforeSend: function (xhr) { 543 xhr.setRequestHeader("XSRF-TOKEN", 544 $('input:hidden[name="__RequestVerificationToken"]').val()); 545 $("#MainModal .modal-title").html("Loading Favorites List"); 546 $("#MainModal .modal-body").html('<div style="text-align: -webkit-center;"><div class="loadingIndicator"></div></div>'); 547 }, 548 //contentType: "application/x-www-form-urlencoded", 549 //dataType: "json", 550 success: function (response) { 551 $("#MainModal").find(".modal-dialog").removeClass("modal-lg").addClass("modal-md"); 552 $("#MainModal .modal-title").html("Add " + sku + " to Favorites"); 553 $("#MainModal .modal-body").html(response); 554 555 if (IsSPRTagging && add) { 556 let products = []; 557 let product = {}; 558 product.productID = sku; 559 product.sku = sku; 560 product.inventoryStatus = $("#inventory_" + sku).text().trim(); 561 562 let productInfoWrapper = { 563 productInfo: product 564 }; 565 products.push(productInfoWrapper); 566 567 createDigitalDataEventLayer(products, "addToFavorites", "favorites"); 568 } 569 570 }, 571 failure: function (response) { 572 }, 573 error: function (response) { 574 console.log("ShowFavorites Error Log"); 575 alert(response.responseText); 576 } 577 }); 578}); 579 580// Favorite List page - End 581 582// Compare - Start 583 584function ShowComparedProducts() { 585 //... 586 var storedProducts = JSON.parse(localStorage.getItem("ComparedProducts")); 587 588 let content = ""; 589 if (storedProducts !== undefined && storedProducts !== null) { 590 if (storedProducts && storedProducts.length > 0) { 591 $('#comparesection').show(); 592 593 jQuery.each(storedProducts, function (index, item) { 594 content += "<div class=\"dropdown-item\"><div class=\"cart-item d-flex flex-row\"><img class=\"lazy\" src=\"" 595 + item.Imageurl + 596 "\" width=\"30\" height=\"30\"><div class=\"item-details\"><p class=\"item-title\">" 597 + item.Description + 598 "</p><div class=\"item-quantity\"><small class=\"text-muted item-quant\">" 599 + item.SKU + 600 "</small><small class=\"text-right f-600\">" 601 + item.Price + 602 "</small></div></div><div class=\"remove-btn\" onclick=\"DeleteComparedProducts('" 603 + item.SKU + 604 "')\"><i class=\"fa fa-close\"></i></div></div></div>"; 605 $(`[id^="checkbox_${item.SKU}"]`).prop('checked', true); 606 }); 607 let count = storedProducts.length; 608 if (count > 1) { 609 $('#compareDropdown span').text("Click to compare (" + count + " items)"); 610 } else { 611 content = ""; 612 $('#comparesection').hide(); 613 } 614 } 615 else { 616 content = ""; 617 $('#comparesection').hide(); 618 } 619 } 620 $('#comparesection').find('#comapareditems').html(content); 621} 622 623function DeleteComparedProducts(sku) { 624 var storedProducts = JSON.parse(localStorage.getItem("ComparedProducts")); 625 $(`[id^="checkbox_${sku}"]`).prop('checked', false); 626 if (storedProducts != null) { 627 if (storedProducts.length > 0) { 628 let array = removeByAttr(storedProducts, 'SKU', sku); 629 localStorage.setItem("ComparedProducts", JSON.stringify(array)); 630 ShowComparedProducts(); 631 } 632 } 633} 634 635// redirect to compare page 636$(".comparepage").on('click', function () { 637 var storedProducts = JSON.parse(localStorage.getItem("ComparedProducts")); 638 let skus = Array.prototype.map.call(storedProducts, function (item) { return item.SKU; }).join(","); 639 if (skus.split(",").length < 2) { 640 alert("Please check 2 to 4 items to compare."); 641 return; 642 } 643 //localStorage.removeItem("ComparedProducts"); 644 //$('#comaparetable').find('tbody').html(""); 645 //$('#comparesection').hide(); 646 //$('input[type=checkbox][id*=checkbox_]').each(function () { 647 // $(this).prop('checked', false); 648 //}); 649 location.href = location.origin + "/compare/" + skus; 650}); 651 652// Checkbox enable/disable 653$(".compare").change(function () { 654 var storedProducts = JSON.parse(localStorage.getItem("ComparedProducts")); 655 656 if (storedProducts != null) { 657 let itemcount = storedProducts.length; 658 if (itemcount >= 4) { 659 this.checked = false;
660 alert("Please check 2 to 4 items to compare."); 661 return; 662 } 663 } 664 665 let id = $(this).attr('id'); 666 let sku = id.split("_")[1]; 667 if (this.checked) { 668 if (storedProducts != null) { 669 if (storedProducts.some(prod => prod.Item === sku)) { 670 alert("Item exsist in compare list."); 671 return; 672 } 673 } 674 let Imageurl = $(`[id^="ItemImg_${sku}"]`).attr('src'); 675 let Description = $(`[id^="Description_${sku}"]`).text(); 676 let Price = $(`[id^="hdnItemPrice_${sku}"]`).val(); 677 let Uom = $(`[id^="hdnItemUOM_${sku}"]`).val(); 678 679 let products = [ 680 { 681 "Imageurl": Imageurl, 682 "SKU": sku, 683 "Description": Description, 684 "Price": Price + "/" + Uom 685 } 686 ]; 687 688 var storedProducts = JSON.parse(localStorage.getItem("ComparedProducts")); 689 if (storedProducts !== undefined && storedProducts !== null) { 690 if (storedProducts.length < 4) { 691 Array.prototype.push.apply(products, storedProducts); 692 localStorage.setItem("ComparedProducts", JSON.stringify(products)); 693 } 694 } 695 else { 696 localStorage.setItem("ComparedProducts", JSON.stringify(products)) 697 } 698 ShowComparedProducts(); 699 $('#comapareditems').show(); 700 } 701 else { // if Unchecked or Disable the check box remove the compared items from local storage 702 let array = removeByAttr(storedProducts, 'SKU', sku); 703 localStorage.setItem("ComparedProducts", JSON.stringify(array)); 704 ShowComparedProducts(); 705 } 706}); 707 708var removeByAttr = function (arr, attr, value) { 709 var i = arr.length; 710 while (i--) { 711 if (arr[i] 712 && arr[i].hasOwnProperty(attr) 713 && (arguments.length > 2 && arr[i][attr] === value)) { 714 715 arr.splice(i, 1); 716 717 } 718 } 719 return arr; 720} 721 722// Compare - End 723 724var clicked = false; 725$(document).on("click", ".btncheckall", function () { 726 $(".checkitem").prop("checked", !clicked); 727 clicked = !clicked; 728 this.innerHTML = clicked ? 'Uncheck All Items' : 'Check All Items'; 729}); 730 731// Accessory Popup - Start 732 733function AccessoryPopup(sku) { 734 $.ajax({ 735 type: "POST", 736 url: "/ajax/ajaxcommon?handler=GetAccessories", 737 data: { "sku": sku, "pageName": pageName }, 738 beforeSend: function (xhr) { 739 xhr.setRequestHeader("XSRF-TOKEN", 740 $('input:hidden[name="__RequestVerificationToken"]').val()); 741 $("#MainModal .modal-body").html('<div style="text-align: -webkit-center;"><div class="loadingIndicator"></div></div>'); 742 }, 743 success: function (response) { 744 if (response.length > 0) { 745 $("#MainModal .modal-content").css("margin", "4.50rem auto 1.75rem"); 746 $("#MainModal").modal('show'); 747 748 $("#MainModal .modal-title").html("Accessories for " + sku); 749 $("#MainModal .modal-body").html(response); 750 LoadPrice(getModelPopupItems()); 751 $("#MainModal").find(".modal-dialog").removeClass("modal-md").addClass("modal-lg"); 752 //$("#MainModal").modal('show'); 753 } 754 } 755 }); 756} 757 758function getModelPopupItems() { 759 let Items = []; 760 $.each($(".itempopup"), function (c_index, container) { 761 let item = {}; 762 let index = $(container).data("index"); 763 let sku = $(container).data("sku") ?? ""; 764 let qty = $(container).find(`[id^="txtQty_${sku}"]`).val() ?? 1; 765 let sellprice = $(container).find(`[id^="hdnItemPrice_${sku}"]`).val() ?? 0; 766 let uom = $(container).find(`[id^="hdnUOM_${sku}"]`).val() ?? ""; 767 let projectId = $(container).find(`[id^="hdnProjectId_${sku}"]`).val() ?? ""; 768 let cartId = $(container).find(`[id^="hdnCartId_${sku}"]`).val() ?? 0; 769 let functionalOrigin = $(container).find(`[id^="hdnFunctionalOrigin_${sku}"]`).val() ?? ""; 770 let hardSubNo = $(container).find(`[id^="hdnHardSubNo_${sku}"]`).val() ?? ""; 771 772 item.checked = $(container).find("input[type=\"checkbox\"]").is(':checked') 773 item.sku = sku.trim(); 774 item.quantity = (parseInt(qty) == NaN ? 0 : parseInt(qty)); 775 item.sellPrice = parseFloat(sellprice); 776 item.uom = uom; 777 item.projectId = projectId; 778 item.cartitemID = cartId; 779 item.sequenceIndex = index; 780 item.lineComment = ""; 781 item.functionalOrigin = functionalOrigin; 782 item.hardSubstituteNo = hardSubNo; 783 Items.push(item); 784 }); 785 return Items; 786} 787 788$(document).on("click", ".accessory", function () { 789 let sku = $(this).data('sku'); 790 AccessoryPopup(sku); 791}); 792 793$(document).on("click", ".softsubspop", function () {
794 let cartitemid = $(this).data('cartitemid'); 795 let sku = $(this).data('sku'); 796 let qty = $("#txtItemQty_" + cartitemid).val(); 797 if (qty == undefined) { 798 qty = $(`[id^="txtItemQty_${sku}"]`).val(); 799 } 800 SoftSubPopup(sku, cartitemid, qty); 801}); 802 803$(document).on("click", ".SelectSoftSub", function () { 804 let cartitemid = $(this).data('cartitemid'); 805 let subsku = $(this).data('sku'); 806 let uom = $(this).data('uom'); 807 let qty = $(`[id^="txt_SoftSubQty_${subsku}"]`).val(); 808 let sellprice = $(`[id^="hdnItemPrice_${subsku}"]`).val(); 809 let obj = {}; 810 obj.CartitemId = cartitemid; 811 obj.sku = subsku; 812 obj.uom = uom; 813 obj.Price = parseFloat(sellprice); 814 obj.qty = parseInt(qty); 815 816 $.ajax({ 817 type: "POST", 818 url: "/ajax/ajaxcommon?handler=SelectSoftSub", 819 data: JSON.stringify(obj), 820 beforeSend: function (xhr) { 821 xhr.setRequestHeader("XSRF-TOKEN", 822 $('input:hidden[name="__RequestVerificationToken"]').val()); 823 $("#MainModal .modal-body").html('<div style="text-align: -webkit-center;"><div class="loadingIndicator"></div></div>'); 824 }, 825 success: function (response) { 826 if (response) { 827 window.location.reload(); 828 } 829 } 830 }); 831 832}); 833 834function SoftSubPopup(sku, cartItemId, qty) { 835 836 $.ajax({ 837 type: "POST", 838 url: "/ajax/ajaxcommon?handler=GetSoftSubs", 839 data: { 840 "sku": sku, "cartItemId": cartItemId, "qty": qty, "mode": pageName 841 }, 842 beforeSend: function (xhr) { 843 xhr.setRequestHeader("XSRF-TOKEN", 844 $('input:hidden[name="__RequestVerificationToken"]').val()); 845 $("#MainModal .modal-body").html('<div style="text-align: -webkit-center;"><div class="loadingIndicator"></div></div>'); 846 }, 847 success: function (response) { 848 if (response.length > 0) { 849 $("#MainModal").modal('show'); 850 } 851 $("#MainModal .modal-title").html("Substitutes for " + sku); 852 $("#MainModal .modal-body").html(response); 853 LoadPrice(getModelPopupItems()); 854 $("#MainModal").find(".modal-dialog").removeClass("modal-md").addClass("modal-lg"); 855 //$("#MainModal").modal('show'); 856 } 857 }); 858} 859 860$(document).on("click", ".replaceSoftSub", function () { 861 let sku = $(this).data('sku'); 862 let quantity = $(this).data('quantity'); 863 let cartitemid = $(this).data('cartitemid'); 864 SoftSubPopup(sku, quantity, cartitemid); 865}); 866 867$(document).on("click", ".accessoriesaddtocart", function () { 868 869 let Items = getModelPopupItems(); 870 871 let CheckedItems = Items.filter(function (item) { 872 return item.checked; 873 }); 874 875 if (CheckedItems.length == 0) { 876 //notification 877 let config = { 878 positionY: "top", 879 positionX: "center" 880 }; 881 882 mkNotifications(config); 883 let options = { 884 status: "warning", 885 icon: { 886 class: 'fa fa-shopping-cart' 887 }, 888 sound: false, 889 duration: 3000 890 }; 891 892 mkNoti( 893 "Cart", 894 "Please check one or more items to add to the cart.", 895 options 896 ); 897 } else { 898 let CartItems = []; 899 let i = 0; 900 901 for (i = 0; i < CheckedItems.length; i++) { 902 let CartItem = { 903 sku: CheckedItems[i].sku, 904 qty: parseInt(CheckedItems[i].quantity), 905 price: parseFloat(CheckedItems[i].sellPrice), 906 uom: CheckedItems[i].uom, 907 lineComment: CheckedItems[i].lineComment, 908 projectID: CheckedItems[i].projectId, 909 HardSubSKU: CheckedItems[i].hardSubstituteNo /* For Hardsub notification message */ 910 }; 911 CartItems.push(CartItem); 912 } 913 if (JSON.parse(SPRTagging.toLowerCase())) { 914 SPRCartType = "accessories_popup"; 915 } 916 let ShowAccessories = false; 917 AddToCart(CartItems, ShowAccessories); 918 $("#MainModal").modal('hide'); 919 if (path.indexOf('/cart/') == 0) { 920 setTimeout(() => { 921 location.reload(); 922 }, 2000) 923 } 924 } 925}); 926 927// Accessory Popup - End 928 929// Apply / Remove Coupon - Start 930 931$(document).on("click", "button[name = 'Model.BtnCoupon']", function () { 932 933 let htmlString = "<div style=\"text-align: -webkit-center;\"><div class=\"loadingIndicator\" style=\"height: 65px;\"></div></div>"; 934 $(".error").html(htmlString); 935 936 if ($("#Coupon_couponCode").val() == '') { 937 htmlString = "<small class='text-danger'>Enter Valid Coupon</small>" 938 $(".error").html(htmlString); 939 return; 940 } 941 let ServiceRequest = ""; 942 if ($(this).text().trim() == "Apply") { 943 ServiceRequest = "applyCoupon"; 944 } else if ($(this).text().trim() == "Remove") { 945 ServiceRequest = "unApplyCoupon"; 946 } else { 947 htmlString = "<small class='text-danger'>Invalid button.</small>" 948 $(".error").html(htmlString); 949 return; 950 } 951 952 let obj = {};
953 obj.value = ServiceRequest; 954 obj.coupon_Code = $('#Coupon_CouponCode').val(); 955 956 $.ajax({ 957 type: "POST", 958 url: "/ajax/ajaxcommon?handler=Coupon", 959 data: JSON.stringify(obj), 960 beforeSend: function (xhr) { 961 xhr.setRequestHeader("XSRF-TOKEN", 962 $('input:hidden[name="__RequestVerificationToken"]').val()); 963 }, 964 success: function (response) { 965 $(".error").empty(); 966 $("#ordersummaryprice").html(response); 967 } 968 }); 969}); 970 971// Apply / Remove Coupon - End 972 973// Apply or Unapply Assembly Charge - Start 974 975$('input[type="radio"][name="SelectedAssemblyCharge"]').on('change', function () { 976 977 let obj = {}; 978 obj.id = $("#BCOrder_id").val(); 979 obj.value = $(this).val(); // Get the selected radio button value 980 981 // Disable the entire page (replace with specific selectors if needed) 982 $("body").css("pointer-events", "none"); // Using CSS 983 984 // Optionally, display a loading indicator 985 $("#loadingIndicator").show(); 986 987 $.ajax({ 988 type: "POST", 989 url: "/ajax/ajaxcommon?handler=AssemblyCharge", 990 data: JSON.stringify(obj), 991 beforeSend: function (xhr) { 992 xhr.setRequestHeader("XSRF-TOKEN", 993 $('input:hidden[name="__RequestVerificationToken"]').val()); 994 }, 995 success: function (response) { 996 $(".error").empty(); 997 $("#ordersummaryprice").html(response); 998 999 // Re-enable the page 1000 $("body").css("pointer-events", "auto"); 1001 1002 // Optionally, hide the loading indicator 1003 $("#loadingIndicator").hide(); 1004 1005 }, 1006 error: function (XMLHttpRequest, textStatus, errorThrown) { 1007 console.log(textStatus); 1008 1009 // Re-enable the page 1010 $("body").css("pointer-events", "auto"); 1011 1012 // Optionally, hide the loading indicator 1013 $("#loadingIndicator").hide(); 1014 1015 } 1016 }); 1017 // Add your logic here (e.g., enable/disable, update interface, etc.) 1018}); 1019 1020 1021// Apply or Unapply Assembly Charge - End 1022 1023 1024 1025async function GetBCPrice(itemList) { 1026 let responseValue = null; 1027 let myPromise = new Promise(function (resolve) { 1028 $.ajax({ 1029 type: "POST", 1030 url: "/ajax/ajaxcommon?handler=GetBCPrice", 1031 data: JSON.stringify(itemList), 1032 dataType: "json", 1033 beforeSend: function (xhr) { 1034 xhr.setRequestHeader("XSRF-TOKEN", 1035 $('input:hidden[name="__RequestVerificationToken"]').val()); 1036 }, 1037 success: function (response) { 1038 resolve(response); 1039 //$("#MainModal").modal('hide'); 1040 } 1041 }); 1042 }); 1043 responseValue = await myPromise; 1044 return responseValue; 1045} 1046 1047async function GetInventory(itemList) { 1048 return new Promise(function (resolve, reject) { 1049 $.ajax({ 1050 type: "POST", 1051 url: "/ajax/ajaxcommon?handler=GetInventory", 1052 data: JSON.stringify(itemList), 1053 dataType: "json", 1054 beforeSend: function (xhr) { 1055 xhr.setRequestHeader("XSRF-TOKEN", 1056 $('input:hidden[name="__RequestVerificationToken"]').val()); 1057 }, 1058 success: function (response) { 1059 resolve(response); 1060 }, 1061 error: function (xhr, status, error) { 1062 reject(error || status); 1063 } 1064 }); 1065 }); 1066} 1067 1068async function GetBCItemMessage(itemList) { 1069 let responseValue = null; 1070 let myPromise = new Promise(function (resolve) { 1071 $.ajax({ 1072 type: "POST", 1073 url: "/ajax/ajaxcommon?handler=GetBCItemMessage", 1074 data: JSON.stringify(itemList), 1075 dataType: "json", 1076 beforeSend: function (xhr) { 1077 xhr.setRequestHeader("XSRF-TOKEN", 1078 $('input:hidden[name="__RequestVerificationToken"]').val()); 1079 }, 1080 success: function (response) { 1081 resolve(response); 1082 //$("#MainModal").modal('hide'); 1083 } 1084 }); 1085 }); 1086 responseValue = await myPromise; 1087 return responseValue; 1088} 1089 1090function GetItemsDetails() { 1091 let Items = []; 1092 $.each($(".itemcard"), function (c_index, container) { 1093 let item = {}; 1094 let postfix = ""; 1095 let cart_item_id = $(container).data("cartitemid") ?? ""; 1096 let sku = $(container).find(".itemsku").text().trim() ?? ""; 1097 if (typeof pageName === 'undefined') { 1098 pageName = ""; 1099 } 1100 if (pageName.toLowerCase() == "cart") { 1101 postfix = cart_item_id; 1102 } else { 1103 postfix = sku; 1104 }
1105 let qty = $(container).find(`[id^="txtItemQty_${postfix}"]`).val() ?? 1; 1106 let lineComment = $(container).find(`[id^="txtItemComment_${postfix}"]`).val() ?? ""; 1107 let sellprice = $(container).find(`[id^="hdnItemPrice_${postfix}"]`).val() ?? 0; 1108 let uom = $(container).find(`[id^="hdnItemUOM_${postfix}"]`).val() ?? ""; 1109 let projectId = $(container).find(`[id^="hdnProjectId_${postfix}"]`).val() ?? ""; 1110 let cartId = $(container).find(`[id^="hdnCartId_${postfix}"]`).val() ?? 0; 1111 let index = $(container).find(`[id^="hdnIndex_${postfix}"]`).val() ?? 0; 1112 let functionalOrigin = $(container).find(`[id^="hdnFunctionalOrigin_${postfix}"]`).val() ?? ""; 1113 let hardSubNo = $(container).find(`[id^="hdnHardSubNo_${postfix}"]`).val() ?? ""; 1114 let sprContent = $(container).find(`[id^="hdnSprContent_${postfix}"]`).val() ?? "false"; 1115 let bcInventory = $(container).find(`[id^="hdnbcInventory_${postfix}"]`).val() ?? 0; 1116 let essInventory = $(container).find(`[id^="hdnessInventory_${postfix}"]`).val() ?? 0; 1117 1118 item.checked = $(container).find("input[type=\"checkbox\"]").is(':checked'); 1119 item.sku = sku.trim(); 1120 item.quantity = (parseInt(qty) == NaN ? 0 : parseInt(qty)); 1121 item.linecomment = lineComment; 1122 item.sellPrice = parseFloat(sellprice); 1123 item.uom = uom; 1124 item.projectId = projectId; 1125 item.cartitemID = cartId; 1126 item.sequenceIndex = index; 1127 item.functionalOrigin = functionalOrigin; 1128 item.hardSubstituteNo = hardSubNo; 1129 item.sprContent = sprContent; 1130 item.bcInventory = bcInventory; 1131 item.essInventory = essInventory; 1132 1133 Items.push(item); 1134 }); 1135 return Items; 1136} 1137 1138function LoadPrice(cItems) { 1139 if (cItems == null) { 1140 cItems = GetItemsDetails(); 1141 } 1142 let Items = []; 1143 for (j = 0; j < cItems.length; j++) { 1144 let Item = { 1145 SKU: cItems[j].sku, 1146 UOM: cItems[j].uom, 1147 Quantity: cItems[j].quantity, 1148 FunctionalOrigin: cItems[j].functionalOrigin, 1149 }; 1150 Items.push(Item); 1151 } 1152 1153 Items = GetBCPrice(Items).then( 1154 function (value) { 1155 Items = value; 1156 if (Items.length > 0) { 1157 for (i = 0; i < Items.length; i++) { 1158 $("label[id='sellprice_" + Items[i].sku + "']").html(USDollar.format(Items[i].sellPrice) + "/" + Items[i].uom); 1159 $("input[id='hdnItemPrice_" + Items[i].sku + "']").val(Items[i].sellPrice); 1160 1161 $("input[id='hdnHardSubNo_" + Items[i].sku + "']").val(Items[i].hardSubstituteNo); 1162 1163 if (Items[i].contractitem) { 1164 $("b[id='contract_" + Items[i].sku + "']").html(contractItemIndicatorMessage); 1165 } 1166 1167 // Triger if it is a Quick Order page. 1168 if (location.pathname.indexOf("/quick-order") >= 0) { 1169 $("input[id='hdnUOM_" + Items[i].sku + "']").val(Items[i].uom); 1170 Total(); 1171 } 1172 } 1173 } 1174 }, 1175 function (error) { /* code if some error */ } 1176 ); 1177} 1178 1179function LoadItemsMessage(cItems) { 1180 if (cItems == null) { 1181 cItems = GetItemsDetails(); 1182 } 1183 let Items = []; 1184 for (j = 0; j < cItems.length; j++) { 1185 let Item = { 1186 SKU: cItems[j].sku, 1187 UOM: cItems[j].uom, 1188 Quantity: cItems[j].quantity, 1189 FunctionalOrigin: cItems[j].functionalOrigin, 1190 }; 1191 Items.push(Item); 1192 } 1193 1194 Items = GetBCItemMessage(Items).then( 1195 function (value) { 1196 Items = value; 1197 if (Items.length > 0) { 1198 for (i = 0; i < Items.length; i++) { 1199 if (Items[i].itemMessage) { 1200 $("b[id='item_message_" + Items[i].sku + "']").html(Items[i].itemMessage); 1201 } 1202 } 1203 } 1204 }, 1205 function (error) { /* code if some error */ } 1206 ); 1207} 1208 1209$(document).on("click", "span.rebate", function () { 1210 let url = $(this).data("rebate"); 1211 window.open(url, 'sprrebate', "width=800,height=600,toolbar=0,resizable=yes"); 1212}); 1213 1214//function UpdateCartPrice() { 1215// $.ajax({ 1216// type: "GET", 1217// url: "/ajax/ajaxcart?handler=UpdateCartPrice", 1218// beforeSend: function (xhr) { 1219// xhr.setRequestHeader("XSRF-TOKEN", 1220// $('input:hidden[name="__RequestVerificationToken"]').val()); 1221// $('body').append('<div id="requestOverlay" class="request-overlay">Re-calculating the cart item price.</div>'); /*Create overlay on demand*/ 1222// $("#requestOverlay").show();/*Show overlay*/ 1223// }, 1224// success: function (response) { 1225// $("#recalculatemessage").html("<b>Pricing has changed since cart was saved; updated price(s) will be used in checkout.</b>"); 1226// UpdateCartSummary(); 1227// }, 1228// complete: function () { 1229// $("#requestOverlay").remove();/*Remove overlay*/ 1230// } 1231// }); 1232//} 1233 1234// POD info popup 1235$(".POD").click(function () { 1236 let request = { 1237 orderNo: this.dataset.orderno, 1238 documentNo: this.dataset.documentno 1239 }; 1240 $.ajax({ 1241 type: "POST", 1242 url: "/ajax/ajaxcommon?handler=PODImageView", // Adjust the URL 1243 data: JSON.stringify(request), 1244 contentType: 'application/json; charset=utf-8', 1245 dataType: 'html', 1246 beforeSend: function (xhr) { 1247 xhr.setRequestHeader("XSRF-TOKEN", 1248 $('input:hidden[name="__RequestVerificationToken"]').val()); 1249 $("#MainModal .modal-title").html("Loading POD..."); 1250 $("#MainModal .modal-body").html('<div style="text-align: -webkit-center;"><div class="loadingIndicator"></div></div>'); 1251 $("#MainModal").modal('show'); 1252 }, 1253 success: function (response) {
1254 $("#MainModal").find(".modal-dialog").removeClass("modal-md").addClass("modal-lg"); 1255 $("#MainModal .modal-title").html("Proof of Delivery"); 1256 // Replace the content of the container with the loaded partial view 1257 $("#MainModal .modal-body").html(response); 1258 1259 // Add an event listener to the thumbnail images 1260 $('.pod-thumb').on('click', function () { 1261 // Get the main image URL from the thumbnail image 1262 const mainImageUrl = this.src; 1263 1264 // Set the main image URL to the main image view 1265 $('.pod-product-main-image').attr('src', mainImageUrl); 1266 }); 1267 1268 }, 1269 failure: function (response) { 1270 }, 1271 error: function (response) { 1272 console.log("POD Error Log"); 1273 console.log(response.responseText); 1274 $("#MainModal").modal('hide'); 1275 } 1276 }); 1277}); 1278$(document).on("click", ".pod-thumb", function () { 1279 let caption = $(this).data("caption"); 1280 $(".caption").text(caption); 1281});
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.