1var ASM = ASM || {}; // make sure ASM is available 2var sessionSec; 3var counter; 4var carts; 5 6function personifyForm() { 7 if ($('#_asmLogin').length) { 8 var loginUser = $("#asmLoginForm input[name='username']"); 9 var min = 1; 10 if (loginUser.val().length >= min) { 11 loginUser.parent().addClass('checked'); 12 } 13 } 14 15 $("#asmLoginForm input[name='username'], #asmLoginForm input[name='password']").keyup(function () { 16 var min = 1; 17 var parentNode = $(this.parentNode); 18 19 if (this.value.length >= (min)) { 20 parentNode.addClass('checked'); 21 checkSignInButton(parentNode); 22 } else { 23 parentNode.removeClass('checked'); 24 checkSignInButton(parentNode); 25 } 26 }); 27 28 $("input[name='customerName']").keyup(function (e) { 29 $("input[name='customerId']").val(""); 30 validateNewAccount(this); 31 $(this).removeData("hover"); 32 removeAsmHover(); 33 toggleBind(false); 34 toggleStartSessionButton(this, false); 35 36 if ($(this).val().length < 3) { 37 toggleCreateAccount(false); 38 } 39 }); 40 41 $("#_asmPersonifyForm input[name='cartId']").keyup(function () { 42 formValidate(this, 3, true, 256); 43 if (isErrorDisplayed()) { 44 $("input[name='cartId']").removeClass('ASM-input-error'); 45 if ($('.ASM_alert')) { 46 $('.ASM_alert').remove(); 47 } 48 } 49 }); 50 51 $("#_asmPersonifyForm input[name='customerName']").keyup(function () { 52 if (isErrorDisplayed()) { 53 $("input[name='customerName']").removeClass('ASM-input-error'); 54 if ($('.ASM_alert')) { 55 $('.ASM_alert').remove(); 56 } 57 if ($(this).val() === "") { 58 $("input[name='cartId']").removeClass('ASM-input-error'); 59 toggleStartSessionButton($("input[name='cartId']"), true); 60 $("input[name='customerId']").val(""); 61 } 62 } 63 if ($(this).val() === "") { 64 $("input[name='cartId']").val(""); 65 $("#asmAutoCompleteCartId").empty(); 66 } 67 }); 68 69 $("#_asmPersonifyForm input[name='cartId']").blur(function () { 70 var regEx = /^\s+$/; 71 if (regEx.test($(this).val())) { 72 $(this).val(''); 73 formValidate(this, 3, true, 256); 74 } 75 }); 76 77 $("#_asmBindForm input[name='cartId']").keyup(function (e) { 78 checkCartIdFieldAndToggleBind(this); 79 }); 80 81 $("#_asmBindForm input[name='cartId']").on('paste', function (e) { 82 var inputField = this; 83 setTimeout(function () { 84 checkCartIdFieldAndToggleBind(inputField); 85 }, 100); 86 }); 87} 88 89function validateForm() { 90 if ($("#sessionTimer").length && $('#asmLogoutForm').length) { 91 startTimer(); 92 } 93 94 if ($("#resetButton").length) { 95 $("#resetButton").click(function () { 96 resetSession(); 97 }); 98 } 99 100 /* for <=IE9 */ 101 if (placeholderNotAvailable()) { 102 $('[placeholder]').focus(function () { 103 var input = $(this); 104 if (input.val() === input.attr('placeholder')) { 105 input.val(''); 106 input.removeClass('placeholder'); 107 } 108 }).blur(function () { 109 var input = $(this); 110 if (input.val() === '' || input.val() === input.attr('placeholder')) { 111 input.addClass('placeholder'); 112 input.val(input.attr('placeholder')); 113 } 114 }).blur(); 115 } 116 117 $('[placeholder]').blur(function () { 118 var input = $(this); 119 if ((input.val() === '') && (input.attr("name"))) { 120 toggleBind(false); 121 } 122 }); 123 124 if ($('.ASM_alert_cart').length) { 125 $("input[name='cartId']").addClass('ASM-input-error'); 126 } 127 128 if ($('.ASM_alert_customer').length) { 129 $("input[name='customerName']").addClass('ASM-input-error'); 130 } 131 132 if ($('.ASM_alert_cred').length) { 133 $("input[name='username']").addClass('ASM-input-error'); 134 $("input[name='password']").addClass('ASM-input-error'); 135 } 136 137 if ($('.ASM_alert_create_new').length) { 138 toggleCreateAccount(true); 139 } 140} 141
142function addASMHandlers() { 143 144 revertAutocompleteNormalize(); 145 removeAsmAlert(3000); 146 addCloseBtnHandler(); 147 addASMFormHandler(); 148 addHideBtnHandler(); 149 addCustomerListBtnHandler(); 150 customerListModalHandler(); 151 addCustomer360Handler(); 152 addGenericCustomer360Handler(); 153 validateForm(); 154 personifyForm(); 155 156 $("#_asmPersonifyForm input[name='customerName'], input[name='customerId']").hover(function () { 157 var item = ($(this).attr('data-hover')) ? JSON.parse($(this).attr('data-hover')) : $(this).data("hover"); 158 var disabled = ($(this).attr('data-hover')) ? "disabled" : ""; 159 160 if (!(item === null || item === undefined)) { 161 $(this) 162 .after( 163 $('<div>') 164 .attr('id', 'asmHover') 165 .addClass(disabled) 166 .append( 167 $('<span>').addClass('name').text(item.name), 168 $('<span>').addClass('email').text(item.email), 169 $('<span>').addClass('date').text(item.date), 170 $('<span>').addClass('card').text(item.card) 171 ) 172 ); 173 } 174 }, function () { 175 removeAsmHover(); 176 } 177 ); 178 179 $("#_asmPersonifyForm input[name='cartId']").autocomplete({ 180 source: function (request, response) { 181 response(carts); 182 }, 183 appendTo: "#asmAutoCompleteCartId", 184 autoFocus: true, 185 minLength: 0, 186 select: function (event, ui) { 187 if (ui.item.value === "") { 188 event.preventDefault(); 189 } 190 toggleStartSessionButton(this, true); 191 } 192 }); 193 194 $("#_asmPersonifyForm input[name='cartId']").on('click, focus', function () { 195 $("#_asmPersonifyForm input[name='cartId']").autocomplete('search', ''); 196 }); 197 198 if ($("input[name='customerName']").length > 0) { 199 $("input[name='customerName']").autocomplete({ 200 source: function (request, response) { 201 $.ajax({ 202 url: ACC.config.encodedContextPath + "/assisted-service/autocomplete", 203 dataType: "json", 204 data: { 205 customerId: request.term 206 }, 207 success: function (data) { 208 response($.map(data, function (item) { 209 return { 210 email: item.email, 211 date: item.date, 212 card: item.card, 213 value: item.value, 214 carts: item.carts 215 }; 216 })); 217 } 218 }); 219 }, 220 minLength: 3, 221 appendTo: "#asmAutoComplete", 222 select: function (event, ui) { 223 if (ui.item.value === null) { 224 event.preventDefault(); 225 return; 226 } 227 // Stop the propagation of this event to prevent the event handler of keydown from processing the enter when an item was selected by that enter 228 event.originalEvent.originalEvent.stopPropagation(); 229 toggleStartSessionButton(this, true); 230 $(this).data('hover', { 231 name: ui.item.value, 232 email: ui.item.email, 233 card: ui.item.card, 234 date: ui.item.date 235 }); 236 237 /* insert item.value in customerId hidden field */ 238 $("input[name='customerId']").val(ui.item.email); 239 240 carts = ui.item.carts; 241 242 function handleCartIdInput() { 243 if (carts !== null) { 244 if (carts.length === 1) { 245 $("input[name='cartId']").val(carts[0]); 246 } else { 247 $("input[name='cartId']").autocomplete('search', ''); 248 $("input[name='cartId']").focus(); 249 } 250 } else { 251 carts = [{label: "No Existing Carts", value: ""}]; 252 $("input[name='cartId']").autocomplete('search', ''); 253 $("input[name='cartId']").focus(); 254 } 255 } 256 257 if ($("input[name='cartId']").attr("orig_value") === null) { 258 $("input[name='cartId']").val(''); 259 handleCartIdInput(); 260 } 261 checkCartIdFieldAndToggleBind($("input[name='cartId']")[0]); 262 263 } 264 }).data("ui-autocomplete")._renderItem = function (ul, item) { 265 if (item.value === null) { 266 toggleCreateAccount(true); 267 return $("<li></li>").data("item.autocomplete", item).append($('<span class=noresult>').text(ASM_MESSAGES.customerIdNotFound)) 268 .appendTo(ul); 269 } else { 270 toggleCreateAccount(false); 271 } 272 273 return $("<li></li>").data("item.autocomplete", item).append($('<span>').addClass('name').text(item.value), 274 $('<span>').addClass('email').text(item.email), 275 $('<span>').addClass('date').text(item.date), 276 $('<span>').addClass('card').text(item.card)).appendTo(ul); 277 }; 278 } 279 280 if ($("#_asmBindForm").length) { 281 var customerId = $("input[name='customerName']").attr('readonly'); 282 283 if (customerId === "readonly") { 284 $(".ASM_icon-chain").removeClass('invisible').addClass('ASM_chain-bind'); 285 286 if ($("#_asmBindForm input[name='customerId']").val() !== undefined && $("#_asmBindForm input[name='customerId']").val() !== "") { 287 $(".js-customer360").removeAttr('disabled'); 288 } 289 } 290 } 291 if ($(".add_to_cart_form").length && $("#_asm input[name='cartId']").val() === "") { 292 $(".add_to_cart_form").submit(function (event) { 293 setTimeout(function () {
294 var url = ACC.config.encodedContextPath + "/assisted-service/add-to-cart"; 295 $.post(url, function (data) { 296 $("#_asm").replaceWith(data); 297 addASMHandlers(); 298 }); 299 }, 400); 300 }); 301 } 302 enableAsmPanelButtons(); 303} 304 305$(document).ready(function () { 306 var ASM = ASM || {}; // make sure ACC is available 307 addASMHandlers(); 308 309 $(document).on("click", ".js-select-store-label", function (e) { 310 $("#colorbox .js-pickup-component").addClass("show-store"); 311 colorboxResize(); 312 }); 313 314 $(document).on("click", ".js-asm-store-finder-details-back", function (e) { 315 $("#colorbox .js-pickup-component").removeClass("show-store"); 316 }); 317}); 318 319function addASMFormHandler() { 320 if (($) && ($(".asmForm").length)) { 321 $(".asmForm").each(function () { 322 $(this).submit(function () { 323 $(this).find('[placeholder]').each(function () { 324 var input = $(this); 325 if (input.val() === input.attr('placeholder')) { 326 input.val(''); 327 } 328 }); 329 $.ajax({ 330 type: "POST", 331 url: $(this).attr('action'), 332 data: $(this).serialize(), 333 success: function (data) { 334 $("#_asm").replaceWith(data); 335 addASMHandlers(); 336 } 337 }); 338 return false; 339 }); 340 }); 341 } 342} 343 344function addCloseBtnHandler() { 345 $("#_asm .closeBtn").click(function () { 346 $("#_asm").remove(); 347 var url = ACC.config.encodedContextPath + "/assisted-service/quit"; 348 $.post(url, function (data) { 349 var params = new URLSearchParams(window.location.search); 350 params.delete('asm'); 351 window.location.search = params; 352 }); 353 }); 354} 355 356function addHideBtnHandler() { 357 $("#_asm .ASM_control_collapse").click(function () { 358 $("#_asm").toggleClass("ASM-collapsed"); 359 }); 360} 361 362function startTimer() { 363 sessionSec = timer; 364 clearInterval(counter); 365 counter = setInterval(timerFunc, 1000); 366} 367 368function timerFunc() { 369 if (sessionSec <= 0) { 370 clearInterval(counter); 371 finishASMagentSession(); 372 return; 373 } 374 sessionSec = sessionSec - 1; 375 var min = Math.floor(sessionSec / 60); 376 var sec = sessionSec % 60; 377 if (min < 10) { 378 min = "0" + min; 379 } 380 if (sec < 10) { 381 sec = "0" + sec; 382 } 383 $("#sessionTimer .ASM_timer_count").html(min + ":" + sec); 384} 385 386function resetSession() { 387 var request = $.ajax({ 388 url: ACC.config.encodedContextPath + "/assisted-service/resetSession", 389 type: "POST" 390 }); 391 request.done(function (msg) { 392 sessionSec = timer + 1; 393 }); 394 request.fail(function (jqXHR, textStatus) { 395 $('#errors').empty(); 396 $('#errors').append("Request failed: " + textStatus); 397 }); 398} 399 400function finishASMagentSession() { 401 $.ajax({ 402 url: ACC.config.encodedContextPath + "/assisted-service/logoutasm", 403 type: "POST", 404 success: function (data) { 405 $("#_asm").replaceWith(data); 406 addASMHandlers(); 407 } 408 }); 409} 410 411function isStartEmulateButtonPresent() { 412 return $(".ASM-btn-start-session").length === 1; 413} 414 415function enableAsmPanelButtons() { 416 $('div[id="_asm"] button').not(".js-customer360, .ASM-btn-start-session, .ASM-btn-create-account, .ASM-btn-login").removeAttr('disabled'); 417 if (isStartEmulateButtonPresent()) { 418 if ($("#_asmPersonifyForm input[name='customerId']").val() !== "") { 419 $("#_asmPersonifyForm input[name='customerId']").parent().addClass("checked"); 420 } 421 formValidate($("#_asmPersonifyForm input[name='cartId']")[0], 3, true, 256); 422 } 423} 424 425function placeholderNotAvailable() { 426 var i = document.createElement('input'); 427 return !('placeholder' in i); 428} 429 430function removeAsmHover() { 431 $('#asmHover').remove(); 432} 433 434function toggleCreateAccount(activate) { 435 var bindIcon = $(".ASM_icon-chain"); 436 var createButton = $("#_asmCreateAccountForm button.ASM-btn-create-account[type='submit']"); 437 if (activate) { 438 createButton.removeClass('hidden'); 439 bindIcon.removeClass('invisible'); 440 } else { 441 createButton.addClass('hidden'); 442 bindIcon.addClass('invisible'); 443 } 444} 445 446function toggleActivationState(button, activate) { 447 if (activate) { 448 button.removeAttr('disabled'); 449 } else { 450 button.attr('disabled', ''); 451 } 452} 453 454function checkSignInButton(el) { 455 var signInBtn = $("#asmLoginForm button[type='submit']"); 456 var checkSum = $(el).parent().find('.checked').length; 457 if (checkSum > 1) { 458 toggleActivationState(signInBtn, true); 459 } else { 460 toggleActivationState(signInBtn, false); 461 } 462} 463
464function checkStartSessionButton(el) { 465 toggleStartSessionButton(el, false); 466 var checkSum = $(el.parentNode).siblings('.checked').length; 467 if (checkSum > 0) { 468 toggleActivationState($("button.ASM-btn-start-session"), true); 469 } 470} 471 472function checkCartIdFieldAndToggleBind(cartIdField) { 473 function checkCustomerDataTyped() { 474 return !$(cartIdField).hasClass('placeholder') 475 && ($("input[name='customerName']").val().length > 0) 476 && ($("input[name='customerId']").val().length > 0); 477 } 478 479 function checkCartIdTyped() { 480 return !isNaN(cartIdField.value) 481 && (cartIdField.value.length === 8); 482 } 483 484 if (checkCustomerDataTyped() && checkCartIdTyped()) { 485 $("#_asmBindForm button[type='submit']").removeClass('hidden'); 486 $(".ASM_icon-chain").removeClass('invisible'); 487 return; 488 } 489 $("#_asmBindForm button[type='submit']").addClass('hidden'); 490 $(".ASM_icon-chain").addClass('invisible'); 491} 492 493function toggleBind(activate) { 494 if ($("#_asmBindForm").length) { 495 var bindIcon = $(".ASM_icon-chain"); 496 var bindButton = $("#_asmBindForm button.ASM-btn-bind-cart[type='submit']"); 497 if (activate) { 498 bindButton.removeClass('hidden'); 499 bindIcon.removeClass('invisible'); 500 } else { 501 bindButton.addClass('hidden'); 502 if ($('.ASM-btn-create-account').hasClass('hidden')) { 503 bindIcon.addClass('invisible'); 504 } 505 } 506 } 507} 508 509function toggleStartSessionButton(el, activate) { 510 var checkedItem = $(el).parent(); 511 var button = $("button.ASM-btn-start-session"); 512 if (activate) { 513 button.removeAttr('disabled'); 514 checkedItem.addClass("checked"); 515 } else { 516 button.attr('disabled', ''); 517 checkedItem.removeClass("checked"); 518 } 519} 520 521function formValidate(el, min, number, max) { 522 if (!$(el).hasClass('placeholder')) { 523 if ($(el).hasClass("ASM-input-error")) { 524 toggleStartSessionButton(el, false); 525 return false; 526 } 527 if ((number !== false) && isNaN(el.value)) { 528 toggleStartSessionButton(el, false); 529 return false; 530 } 531 if (el.value.length >= (min)) { 532 toggleStartSessionButton(el, true); 533 if (max !== undefined && el.value.length > (max)) { 534 toggleStartSessionButton(el, false); 535 } 536 } else if (el.value.length === 0) { 537 checkStartSessionButton(el); 538 } else { 539 toggleStartSessionButton(el, false); 540 return false; 541 } 542 return true; 543 } 544 return false; 545} 546 547function validateEmail(mailAddress) { 548 return ($('<input>').attr({ 549 type: 'email', 550 required: 'required' 551 }).val(mailAddress))[0].checkValidity() && (mailAddress.indexOf(".") > 0); 552} 553 554function validateName(name) { 555 var split = name.trim().split(/\s+/); 556 return !isBlank(split[0]) && !isBlank(split[1]); 557} 558 559function isBlank(str) { 560 return (!str || 0 === str.length); 561} 562 563function validateNewAccount(el) { 564 var createAccountButton = $("#_asmCreateAccountForm button.ASM-btn-create-account[type='submit']"); 565 var customerValues = el.value.split(', '); 566 var IdInput = $("#_asmCreateAccountForm input[name='customerId']"); 567 var NameInput = $("#_asmCreateAccountForm input[name='customerName']"); 568 569 if (customerValues.length > 1) { 570 var validName = validateName(customerValues[0]); 571 var validMail = validateEmail(customerValues[1]); 572 if (validName && validMail) { 573 toggleActivationState(createAccountButton, true); 574 /* fill hidden input fields */ 575 IdInput.val(customerValues[1].replace(/^\s\s*/, '').replace(/\s\s*$/, '')); 576 NameInput.val(customerValues[0]); 577 } else { 578 /* no valid customer values */ 579 toggleActivationState(createAccountButton, false); 580 return false; 581 } 582 } else { 583 /* too less customer values */ 584 toggleActivationState(createAccountButton, false); 585 return false;
586 } 587} 588 589function revertAutocompleteNormalize() { 590 /* After http://bugs.jqueryui.com/ticket/9762 there was a change when for empty value label is placed instead. 591 * But we want to send empty values for NO_FOUND case */ 592 $.ui.autocomplete.prototype._normalize = function (a) { 593 if (a.length && a[0].label && a[0].value) { 594 return a; 595 } 596 return $.map(a, function (b) { 597 if (typeof b === "string") { 598 return {label: b, value: b}; 599 } 600 return $.extend({label: b.label || b.value, value: b.value || b.label}, b); 601 }); 602 }; 603} 604 605function isErrorDisplayed() { 606 return $('.ASM_alert').length; 607} 608 609 610function addCustomerListBtnHandler() { 611 $(".js-customer-list-btn").removeClass('disabled'); 612 $(document).on("click", ".js-customer-list-btn", function (e) { 613 e.preventDefault(); 614 populateCustomerListModal($(this).data('actionurl'), '.js-customer-list-modal-content', addCustomerListSelect); 615 }); 616} 617 618function openCustomer360Colorbox(colorboxTarget) { 619 colorboxTarget.colorbox({ 620 inline: 'true', 621 className: 'ASM_customer360-modal', 622 width: "100%", 623 maxWidth: "1200px", 624 close: '<span class="ASM_icon ASM_icon-close"></span>', 625 transition: 'none', 626 scrolling: false, 627 opacity: 0.7, 628 top: 10, 629 onOpen: function () { 630 customer360Callback(); 631 $(window).on("resize", colorboxResize); 632 }, 633 onClosed: function () { 634 $(window).off("resize", colorboxResize); 635 } 636 }); 637} 638 639function colorboxResize() { 640 $.colorbox.resize(); 641} 642 643function addCustomer360Handler() { 644 openCustomer360Colorbox($(".js-customer360")); 645} 646 647function addGenericCustomer360Handler() { 648 if ($("#enable360View").val()) { 649 openCustomer360Colorbox($); 650 } 651} 652 653function customer360Callback() { 654 var loader = "<div class='loader'>Loading..</div>"; 655 $("#cboxLoadedContent").html(loader).show(); 656 $.ajax({ 657 url: ACC.config.encodedContextPath + "/assisted-service-aif/customer360", 658 type: "GET", 659 success: function (data) { 660 $("#cboxLoadedContent").append(data); 661 $.colorbox.resize(); 662 }, 663 error: function (xht, textStatus, ex) { 664 console.debug("Failed to load Customer 360. %s", ex); 665 document.location.reload(); 666 } 667 }); 668} 669 670function loadCustomer360Fragment(params) { 671 return $.ajax({ 672 url: ACC.config.encodedContextPath + "/assisted-service-aif/customer360Fragment", 673 timeout: params.timeout, 674 type: params.method, 675 data: params, 676 success: function (data) { 677 $("#" + params.fragmentId).html(data); 678 $.colorbox.resize(); 679 680 }, 681 error: function (xht, textStatus, ex) { 682 if (textStatus === 'timeout') { 683 $("#" + params.fragmentId).html("Widget timeout!"); 684 //do something. Try again perhaps? 685 } else { 686 console.debug("Failed to get widget data! %s", ex); 687 $("#" + params.fragmentId).html("Failed to get widget data!"); 688 } 689 } 690 }); 691} 692 693function asmAifSectionClickHandler() { 694 $(document).on("click", ".asm__customer360__menu li", function (e) { 695 e.preventDefault(); 696 if (!$(this).hasClass('nav-tabs-mobile-caret')) { 697 aifSelectSection($(this).index()); 698 } 699 }); 700} 701 702function aifSelectLastSection() { 703 var index = 0; 704 if (sessionStorage.getItem("lastSection")) { 705 var lastSection = JSON.parse(sessionStorage.getItem("lastSection")); 706 if (getCurrentEmulatedCustomerId() === lastSection.userId) { 707 index = lastSection.sectionId; 708 } 709 } 710 $($(".asm__customer360__menu li[role='presentation']")[index]).addClass("active"); 711 aifSelectSection(index); 712} 713 714function aifSelectSection(index) { 715 $("#sectionPlaceholder").hide(); 716 $("#longLoadExample").show(); 717 var sectionId = $(".asm__customer360__menu li").get(index).getAttribute("value"); 718 sessionStorage.setItem("lastSection", JSON.stringify({userId: getCurrentEmulatedCustomerId(), sectionId: index})); 719 $.ajax({ 720 url: ACC.config.encodedContextPath + "/assisted-service-aif/customer360section?sectionId=" + sectionId, 721 type: "GET", 722 success: function (data) { 723 $("#sectionPlaceholder").html(data); 724 $("#longLoadExample").hide(); 725 $("#sectionPlaceholder").show(); 726 $.colorbox.resize(); 727 } 728 }); 729 resetSession(); 730} 731 732function getCurrentEmulatedCustomerId() { 733 if ($("#_asmBindForm input[name='customerId']").length) { 734 return $("#_asmBindForm input[name='customerId']").val(); 735 } 736 return "anonymous"; 737} 738 739function getCustomerListSearchUrl() { 740 var targetUrl = $(".js-customer-list-sorting").data('sort-url'); 741 targetUrl += $(".ASM_customer-list-modal .sort-refine-bar .form-control").val(); 742 var query = $("#ASM_customer-list-queryInput").val(); 743 var uriEncodedquery = encodeURIComponent(query); 744 targetUrl += '&query=' + uriEncodedquery; 745 return targetUrl; 746} 747 748function customerListModalHandler() { 749 $(document).on("click", ".ASM_customer-list-modal .pagination a", function (e) { 750 e.preventDefault(); 751 populateCustomerListModal($(this).attr('href'), ".asm-account-section", replaceCustomerListTable); 752 }); 753 754 $(document).on("click", "#ASM_customer-list-sortOptions .sortOption", function (e) { 755 e.preventDefault(); 756 var selectedOption = $(this).data('value'); 757 var previouslySelectedOption = $(".ASM_customer-list-modal .sort-refine-bar .form-control").val(); 758 if (selectedOption !== previouslySelectedOption) { 759 $(".ASM_customer-list-modal .sort-refine-bar .form-control").val(selectedOption); 760 var targetUrl = getCustomerListSearchUrl(); 761 populateCustomerListModal(targetUrl, ".asm-account-section", replaceCustomerListTable); 762 } 763 }); 764 765 $(document).on("keypress", "#ASM_customer-list-queryInput", function (event) { 766 if (event.keyCode === 13) { 767 $("#ASM_customer-list-searchButton").click(); 768 return false;
769 } else { 770 return true; 771 } 772 }); 773 774 $(document).on("click", "#ASM_customer-list-searchButton", function (e) { 775 e.preventDefault(); 776 var targetUrl = getCustomerListSearchUrl(); 777 populateCustomerListModal(targetUrl, ".asm-account-section", replaceCustomerListTable); 778 }); 779 780 $(document).on("change", ".ASM_customer-list-modal .sort-refine-bar .form-control", function (e) { 781 e.preventDefault(); 782 783 var targetUrl = getCustomerListSearchUrl(); 784 populateCustomerListModal(targetUrl, ".asm-account-section", replaceCustomerListTable); 785 }); 786 787 $(document).on("change", ".js-customer-list-select", function (e) { 788 e.preventDefault(); 789 var targetUrl = $(this).data('search-url'); 790 targetUrl += $(this).val(); 791 var request = populateCustomerListModal(targetUrl, ".asm-account-section", replaceCustomerListTable); 792 request.done(function () { 793 $.colorbox.resize(); 794 }); 795 }); 796} 797 798function addCustomerListSelect(componentToUpdate, data) { 799 var selector = $(data).find('.js-customer-list-select'); 800 $(componentToUpdate).html(data); 801 var searchUrl = $(data).find('.js-customer-list-select').data('search-url'); 802 if (selector[0].options.length > 0) { 803 searchUrl += selector[0].options[0].value; 804 } 805 806 var request = populateCustomerListModal(searchUrl, componentToUpdate, appendCustomerListTable); 807 request.done(function () { 808 ACC.colorbox.open("", { 809 href: ".js-customer-list-modal-content", 810 inline: true, 811 className: 'ASM_customer-list-modal', 812 width: "100%", 813 maxWidth: "1200px", 814 close: '<span class="ASM_icon ASM_icon-close"></span>', 815 transition: 'none', 816 scrolling: false, 817 opacity: 0.7, 818 top: 10, 819 onOpen: function () { 820 $(window).on("resize", colorboxResize); 821 }, 822 onClosed: function () { 823 $(window).off("resize", colorboxResize); 824 } 825 }); 826 }); 827} 828 829function appendCustomerListTable(componentToUpdate, data) { 830 $(componentToUpdate).append(data); 831} 832 833function replaceCustomerListTable(componentToUpdate, data) { 834 $(componentToUpdate).html(data); 835} 836 837function populateCustomerListModal(targetUrl, componentToUpdate, callFunction) { 838 var method = "GET"; 839 return $.ajax({ 840 url: targetUrl, 841 type: method, 842 success: function (data) { 843 callFunction(componentToUpdate, data); 844 }, 845 error: function (xht, textStatus, ex) { 846 console.debug("Failed to get customer list. %s", ex); 847 document.location.reload(); 848 } 849 }); 850} 851 852function getAifTablePageSize() { 853 var pagesNumber = 5; // number 854 if ($(window).width() < 668) { 855 pagesNumber = 10; 856 } 857 return pagesNumber; 858} 859 860function copyToClipBoard(text) { 861 $("#asmCopyHoldtext").val(text); 862 $("#asmCopyHoldtext").show(); 863 $("#asmCopyHoldtext").select(); 864 try { 865 return document.execCommand("copy"); 866 } catch (ex) { 867 console.debug("Copy to clipboard failed.", ex); 868 return false; 869 } finally { 870 $("#asmCopyHoldtext").hide(); 871 } 872} 873 874function addRatesTableSorterParser() { 875 $.tablesorter.addParser({ 876 // set a unique id 877 id: 'rates', 878 is: function (s) { 879 // return false so this parser is not auto detected 880 return false; 881 }, 882 format: function (s, table, cell) { 883 return Math.floor($(cell).attr('data-text') * 10); 884 }, 885 type: 'numeric' 886 }); 887} 888 889function removeAsmAlert(delay) { 890 setTimeout(function () { 891 $(".ASM_alert").fadeOut("slow"); 892 }, delay); 893} 894 895ACC.assistedservicestorefront = { 896 897 buildArrayValues: function (variableArray, value) { 898 variableArray.push(value); 899 return variableArray; 900 } 901 902}; 903// collapsible 904$(function () { 905 if ($(".js-ASM-collapseBtn").length > 0) { 906 var onDragging = false; 907 908 var readASMcollapseCookie = function () { 909 var nameEQ = "ASMcollapseBtn="; 910 var ca = document.cookie.split(';'); 911 for (var i = 0; i < ca.length; i++) { 912 var c = ca[i]; 913 while (c.charAt(0) === ' ') { 914 c = c.substring(1, c.length); 915 } 916 if (c.indexOf(nameEQ) === 0) { 917 return JSON.parse(decodeURIComponent(c.substring(nameEQ.length, c.length))); 918 } 919 } 920 return null; 921 }; 922 923 //get saved values from cookie 924 var startPosition = readASMcollapseCookie(); 925 if (startPosition) { 926 //set position of collapseBtn 927 $(".js-ASM-collapseBtn").css("left", startPosition.position + "%"); 928 if (startPosition.state) { 929 $("#_asm").addClass("asm-collapsed"); 930 } 931 } 932 933 $("#_asm").show(); 934 935 var saveCollapseBtn = function () { 936 var pos = $(".js-ASM-collapseBtn").offset().left; 937 var parentWidth = $(".js-ASM-collapseBtn-wrapper").width(); 938 var obj = { 939 position: pos / (parentWidth / 100), 940 state: $("#_asm").hasClass("asm-collapsed") 941 }; 942 document.cookie = "ASMcollapseBtn=" + encodeURIComponent(JSON.stringify(obj)) + "; path=/"; 943 }; 944 945 //init drag of the button 946 $(".js-ASM-collapseBtn").draggable({ 947 cancel: '.no-drag', 948 axis: "x", 949 containment: ".collapseBtn-wrapper", 950 delay: 300, 951 distance: 10, 952 opacity: 0.8, 953 start: function () { 954 onDragging = true; 955 $(".js-ASM-collapseBtn-wrapper").addClass("active"); 956 957 }, 958 stop: function () { 959 onDragging = false;
960 $(".js-ASM-collapseBtn-wrapper").removeClass("active"); 961 //save values to cookie 962 saveCollapseBtn(); 963 } 964 }); 965 966 //bind event for toogle the asm panel 967 $(document).on("mouseup", ".js-ASM-collapseBtn", function () { 968 if (!onDragging) { 969 if ($("#_asm").hasClass("asm-collapsed")) { 970 $("#_asm").removeClass("asm-collapsed"); 971 } else { 972 $("#_asm").addClass("asm-collapsed"); 973 } 974 //save values to cookie 975 saveCollapseBtn(); 976 } 977 }); 978 979 } 980}); 981 982// dropdown 983$(function () { 984 $(document).on("click", ".js-dropdown", function (e) { 985 e.preventDefault(); 986 var $e = $(this).parent(); 987 if ($e.hasClass("open")) { 988 $e.removeClass("open"); 989 } else { 990 $e.addClass("open"); 991 } 992 }); 993 $(document).on("click", ".js-customer-360-tab", function (e) { 994 e.preventDefault(); 995 $(this).parent().addClass("active").siblings().removeClass("active"); 996 }); 997});
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.