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