1$(document).ready(function () { 2 ProductSelection.init(); 3 $('#divProductsTop').removeClass('disabledProducts'); 4}); 5 6var ProductSelection = { 7 init: function () { 8 9 ////////////////////////////////////////// 10 // Polyfill - Start 11 ////////////////////////////////////////// 12 13 if (typeof Object.assign !== 'function') { 14 Object.assign = function (target) { 15 'use strict'; 16 if (target === null) { 17 throw new TypeError('Cannot convert undefined or null to object'); 18 } 19 20 target = Object(target); 21 for (var index = 1; index < arguments.length; index++) { 22 var source = arguments[index]; 23 if (source != null) { 24 for (var key in source) { 25 if (Object.prototype.hasOwnProperty.call(source, key)) { 26 target[key] = source[key]; 27 } 28 } 29 } 30 } 31 return target; 32 }; 33 } 34
35 ////////////////////////////////////////// 36 // Polyfill - End 37 ////////////////////////////////////////// 38 39 window.isFromClosebuttonAndLink = false; 40 window.isHideProductBasedOnbundlesSelection = false; 41 window.isSelectBundleBasedonProductSelection = true; 42 window.isProductRowAgainClick = false; 43 window.isRemoveProductWhenOtherBundleSelect = false; 44 window.isApplyProductWhenOtherBundleSelect = false; 45 window.isformsubmitonce = false; 46 window.checkboxType = ""; 47 FormUtils.initWithHiddenInputs(); 48 49 RESPONSIVEUI.responsiveTabs(ProductOptions.transferVisibleToNewTab); 50 51 $(document).on('UpdateScreen', ProductSelection.updateScreen); 52 53 ProductSelection.updateScreenOnLoad(); 54 55 if ($('#IsAddressManuallyEdit').val() !== 'True') { 56 SearchAlerts.loadAlerts(); 57 } 58 59 if (window.navigator.userAgent.indexOf('MSIE ') > 0 || window.navigator.userAgent.indexOf('Trident/') > 0 || window.navigator.userAgent.indexOf('Edge/') > 0) { 60 $('.product-choices').on('change', '.product-row', ProductSelection.clickProductNav); 61 $('.product-choices').on('click', '.options-icon,.product-price', ProductSelection.clickRowWhenOptionIconClick); 62 $('.product-choices').on('click', '.label-product-selection', ProductSelection.clickRowWhenLabelClick); 63 64 $('#product-grouping-tree').on('change', '.product-nav', ProductSelection.clickProductNav); 65 $('#product-grouping-tree').on('click', '.label-product-nav,.options-icon-nav,.product-price,.DrainageAndWaterProduct', ProductSelection.clickNavRowWhenNavLabelIconClick); 66 } 67 else { 68 $('.product-choices').on('click', '.product-row', ProductSelection.clickProductNav); 69 $('#product-grouping-tree').on('click', '.product-nav', ProductSelection.clickProductNav); 70 } 71 72 73 $('#product-grouping-tree').on('click', '.product-grouping-nav-sub-header,.product-grouping-nav-header', 74 ProductGrouping.toggleGroupDisplay); 75 76 $('#product-grouping-tree-Residential').on('click', '.product-grouping-nav-sub-header,.product-grouping-nav-header', 77 ProductGrouping.toggleGroupDisplay); 78 $('#product-grouping-tree-Commercial').on('click', '.product-grouping-nav-sub-header,.product-grouping-nav-header', 79 ProductGrouping.toggleGroupDisplay); 80 $('#product-grouping-tree-Mapping').on('click', '.product-grouping-nav-sub-header,.product-grouping-nav-header', 81 ProductGrouping.toggleGroupDisplay); 82 83 $('[id=Bundle]').on('click', ProductSelection.selectProductBasedOnBundles); 84 $('[id=ChooseBundle]').on('click', Bundles.bindBundleClickOnChooseBundleLink); 85 $('#product-grouping-tree-Residential').on('click', '.product-nav', ProductSelection.clickProductNav); 86 $('#product-grouping-tree-Commercial').on('click', '.product-nav', ProductSelection.clickProductNav); 87 $('#product-grouping-tree-Mapping').on('click', '.product-nav', ProductSelection.clickProductNav); 88 89 $('.search-alerts').on('click', '.search-alert-link', ProductSelection.selectProductBasedOnSearchAlertLink); 90 91 $('.js-hide-search-alerts').click(function (event) { 92 ProductSelection.toggleModuleCtHeader(event, this, { 93 className: 'js-search-alerts-details', 94 showHTML: 'Show alerts', 95 showTitle: 'Show the search alerts.', 96 hideHTML: 'Collapse', 97 hideTitle: 'Collapse the search alerts.' 98 }); 99 }); 100 101 $('.js-hide-templates').click(function (event) { 102 ProductSelection.toggleModuleCtHeader(event, this, { 103 className: 'js-templates-details', 104 showHTML: 'Show templates', 105 showTitle: 'Show the available templates.', 106 hideHTML: 'Collapse', 107 hideTitle: 'Collapse the available templates.' 108 }); 109 }); 110 111 $("#ProductSelection").submit(function (e) { 112 e.preventDefault(); 113 $('#TemplateIdFromPlaceOrder').val(""); 114 if ($(this).find('.product-choices .product-selection').is(':checked') === false) { 115 $(this).closest('.form--surrogate').addClass('form__searches--error'); 116 $('#form-error-no-product-selection').addClass('form-error'); 117 return false; 118 } 119 else if ($('#TotalProductAmount').val() <= 0) { 120 alert("Total amount must be greater than £0.00. Please re-select product(s) after page refresh."); 121 window.location.reload(); 122 return false; 123 } 124 else { 125 126 var arr = $(this).find('.product-choices .product-selection'); 127 var i; 128 for (i = 0; i < arr.length; i++) {
129 if (arr[i].checked && $(arr[i]).siblings('#TotalCost').val() == 0) { 130 var fieldLabel = $(arr[i]).siblings('label').text(); 131 $('#form-error-no-product-options-selection').html('Please select one of the options for the \'' + fieldLabel + '\' product.'); 132 $(this).closest('.form--surrogate').addClass('form__searches--error'); 133 $('#form-error-no-product-options-selection').addClass('form-error'); 134 return false; 135 } 136 } 137 if (!ProductQuestionsValidation.validateForm($(this).closest('.form'))) { 138 $(this).closest('.form--surrogate').addClass('form__searches--error'); 139 return; 140 } 141 142 $('#form-error-no-product-selection').removeClass('form-error'); 143 $('#form-error-no-product-options-selection').removeClass('form-error'); 144 145 var _this = $(this); 146 _this.unbind('submit').submit(); 147 148 } 149 }); 150 151 ProductOptionsQuestion.bindEvents(); 152 153 if ($('.bundle-details').length > 0) { 154 $('.bundle-details').on('mouseenter mouseleave', Bundles.toggleHighlights); 155 } 156 var alertPromise = $.ajax({ 157 type: "GET", 158 async: false, 159 url: "/ProductSearch/GetCivicaDiscAllowedProducts", 160 contentType: "application/json;", 161 dataType: 'json', 162 }); 163 164 alertPromise.done(function (data) { 165 $('#CivicaDiscAllowedProducts').val(data); 166 }); 167 168 var labelPromise = $.ajax({ 169 type: "GET", 170 async: false, 171 url: "/ProductSearch/GetLocalAuthorityProductLabel?propertyTypeValue=" + $("#PropertyTypeForAlerts").val(), 172 // data: { 173 // propertyTypeValue: $("#PropertyTypeForAlerts").val(), 174 // }, 175 }); 176 177 labelPromise.done(function (data) { 178 var label; 179 if (data != "") { 180 label = data.split(';'); 181 } 182 $('#LocalAuthorityProductLabel').val(label[0]); 183 $('#LocalAuthorityHighwayProductLabel').val(label[1]); 184 $('#LocalAuthorityLlc1ProductLabel').val(label[2]); 185 }); 186 187 ProductSelection.selectProductOnAmend(); 188 ProductSelection.applyDiscountOnLoad(); 189 190 if ($('#StaticProductCode').val() !== "") { 191 var productCode = $('#StaticProductCode').val(); 192 var input = $("li.product-nav").find('input[value="' + productCode + '"]'); 193 var checkbox = $(input).siblings('input[type=checkbox]'); 194 if (checkbox.length > 0 && $(checkbox).prop('checked') !== true) { 195 $(checkbox).trigger("click"); 196 } 197 } 198 199 $('.productselectionfilter').change(function () { 200 $("#profile-tab").click(); 201 //on each click, refresh visible / hidden for each item 202 $('ul.productselectionfilterresult').each(function (i, item) { 203 var product = $(this).data('product'); 204 var visible = $('input.productselectionfilter[data-product="' + product + '"]:checked').length > 0; 205 visible ? $(this).show() : $(this).hide(); 206 }); 207 208 //if no checkboxes are checked, show everything 209 if ($('input.productselectionfilter:checked').length === 0) $('ul.productselectionfilterresult').show(); 210 }); 211 212 $("input[name='bundleName']").filter(function () { 213 return ($(this).val() || "") 214 .toLowerCase() 215 .includes("full official local authority"); 216 }).closest(".product-card").css("border", "2px solid red"); 217 //$("input[name=radioPropertyType]:radio").change(function () { 218 // if (confirm('Are you sure ?')) { 219 // $.ajax({
220 // type: "GET", 221 // async: false, 222 // url: "/ProductSearch/UpdatePropertyType?radioPropertyType=" + $('input[name="radioPropertyType"]:checked').val(), 223 // success: function (data) { 224 // location.reload(); 225 // }, 226 // error: function () { 227 // }, 228 // }); 229 // } else { 230 // location.reload(); 231 // //alert('cancel') 232 // } 233 234 //}); 235 236 }, 237 238 239 240 updateScreen: function (event) { 241 ProductGrouping.updateCheckedProductStyling(); 242 ProductGrouping.updateNavSelectedHeaders(); 243 }, 244 245 selectProductOnAmend: function () { 246 if ($('#IsOrderAmend').val() === "True" && $('#BackToProductSelection').val() == "1") { 247 var productsIdsOnAmend = $('#SelectedProductsIdsOnAmend').val(); 248 if (productsIdsOnAmend != "") { 249 var productIds = productsIdsOnAmend.split(';'); 250 for (var i = 0; i < productIds.length; i++) { 251 var checkbox = $("li.product-nav").find('input[value="' + productIds[i] + '"]').siblings('input[type=checkbox]'); 252 $(checkbox).trigger("click"); 253 } 254 } 255 } 256 }, 257 258 updateScreenOnLoad: function () { 259 var $checkedNavProducts = $('.product-nav-checkbox:checked'); 260 if ($checkedNavProducts.length > 0) { 261 $checkedNavProducts.each(function () { 262 ProductGrouping.updateNavChecked($(this)); 263 }); 264 } 265 $(document).trigger('UpdateScreen'); 266 }, 267 268 toggleModuleCtHeader: function (event, elem, options) { 269 event.preventDefault(); 270 if ($('.' + options.className + ' > li').is(':visible')) { 271 $('.' + options.className + ' > li').slideUp(); 272 $(elem).html(options.showHTML); 273 $(elem).attr('title', options.showTitle); 274 } else { 275 $('.' + options.className + ' > li').slideDown(); 276 $(elem).html(options.hideHTML); 277 $(elem).attr('title', options.hideTitle); 278 } 279 }, 280 281 productSelected: function (product, productnav) { 282 283 ProductOptions.toggleDisplay(product, productnav); 284 ProductGrouping.updateNavChecked(productnav); 285 $(document).trigger('UpdateScreen'); 286 }, 287 288 clickRowWhenOptionIconClick: function () { 289 event.preventDefault(); 290 event.stopPropagation(); 291 $('.product-choices').on('click', '.product-row', ProductSelection.clickProductNav); 292 $(this).parent('tr').trigger('click'); 293 $('.product-choices').off('click', '.product-row', ProductSelection.clickProductNav); 294 }, 295 296 clickRowWhenLabelClick: function () { 297 event.preventDefault(); 298 event.stopPropagation(); 299 $('.product-choices').on('click', '.product-row', ProductSelection.clickProductNav); 300 $(this).parent().parent('tr').trigger('click'); 301 $('.product-choices').off('click', '.product-row', ProductSelection.clickProductNav); 302 }, 303 304 clickNavRowWhenNavLabelIconClick: function () { 305 event.preventDefault(); 306 event.stopPropagation(); 307 $('#product-grouping-tree').on('click', '.product-nav', ProductSelection.clickProductNav); 308 $(this).parent('li').trigger('click'); 309 $('#product-grouping-tree').off('click', '.product-nav', ProductSelection.clickProductNav); 310 }, 311 312 clickProductNav: function (event) { 313 var target; 314 var $label = $(this).find('label'); 315 window.isProductRowAgainClick = $(this).find('input[type=checkbox]')[0].checked; 316 if (event.target === $label[0]) { 317 event.preventDefault(); 318 event.stopPropagation(); 319 } 320 else if (event.target == $(this).find('input[type=checkbox]')[0]) { 321 target = "checkbox"; 322 if ($(this).find('input[type=checkbox]')[0].checked) { 323 window.isProductRowAgainClick = false; 324 } 325 else { 326 window.isProductRowAgainClick = true; 327 } 328 } 329 330 ProductSelection.addProductRow.call(this, target); 331 }, 332 333 addProductRow: function (target) { 334
335 var $navCheckbox; 336 var $code; 337 338 339 if ($(this).hasClass('product-row') && $(this).find('input[type=checkbox]')[0].id != "" && jQuery.type($(this).find('input[type=checkbox]')[0].id) == 'string') { 340 $navCheckbox = $('#' + $(this).find('input[type=checkbox]')[0].id + '-nav'); 341 window.checkboxType = "productcheckbox"; 342 } else if ($(this).hasClass('product-nav')) { 343 $navCheckbox = $(this).find('input'); 344 window.checkboxType = "navcheckbox"; 345 } else if ($(this).hasClass('label-product-nav')) { 346 $navCheckbox = $('#' + $(this).attr('for')); 347 window.checkboxType = "navcheckbox"; 348 } 349 350 if (!($navCheckbox) || $navCheckbox.length === 0) { 351 return false; 352 } 353 354 if ($navCheckbox != 'undefined') { 355 var $productnav = $navCheckbox.get(0); 356 if ($productnav.id.indexOf("-nav") !== -1) { 357 $code = $productnav.id.split("-nav")[0]; 358 } 359 else { 360 $code = $productnav.id; 361 } 362 } 363 else { 364 $code = this.id; 365 } 366 367 ProductOptionsQuestion.addProductRowInPopularProductsIfNotPresent($code, $navCheckbox); 368 369 var $productCheckbox = $('#' + $code); 370 if ($productCheckbox.length > 0 || $productnav != null) { 371 var $thisoptions = $('[id=' + $code + '-options]'); 372 if ($thisoptions.length === 0) { 373 var checkbox = this; 374 if ($(this).hasClass('product-row')) { 375 checkbox = $(this).find('input[type=checkbox]')[0]; 376 } 377 378 ProductSelection.selectSingleProduct(checkbox, target); 379 if (window.isSelectBundleBasedonProductSelection) { 380 Bundles.selectBundleBasedonProductSelection(); 381 Discount.applyDiscount(checkbox); 382 } 383 if (window.isRemoveProductWhenOtherBundleSelect) { 384 Discount.applyDiscount(checkbox); 385 } 386 ProductSelection.tooltips.apply($productCheckbox.get(0)); 387 return; 388 } 389 390 ProductSelection.productSelected($productCheckbox.get(0), $productnav); 391 if (window.isSelectBundleBasedonProductSelection) { 392 Bundles.selectBundleBasedonProductSelection(); 393 Discount.applyDiscount($productCheckbox.get(0)); 394 } 395 396 if (window.isRemoveProductWhenOtherBundleSelect) { 397 Discount.applyDiscount($productCheckbox.get(0)); 398 } 399 ProductSelection.tooltips.apply($productCheckbox.get(0)); 400 return false; 401 } 402 403 if (window.isSelectBundleBasedonProductSelection) { 404 Bundles.selectBundleBasedonProductSelection(); 405 Discount.applyDiscount($productCheckbox.get(0)); 406 } 407 return false; 408 409 }, 410 411 selectSingleProduct: function (selectedCheckbox, target) { 412 413 if (selectedCheckbox.id != "" && jQuery.type(selectedCheckbox.id) == 'string') { 414 var navCheckbox = $('#' + selectedCheckbox.id + '-nav'); 415 if (target === "checkbox") { 416 navCheckbox.prop('checked', selectedCheckbox.checked); 417 } 418 else if (target === undefined && !navCheckbox[0].checked) { 419 navCheckbox.prop('checked', true); 420 selectedCheckbox.checked = true; 421 422 } 423 else if (target === undefined && navCheckbox[0].checked) { 424 425 navCheckbox.prop('checked', false); 426 selectedCheckbox.checked = false; 427 } 428 429 Amount.updateAmount(selectedCheckbox, navCheckbox); 430 ProductGrouping.updateNavChecked(navCheckbox); 431 } 432 else if ($(selectedCheckbox).hasClass('product-nav')) { 433 var $code; 434 var navCheckbox = $(selectedCheckbox).find('input').get(0); 435 if (navCheckbox.id.indexOf("-nav") !== -1) { 436 $code = navCheckbox.id.split("-nav")[0]; 437 } 438 else { 439 $code = navCheckbox.id; 440 } 441 var product = $('#' + $code); 442 if (target === "checkbox") { 443 product.prop('checked', navCheckbox.checked); 444 } 445 else if (target === undefined && !navCheckbox.checked) { 446 product.prop('checked', true); 447 navCheckbox.checked = true; 448 } 449 else if (target === undefined && navCheckbox.checked) { 450 product.prop('checked', false); 451 navCheckbox.checked = false; 452 } 453
454 Amount.updateAmount(product, navCheckbox); 455 ProductGrouping.updateNavChecked(navCheckbox); 456 } 457 $(document).trigger('UpdateScreen'); 458 }, 459 460 selectProductBasedOnBundles: function (event) { 461 var bundleId = $(this).find('[id=BundleId]')[0].value; 462 463 var previouslySelectedBundleId = ""; 464 if ($('.moduleCt--septenary').length != 0) { 465 previouslySelectedBundleId = $('.moduleCt--septenary').find('[id=BundleId]')[0].value; 466 } 467 468 if (bundleId === previouslySelectedBundleId) { 469 return; 470 } 471 Bundles.removePreviouslySelectedBundlesProduct(); 472 var radioButtonValue = $(this).find('[id=ChooseBundle]')[0].value; 473 $("input[name=chkBundle][value='" + radioButtonValue + "']").prop("checked", true); 474 Bundles.applySelectedBundlesProduct(this); 475 var polygonCheckbox = ProductSelection.getPolygonDiscountProduct(); 476 Discount.applyDiscount(polygonCheckbox); 477 }, 478 479 selectProductBasedOnSearchAlertLink: function () { 480 var productId = $(this).data('product-code'); 481 var input = $("li.product-nav").find('input[value="' + productId + '"]'); 482 var checkbox = $(input).siblings('input[type=checkbox]'); 483 if (!$(this).data('selected') && !(checkbox.prop("checked"))) { 484 SearchAlerts.toggleAlertLinkText($(this)); 485 $(checkbox).trigger("click"); 486 } 487 else if ($(this).data('selected') && (checkbox.prop("checked"))) { 488 SearchAlerts.toggleAlertLinkText($(this)); 489 $(checkbox).trigger("click"); 490 } 491 else { 492 SearchAlerts.toggleAlertLinkText($(this)); 493 } 494 495 //event.preventDefault(); 496 }, 497 498 getPolygonDiscountProduct: function () { 499 var polygonCheckbox; 500 var $checkedProducts = $('.product-choices .product-selection'); 501 var civicaDiscAllowedProducts = $("#CivicaDiscAllowedProducts").val().split(';'); 502 if ($checkedProducts.length > 0) { 503 for (i = 0; i < $checkedProducts.length; i++) { 504 var checkbox = $checkedProducts.eq(i); 505 if (checkbox.is(':checked') && civicaDiscAllowedProducts.indexOf(checkbox.get(0).id) >= 0) { 506 polygonCheckbox = checkbox.get(0); 507 break; 508 } 509 } 510 } 511 return polygonCheckbox; 512 }, 513 514 tooltips: function () { 515 var $tooltip = $('#' + this.id + '-tooltip,#' + this.id + '-tooltip-nav'); 516 if ($(this).prop('checked')) { 517 $tooltip.slideDown('400', function () { 518 $tooltip.addClass('product-tooltip-glow'); 519 }); 520 window.setTimeout(function () { 521 $tooltip.removeClass('product-tooltip-glow'); 522 }, 3000); 523 } else { 524 $tooltip.fadeOut('400'); 525 } 526 }, 527 528 applyDiscountOnLoad: function () { 529 if ($('#UserType').val() !== "InternalUser") { 530 if ($("#ProductSelection").find('.product-choices .product-selection').is(':checked') === true && $('#IsMapSubmit').val() === "True") { 531 var arr = $("#ProductSelection").find('.product-choices .product-selection'); 532 var i; 533 for (i = 0; i < arr.length; i++) { 534 var civicaDiscAllowedProducts = $("#CivicaDiscAllowedProducts").val().split(';'); 535 if (arr[i].checked && civicaDiscAllowedProducts.indexOf(arr[i].id) >= 0) { 536 $(arr[i]).trigger("click").trigger("click"); 537 } 538 } 539 540 $('.moduleCt--septenary').removeClass('moduleCt--septenary'); 541 } 542 } 543 }, 544 545 checkLocalAuthorityProductLabelText: function () { 546 return "label:contains('" + $('#LocalAuthorityProductLabel').val() + "')"; 547 }, 548 549 checkLocalAuthorityHighwayProductLabelText: function () { 550 return "label:contains('" + $('#LocalAuthorityHighwayProductLabel').val() + "')"; 551 }, 552 553 checkLocalAuthorityLlc1ProductLabelText: function () { 554 return "label:contains('" + $('#LocalAuthorityLlc1ProductLabel').val() + "')"; 555 }, 556}; 557 558function PropertyTypeChange() { 559 560 if (confirm('Changing property type will clear all the selected products. Do you wish to proceed?')) { 561 $.ajax({
562 type: "GET", 563 async: false, 564 url: "/ProductSearch/UpdatePropertyType?radioPropertyType=" + $('input[name="radioPropertyType"]:checked').val(), 565 success: function (data) { 566 location.reload(); 567 }, 568 error: function () { 569 }, 570 }); 571 } else { 572 event.preventDefault(); 573 event.stopPropagation(); 574 } 575} 576 577var ProductOptions = { 578 579 toggleDisplay: function (product, productnav) { 580 581 var productCode = product.id; 582 583 var $thisoptions = $('[id=' + productCode + '-options]'); 584 585 $('.product-options-table input[type=checkbox]').off('click'); 586 $('.product-options-table input[type=radio]').off('click'); 587 if ($thisoptions.length !== 0 && !$thisoptions.is(':visible') && window.isHideProductBasedOnbundlesSelection === false) { 588 if (window.isFromClosebuttonAndLink == true) { 589 if (window.checkboxType == "productcheckbox" && $(productnav).prop('checked') == false) { 590 window.isFromClosebuttonAndLink = false; 591 } 592 else if (window.checkboxType == "navcheckbox" && $(product).prop('checked') == false) { 593 window.isFromClosebuttonAndLink = false; 594 } 595 } 596 597 $(product).prop('checked', true); 598 $(productnav).prop('checked', true); 599 $('.product-options-table input[type=checkbox]').on('click', ProductOptions.updateParentProductAmountForOptions); 600 $('.product-options-table input[type=radio]').on('click', ProductOptions.updateParentProductAmountForRadioOptions); 601 if ($('.product-options-table input[type=radio]:checked').length > 0) { 602 $('.product-options-table input[type=radio]:checked').off('click'); 603 } 604 605 if ((!window.isFromClosebuttonAndLink && !window.isProductRowAgainClick) || window.isApplyProductWhenOtherBundleSelect) { 606 ProductOptions.updateProductAmount(productCode, product, productnav, true); 607 ProductOptions.updateProductAmountForRadio(productCode, product, productnav, true); 608 Amount.updateAmount(product, productnav); 609 } 610 } else { 611 ProductOptions.hideOptions(productCode); 612 $(product).prop('checked', false); 613 $(productnav).prop('checked', false); 614 $('.product-options-table input[type=checkbox]').on('click', ProductOptions.updateParentProductAmountForOptions); 615 $('.product-options-table input[type=radio]').on('click', ProductOptions.updateParentProductAmountForRadioOption); 616 if (!window.isFromClosebuttonAndLink || window.isRemoveProductWhenOtherBundleSelect) { 617 Amount.updateAmount(product, productnav); 618 ProductOptions.updateProductAmount(productCode, product, productnav, false); 619 ProductOptions.updateProductAmountForRadio(productCode, product, productnav, false); 620 } 621 return; 622 } 623 ProductOptions.showOptions($thisoptions); 624 }, 625 626 showOptions: function ($thisoptions) { 627 if ($thisoptions.length > 0) { 628 $('.showOptions').hide('0'); 629 $('.showOptions').removeClass('showOptions'); 630 ProductOptions.displayOptions($thisoptions); 631 } 632 }, 633 634 hideOptions: function (productCode) { 635 $('[id=' + productCode + '-options]').attr("style", "display:none"); 636 $('[id=' + productCode + '-options]').removeClass('showOptions'); 637 if (window.isHideProductBasedOnbundlesSelection) { 638 $('[id=' + productCode + '-options]').attr("style", "display:none"); 639 $('[id=' + productCode + '-options]').removeClass('showOptions'); 640 } 641 }, 642 643 displayOptions: function ($options) { 644 645 window.isFromClosebuttonAndLink = false; 646 $options.attr("style", "display:block"); 647 $options.addClass('showOptions'); 648 649 // For the close icon 650 $options.on('click', '.options-close-link, .options-close-button', function (event) { 651 event.preventDefault(); 652 window.isFromClosebuttonAndLink = true; 653 $options.attr("style", "display:none"); 654 $options.removeClass('showOptions'); 655 if (window.isHideProductBasedOnbundlesSelection) { 656 $options.attr("style", "display:none"); 657 $options.removeClass('showOptions'); 658 } 659 }); 660 661 // For the close icon hover 662 $options.find('.options-close').hover( 663 function (event) { 664 $(this).toggleClass('options-close-hover', event.type === 'mouseenter'); 665 }); 666 667 668 }, 669 670 updateParentProductAmountForOptions: function () { 671 672 var selectedOptionPrice = parseFloat($(this).parent('td').siblings('td.product-price').text().replace('£', '')).toFixed(2);
673 var productCode = $(this).parentsUntil('.options-row').last().attr('data-productcode'); 674 675 var productCheckbox = $('#' + productCode); 676 var navCheckbox = $('#' + productCode + '-nav'); 677 678 679 if (this.checked) { 680 $('[id=' + this.id + ']').prop('checked', true); 681 var navProductPrice = parseFloat(navCheckbox.siblings('div.product-price').text().replace('£', '')).toFixed(2); 682 var amount = (parseFloat(navProductPrice) + parseFloat(selectedOptionPrice)).toFixed(2); 683 navCheckbox.siblings('div.product-price').text('£' + amount); 684 productCheckbox.parents('tr').children('td.product-price').text('£' + amount); 685 productCheckbox.siblings('#TotalCost').val(amount); 686 navCheckbox.siblings('#TotalCost').val(amount); 687 ProductOptions.updateTotalAmountBasedOnOptions(selectedOptionPrice, true); 688 689 } 690 else { 691 $('[id=' + this.id + ']').prop('checked', false); 692 var navProductPrice = parseFloat(navCheckbox.siblings('div.product-price').text().replace('£', '')).toFixed(2); 693 var amount = (parseFloat(navProductPrice) - parseFloat(selectedOptionPrice)).toFixed(2); 694 navCheckbox.siblings('div.product-price').text('£' + amount); 695 productCheckbox.parents('tr').children('td.product-price').text('£' + amount); 696 productCheckbox.siblings('#TotalCost').val(amount); 697 navCheckbox.siblings('#TotalCost').val(amount); 698 ProductOptions.updateTotalAmountBasedOnOptions(selectedOptionPrice, false); 699 } 700 Discount.applyDiscount(productCheckbox); 701 }, 702 703 updateParentProductAmountForRadioOptions: function () { 704 705 var selectedOptionPrice = parseFloat($(this).parent('td').siblings('td.product-price').text().replace('£', '')).toFixed(2); 706 var productCode = $(this).parentsUntil('.options-row').last().attr('data-productcode'); 707 708 var previouslySelectedRadioOptionPrice = $(this).closest('.product-options-table').find('input[type=radio]:checked').not(this).parent().siblings('.product-price').text().replace('£', ''); 709 $('[id=' + this.id + ']').closest('.product-options-table').find('input[type=radio]:checked').not(this).on('click', ProductOptions.updateParentProductAmountForRadioOptions); 710 $('[id=' + this.id + ']').closest('.product-options-table').find('input[type=radio]:checked').not(this).prop('checked', false); 711 var productCheckbox = $('#' + productCode); 712 var navCheckbox = $('#' + productCode + '-nav'); 713 714 var navProductPrice = parseFloat(navCheckbox.siblings('div.product-price').text().replace('£', '')).toFixed(2); 715 if (previouslySelectedRadioOptionPrice !== "") { 716 navProductPrice = (parseFloat(navProductPrice) - parseFloat(previouslySelectedRadioOptionPrice)).toFixed(2); 717 var updateTotalAmountBeforeDiscount = (parseFloat($("#TotalAmountBeforeDiscount").val()) - parseFloat(previouslySelectedRadioOptionPrice)).toFixed(2); 718 $("#TotalAmountBeforeDiscount").val(updateTotalAmountBeforeDiscount); 719 } 720 721 if (this.checked) { 722 $('[id=' + this.id + ']').prop('checked', true); 723 $('[id=' + this.id + ']').off('click'); 724 var amount = (parseFloat(navProductPrice) + parseFloat(selectedOptionPrice)).toFixed(2); 725 navCheckbox.siblings('div.product-price').text('£' + amount); 726 productCheckbox.parents('tr').children('td.product-price').text('£' + amount); 727 productCheckbox.siblings('#TotalCost').val(amount); 728 navCheckbox.siblings('#TotalCost').val(amount); 729 ProductOptions.updateTotalAmountBasedOnOptions(selectedOptionPrice, true); 730 } 731 else { 732 $('[id=' + this.id + ']').prop('checked', false); 733 $('[id=' + this.id + ']').on('click', ProductOptions.updateParentProductAmountForRadioOptions); 734 var amount = (parseFloat(navProductPrice) - parseFloat(selectedOptionPrice)).toFixed(2); 735 navCheckbox.siblings('div.product-price').text('£' + amount); 736 productCheckbox.parents('tr').children('td.product-price').text('£' + amount); 737 productCheckbox.siblings('#TotalCost').val(amount); 738 navCheckbox.siblings('#TotalCost').val(amount); 739 ProductOptions.updateTotalAmountBasedOnOptions(selectedOptionPrice, false); 740 } 741 Discount.applyDiscount(productCheckbox); 742 }, 743 744 updateTotalAmountBasedOnOptions: function (selectedOptionPrice, isOptionSelected) { 745 746 var amount; 747 if (isOptionSelected) { 748 amount = (parseFloat($("#TotalAmountBeforeDiscount").val()) + parseFloat(selectedOptionPrice)).toFixed(2); 749 $("#TotalAmount").text(amount); 750 } 751 else { 752 amount = (parseFloat($("#TotalAmountBeforeDiscount").val()) - parseFloat(selectedOptionPrice)).toFixed(2); 753 $("#TotalAmount").text(amount); 754 } 755 $("#TotalAmountBeforeDiscount").val(amount); 756 $("#TotalProductAmount").val(parseFloat($("#TotalAmount").text()).toFixed(2)) 757 758 }, 759 760 updateProductAmount: function (productCode, product, productnav, isProductSelected) {
761 var selectedOptionsList = $('#' + productCode + '-options').find('input[type=checkbox]:checked').parent('td').siblings('td.product-price'); 762 var i; 763 var selectedOptionsAmount = 0; 764 for (i = 0; i < selectedOptionsList.length; i++) { 765 selectedOptionsAmount = selectedOptionsAmount + parseFloat(selectedOptionsList.eq(i).text().replace('£', '')); 766 } 767 if (selectedOptionsList.length > 0) { 768 if (isProductSelected) { 769 var navProductAmount = parseFloat($(productnav).siblings('.product-price').text().replace('£', '')) + parseFloat(selectedOptionsAmount); 770 $(productnav).siblings('.product-price').text('£' + navProductAmount.toFixed(2)); 771 $(product).parent('td').siblings('.product-price').text('£' + navProductAmount.toFixed(2)); 772 $(product).siblings('#TotalCost').val(navProductAmount.toFixed(2)); 773 $(productnav).siblings('#TotalCost').val(navProductAmount.toFixed(2)); 774 } 775 else { 776 var productAmount = parseFloat($(productnav).siblings('.product-price').text().replace('£', '')) - parseFloat(selectedOptionsAmount); 777 $(productnav).siblings('.product-price').text('£' + (productAmount).toFixed(2)); 778 $(product).parent('td').siblings('.product-price').text('£' + (productAmount).toFixed(2)); 779 $(product).siblings('#TotalCost').val(productAmount.toFixed(2)); 780 $(productnav).siblings('#TotalCost').val(productAmount.toFixed(2)); 781 } 782 } 783 }, 784 785 updateProductAmountForRadio: function (productCode, product, productnav, isProductSelected) { 786 var selectedOptionsList = $('#' + productCode + '-options').find('input[type=radio]:checked').parent('td').siblings('td.product-price'); 787 var i; 788 var selectedOptionsAmount = 0; 789 for (i = 0; i < selectedOptionsList.length; i++) { 790 selectedOptionsAmount = selectedOptionsAmount + parseFloat(selectedOptionsList.eq(i).text().replace('£', '')); 791 } 792 if (selectedOptionsList.length > 0) { 793 if (isProductSelected) { 794 var navProductAmount = parseFloat($(productnav).siblings('.product-price').text().replace('£', '')) + parseFloat(selectedOptionsAmount); 795 $(productnav).siblings('.product-price').text('£' + navProductAmount.toFixed(2)); 796 $(product).parent('td').siblings('.product-price').text('£' + navProductAmount.toFixed(2)); 797 $(product).siblings('#TotalCost').val(navProductAmount.toFixed(2)); 798 $(productnav).siblings('#TotalCost').val(navProductAmount.toFixed(2)); 799 } 800 else { 801 var productAmount = parseFloat($(productnav).siblings('.product-price').text().replace('£', '')) - parseFloat(selectedOptionsAmount); 802 $(productnav).siblings('.product-price').text('£' + (productAmount).toFixed(2)); 803 $(product).parent('td').siblings('.product-price').text('£' + (productAmount).toFixed(2)); 804 $(product).siblings('#TotalCost').val(productAmount.toFixed(2)); 805 $(productnav).siblings('#TotalCost').val(productAmount.toFixed(2)); 806 } 807 } 808 }, 809}; 810 811var Bundles = { 812 813 CLASS_BUNDLES_DETAILS_HOVER: 'moduleCt--secondary', 814 CLASS_BUNDLES_DETAILS_SELECTED: 'moduleCt--septenary', 815 CLASS_BUNDLES_DETAILS_NORMAL: 'moduleCt--quinary', 816 817 setDetailsSelectedClasses: function (bundleId) { 818 819 var bundle = ($($('[id=Bundle]').find('input[value="' + bundleId + '"]')).parent('#Bundle')); 820 var radioButtonValue = bundle.find('[id=ChooseBundle]')[0].value; 821 $("input[name=chkBundle][value='" + radioButtonValue + "']").prop("checked", true); 822 823 $('input[value="' + bundleId + '"]').closest('.bundle-details') 824 .addClass(Bundles.CLASS_BUNDLES_DETAILS_SELECTED) 825 .removeClass(Bundles.CLASS_BUNDLES_DETAILS_HOVER + " " + Bundles.CLASS_BUNDLES_DETAILS_NORMAL); 826 }, 827 828 removeDetailsSelectedClasses: function () {
829 $('.' + Bundles.CLASS_BUNDLES_DETAILS_SELECTED) 830 .addClass(Bundles.CLASS_BUNDLES_DETAILS_NORMAL) 831 .removeClass(Bundles.CLASS_BUNDLES_DETAILS_SELECTED); 832 }, 833 834 removePreviouslySelectedBundlesProduct: function () { 835 836 var alreadyAppliedbundleProducts = $('.moduleCt--septenary').find('[id=Productid]'); 837 if (alreadyAppliedbundleProducts.length > 0) { 838 Bundles.removeProductsSelection(alreadyAppliedbundleProducts); 839 } 840 else if ($('#BackToProductSelection').val() == "1") { 841 if ($('#AppliedBundleId').val() != "") { 842 var previousSelectedBundleProducts = $('input[value = "' + $('#AppliedBundleId').val() + '"]').parent('div#Bundle').find('[id=Productid]'); 843 if (previousSelectedBundleProducts.length > 0) { 844 Bundles.removeProductsSelection(previousSelectedBundleProducts); 845 } 846 } 847 } 848 }, 849 850 removeProductsSelection: function (alreadyAppliedbundleProducts) { 851 var i; 852 var isBothLAProductSelected = ''; 853 for (i = 0; i < alreadyAppliedbundleProducts.length; i++) { 854 var productId = alreadyAppliedbundleProducts[i].value; 855 var input = $("li.product-nav").find('input[value="' + productId + '"]'); 856 857 if (productId === "") { 858 if (isBothLAProductSelected === '') { 859 isBothLAProductSelected = "False"; 860 } 861 else { 862 isBothLAProductSelected = "True"; 863 } 864 var checkboxNav = getProductCheckbox("li.product-nav", isBothLAProductSelected); 865 var checkbox = getProductCheckbox(".product-row td", isBothLAProductSelected); 866 867 window.isHideProductBasedOnbundlesSelection = true; 868 window.isSelectBundleBasedonProductSelection = false; 869 window.isRemoveProductWhenOtherBundleSelect = true; 870 $(checkboxNav).trigger("click"); 871 Bundles.removeBundleProductDisocunt(checkbox, checkboxNav); 872 } 873 else { 874 if (input.length > 0) { 875 876 var checkboxNav = $(input).siblings('input[type=checkbox]'); 877 var checkbox = $(".product-choices").find('input[value="' + productId + '"]').siblings('input[type=checkbox]'); 878 window.isHideProductBasedOnbundlesSelection = true; 879 window.isSelectBundleBasedonProductSelection = false; 880 window.isRemoveProductWhenOtherBundleSelect = true; 881 $(checkboxNav).trigger("click"); 882 Bundles.removeBundleProductDisocunt(checkbox, checkboxNav); 883 } 884 } 885 } 886 window.isHideProductBasedOnbundlesSelection = false; 887 window.isSelectBundleBasedonProductSelection = true; 888 window.isRemoveProductWhenOtherBundleSelect = false; 889 Bundles.removeDetailsSelectedClasses(); 890 }, 891 892 applySelectedBundlesProduct: function (selectedBundle) { 893 894 var bundleProducts = $(selectedBundle).find('[id=Productid]'); 895 var bundleId = $(selectedBundle).find('[id=BundleId]')[0].value; 896 var isLLC1Products = $(selectedBundle).find('[id=IsLLC1Product]'); 897 var i; 898 var allProductCount = 0; 899 Bundles.removeProductRowHighlight(); 900 for (i = 0; i < bundleProducts.length; i++) { 901 var productId = bundleProducts[i].value; 902 var isLLC1Product = isLLC1Products[i].value; 903 var inputNav = $("li.product-nav").find('input[value="' + productId + '"]') 904 905 var bundleProductDiscount = Bundles.getBundleProductDisocuntExcVat(productId, bundleId); 906 var bundleProductDiscountIncVat = Bundles.getBundleProductDisocuntIncVat(productId, bundleId); 907 908 if (productId === "") { 909 allProductCount++; 910 911 var checkboxNav = getProductCheckbox("li.product-nav", isLLC1Product); 912 var checkbox = getProductCheckbox(".product-row td", isLLC1Product); 913 914 //var labelNav = $("li.product-nav").children(ProductSelection.checkLocalAuthorityProductLabelText()); 915 //var checkboxNav = $(labelNav).siblings('input[type=checkbox]'); 916 917 //var label = $(".product-row td").children(ProductSelection.checkLocalAuthorityProductLabelText()); 918 //var checkbox = $(label).siblings('input[type=checkbox]'); 919 920 if (!(checkboxNav.prop("checked"))) { 921 window.isSelectBundleBasedonProductSelection = false; 922 window.isApplyProductWhenOtherBundleSelect = true; 923 $(checkboxNav).trigger("click"); 924 //let label = $(".product-row td").children(ProductSelection.checkLocalAuthorityProductLabelText()); 925 //checkbox = $(label).siblings('input[type=checkbox]'); 926 checkbox = getProductCheckbox(".product-row td", isLLC1Product); 927 } 928 Bundles.setBundleProductDisocuntWithSelectedProduct(checkbox, checkboxNav, bundleProductDiscount, bundleProductDiscountIncVat); 929 Bundles.highlightProductRowsBasedOnBundleSelection(checkbox, checkboxNav); 930 } 931 else { 932 if (inputNav.length > 0) { 933 934 allProductCount++; 935 var checkboxNav = $(inputNav).siblings('input[type=checkbox]'); 936 var checkbox = $(".product-choices").find('input[value="' + productId + '"]').siblings('input[type=checkbox]'); 937 938 if (!(checkboxNav.prop("checked"))) { 939 window.isSelectBundleBasedonProductSelection = false; 940 window.isApplyProductWhenOtherBundleSelect = true; 941 $(checkboxNav).trigger("click"); 942 checkbox = $(".product-choices").find('input[value="' + productId + '"]').siblings('input[type=checkbox]'); 943 Bundles.setBundleProductDisocuntWithSelectedProduct(checkbox, checkboxNav, bundleProductDiscount, bundleProductDiscountIncVat); 944 Bundles.highlightProductRowsBasedOnBundleSelection(checkbox, checkboxNav); 945 } 946 } 947 } 948 } 949 if (bundleProducts.length === allProductCount) { 950 Bundles.setDetailsSelectedClasses(bundleId); 951 } 952 else { 953 Bundles.removeDetailsSelectedClasses(); 954 } 955 window.isSelectBundleBasedonProductSelection = true; 956 window.isApplyProductWhenOtherBundleSelect = false; 957 }, 958 959 selectBundleBasedonProductSelection: function () { 960 961 var productRow = $('.product-row'); 962 var alreadyCheckedProduct = productRow.find('input[type=checkbox]:checked'); 963 var productIdHiddenFields = alreadyCheckedProduct.siblings("input#ProductId"); 964 if (productIdHiddenFields.length > 0) { 965 966 var productIds = []; 967 var productsLabel = []; 968 var products = {}; 969 var matchedBundles = {}; 970 971 products = Bundles.getSelectedProducts(productIdHiddenFields, productIds, productsLabel); 972 973 var allBundle = $('[id=Bundle]'); 974 if (productIds.length >= 1) { 975 976 matchedBundles = Bundles.getMatchedBundles(allBundle, products); 977 Bundles.highlightMatchedBundle(matchedBundles); 978 } 979 else { 980 Bundles.removeDetailsSelectedClasses(); 981 $('input[name="chkBundle"]').attr('checked', false); 982 Bundles.removeProductRowHighlight(); 983 Bundles.removeAllBundleProductDiscount(); 984 } 985 } 986 else { 987 Bundles.removeAllBundleProductDiscount(); 988 } 989 990 }, 991 992 getSelectedProducts: function (productIdHiddenFields, productIds, productsLabel) { 993 var products = {}; 994 for (i = 0; i < productIdHiddenFields.length; i++) { 995 var labelText = productIdHiddenFields.eq(i).siblings('.label-product-selection')[0].innerText; 996 productIds.push(productIdHiddenFields[i].value); 997 productsLabel.push(labelText); 998 var p = {};
999 p[labelText] = productIdHiddenFields[i].value; 1000 Object.assign(products, p); 1001 } 1002 1003 return products; 1004 }, 1005 1006 getBundleProductsId: function (bundle) { 1007 1008 var bundleProductIds = {}; 1009 var bundleProducts = bundle.find('[id=Productid]'); 1010 var isLLC1Products = $(bundle).find('[id=IsLLC1Product]'); 1011 if (bundleProducts.length > 0) { 1012 for (j = 0; j < bundleProducts.length; j++) { 1013 var bundleProductId = bundleProducts[j].value; 1014 var isLLC1Product = isLLC1Products[j].value; 1015 var bundleProdDiscount = $("#BundleProductPriceDifference_" + bundleProductId + "_" + bundle.find('#BundleId').val()).val(); 1016 var bundleProdDiscountIncVat = $("#BundleProductPriceDifferenceIncVat_" + bundleProductId + "_" + bundle.find('#BundleId').val()).val(); 1017 if (bundleProductId === "") { 1018 //var localAuthoritySearchLabel = $("li.product-nav").children(ProductSelection.checkLocalAuthorityProductLabelText()); 1019 //var localAuthorityLLC1SearchLabel = $("li.product-nav").children(ProductSelection.checkLocalAuthorityLlc1ProductLabelText()); 1020 //if (localAuthoritySearchLabel.length > 0) { 1021 // bundleProdDiscount = $("#BundleProductPriceDifference_" + bundleProductId + "_" + bundle.find('#BundleId').val()).val(); 1022 // bundleProdDiscountIncVat = $("#BundleProductPriceDifferenceIncVat_" + bundleProductId + "_" + bundle.find('#BundleId').val()).val(); 1023 // bundleProductId = $("li.product-nav").children(ProductSelection.checkLocalAuthorityProductLabelText()).siblings('#ProductId')[0].value; 1024 //} 1025 //else if (localAuthorityLLC1SearchLabel.length > 0) { 1026 // bundleProdDiscount = $("#BundleProductPriceDifference_" + bundleProductId + "_" + bundle.find('#BundleId').val()).val(); 1027 // bundleProdDiscountIncVat = $("#BundleProductPriceDifferenceIncVat_" + bundleProductId + "_" + bundle.find('#BundleId').val()).val(); 1028 // bundleProductId = $("li.product-nav").children(ProductSelection.checkLocalAuthorityLlc1ProductLabelText()).siblings('#ProductId')[0].value; 1029 //} 1030 var localAuthoritySearchLabel; 1031 1032 if (isLLC1Product === "True") { 1033 // LLC1 product 1034 localAuthoritySearchLabel = $("li.product-nav").children( 1035 ProductSelection.checkLocalAuthorityLlc1ProductLabelText() 1036 ); 1037 } 1038 else { 1039 //CON29 product 1040 localAuthoritySearchLabel = $("li.product-nav").children( 1041 ProductSelection.checkLocalAuthorityProductLabelText() 1042 ); 1043 } 1044 1045 if (localAuthoritySearchLabel.length > 0) { 1046 var bundleId = bundle.find('#BundleId').val(); 1047 1048 bundleProdDiscount = $( 1049 "#BundleProductPriceDifference_" + bundleProductId + "_" + bundleId 1050 ).val(); 1051 1052 bundleProdDiscountIncVat = $( 1053 "#BundleProductPriceDifferenceIncVat_" + bundleProductId + "_" + bundleId 1054 ).val(); 1055 1056 bundleProductId = localAuthoritySearchLabel 1057 .siblings('#ProductId') 1058 .val(); 1059 } 1060 1061 } 1062 1063 bundleProductIds[bundleProductId] = bundleProdDiscount + "_" + bundleProdDiscountIncVat; 1064 } 1065 } 1066 1067 return bundleProductIds; 1068 }, 1069 1070 getMatchedBundles: function (allBundle, products) { 1071 1072 var matchedBundles = {}; 1073 var prod = {}; 1074 Object.assign(prod, products); 1075 var productValues = Object.keys(prod).map(function (e) { 1076 return prod[e]; 1077 }); 1078 if (allBundle.length > 0) { 1079 for (var i = 0; i < allBundle.length; i++) { 1080 { 1081 var bundleProductIds = Bundles.getBundleProductsId(allBu
1081ndle.eq(i)); 1082 1083 var isBundleExist = Bundles.CheckBundleForSelectedProductExits(productValues, Object.keys(bundleProductIds)); 1084 1085 if (isBundleExist) { 1086 1087 var b = {}; 1088 b[allBundle.eq(i).find('[id=BundleId]')[0].value] = allBundle.eq(i).find('[id=bundleDiscount]')[0].value; 1089 Object.assign(matchedBundles, b); 1090 } 1091 } 1092 } 1093 } 1094 return matchedBundles; 1095 }, 1096 1097 CheckBundleForSelectedProductExits: function (productValues, bundleProductIds) { 1098 for (var j = 0; j < bundleProductIds.length; j++) { 1099 if (productValues.indexOf(bundleProductIds[j]) === -1) { 1100 return false; 1101 } 1102 } 1103 return true; 1104 }, 1105 1106 highlightMatchedBundle: function (matchedBundles) { 1107 var bundleProductIds = []; 1108 if (matchedBundles != null && Object.keys(matchedBundles).length > 0) { 1109 1110 if (Object.keys(matchedBundles).length === 1) { 1111 Bundles.removeDetailsSelectedClasses(); 1112 var bundleId = Object.keys(matchedBundles); 1113 Bundles.setDetailsSelectedClasses(bundleId); 1114 bundleProductIds = Bundles.getBundleProductsId(($($('[id=Bundle]').find('input[value="' + bundleId + '"]')).parent('#Bundle'))); 1115 } 1116 else { 1117 var keys = Object.keys(matchedBundles); 1118 keys.sort(function (a, b) { 1119 return matchedBundles[b] - matchedBundles[a]; 1120 }); 1121 var bundleProvideMaxdiscount = keys.slice(0, 1); 1122 var newBundleWithMaximumDiscount = bundleProvideMaxdiscount; 1123 var currentSelectedBundleId = $('#AppliedBundleId').val(); 1124 if (keys.indexOf(currentSelectedBundleId) >= 0) { 1125 var currentSelectedBundleDiscount = matchedBundles[currentSelectedBundleId]; 1126 var maxBundleDiscount = matchedBundles[bundleProvideMaxdiscount]; 1127 if (parseFloat(currentSelectedBundleDiscount) >= parseFloat(maxBundleDiscount)) { 1128 newBundleWithMaximumDiscount = currentSelectedBundleId; 1129 } 1130 } 1131 1132 if (bundleProvideMaxdiscount !== 'undefined') { 1133 Bundles.removeDetailsSelectedClasses(); 1134 Bundles.setDetailsSelectedClasses(newBundleWithMaximumDiscount); 1135 bundleProductIds = Bundles.getBundleProductsId($($('[id=Bundle]').find('input[value="' + newBundleWithMaximumDiscount + '"]')).parent('#Bundle')); 1136 } 1137 } 1138 Bundles.highlightProductRowsBasedOnProductSelection(bundleProductIds); 1139 } 1140 else { 1141 Bundles.removeDetailsSelectedClasses(); 1142 $('input[name="chkBundle"]').attr('checked', false); 1143 Bundles.removeProductRowHighlight(); 1144 Bundles.removeAllBundleProductDiscount(); 1145 } 1146 }, 1147 1148 highlightProductRowsBasedOnProductSelection: function (bundleProductIds) { 1149 1150 Bundles.removeProductRowHighlight(); 1151 Bundles.removeAllBundleProductDiscount(); 1152 1153 for (var i = 0; i < Object.keys(bundleProductIds).length; i++) { 1154 1155 var checkboxNav = $("li.product-nav").find('input[value="' + Object.keys(bundleProductIds)[i] + '"]').siblings('input[type=checkbox]'); 1156 var checkbox = $(".product-choices").find('input[value="' + Object.keys(bundleProductIds)[i] + '"]').siblings('input[type=checkbox]'); 1157 var bundleProductDiscount = bundleProductIds[Object.keys(bundleProductIds)[i]]; 1158 1159 if (bundleProductDiscount !== "") { 1160 var bundleProductDiscounts = bundleProductDiscount.split('_'); 1161 Bundles.setBundleProductDisocuntWithSelectedProduct(checkbox, checkboxNav, bundleProductDiscounts[0], bundleProductDiscounts[1]); 1162 } 1163 $(checkbox).closest('tr').addClass('bundle-row-checked-highlight'); 1164 $(checkboxNav).closest('li').addClass('bundle-row-checked-highlight'); 1165 } 1166 }, 1167 1168 highlightProductRowsBasedOnBundleSelection: function (checkbox, checkboxNav) { 1169 1170 $(checkbox).closest('tr').addClass('bundle-row-checked-highlight'); 1171 $(checkboxNav).closest('li').addClass('bundle-row-checked-highlight'); 1172 }, 1173 1174 highlightProductRowsBasedOnBundleMouseHover: function (checkbox, checkboxNav, event) { 1175 1176 $(checkbox).closest('tr').toggleClass( 1177 'bundle-row-highlight', event.type === 'mouseenter'); 1178 $(checkboxNav).closest('li').toggleClass( 1179 'bundle-row-highlight', event.type === 'mouseenter'); 1180 }, 1181 1182 removeProductRowHighlight: function () { 1183 // remove the existing highlights 1184 $('.product-choices').find('.bundle-row-checked-highlight') 1185 .removeClass('bundle-row-checked-highlight'); 1186 $('#product-grouping-tree').find('.bundle-row-checked-highlight') 1187 .removeClass('bundle-row-checked-highlight'); 1188 $('.product-choices').find('.bundle-row-highlight').removeClass('bundle-row-highlight'); 1189 $('#product-grouping-tree').find('.bundle-row-highlight').removeClass('bundle-row-highlight'); 1190 }, 1191 1192 bindBundleClickOnChooseBundleLink: function () { 1193 //$(this).closest('div').find('#Bundle').trigger('click'); 1194 //event.preventDefault(); 1195 }, 1196 1197 setDetailsHoverClasses: function ($elem, event) { 1198 $elem.css('cursor', 'pointer'); 1199 if ($elem.hasClass(Bundles.CLASS_BUNDLES_DETAILS_NORMAL) || 1200 $elem.hasClass(Bundles.CLASS_BUNDLES_DETAILS_HOVER)) { 1201 1202 $elem.toggleClass(Bundles.CLASS_BUNDLES_DETAILS_HOVER, event.type === 'mouseenter'); 1203 $elem.toggleClass(Bundles.CLASS_BUNDLES_DETAILS_NORMAL, event.type !== 'mouseenter'); 1204 } 1205 }, 1206 1207 toggleHighlights: function (event) { 1208 1209 var $elem = $(this); 1210 var bundleProducts = $elem.find('[id=Productid]'); 1211 var is = $elem.find('[id=Productid]'); 1212 var isLLC1Products = $elem.find('[id=IsLLC1Product]'); 1213 Bundles.setDetailsHoverClasses($elem, event); 1214 1215 for (i = 0; i < bundleProducts.length; i++) { 1216 var productId = bundleProducts[i].value; 1217 var isLLC1Product = isLLC1Products[i].value; 1218 var inputNav = $("li.product-nav").find('input[value="' + productId + '"]'); 1219 if (productId === "") { 1220 1221 var checkboxNav = getProductCheckbox("li.product-nav", isLLC1Product); 1222 var checkbox = getProductCheckbox(".product-row td", isLLC1Product); 1223 1224 //var labelNav = $("li.product-nav").children(ProductSelection.checkLocalAuthorityProductLabelText()); 1225 //var checkboxNav = $(labelNav).siblings('input[type=checkbox]'); 1226 1227 //var label = $(".product-row td").children(ProductSelection.checkLocalAuthorityProductLabelText()); 1228 //var checkbox = $(label).siblings('input[type=checkbox]'); 1229 1230 1231 Bundles.highlightProductRowsBasedOnBundleMouseHover(checkbox, checkboxNav, event); 1232 } 1233 else { 1234 if (inputNav.length > 0) { 1235 var checkboxNav = $(inputNav).siblings('input[type=checkbox]'); 1236 var checkbox = $(".product-choices").find('input[value="' + productId + '"]').siblings('input[type=checkbox]'); 1237 Bundles.highlightProductRowsBasedOnBundleMouseHover(checkbox, checkboxNav, event); 1238 } 1239 } 1240 } 1241 }, 1242 1243 setBundleProductDisocuntWithSelectedProduct: function (checkbox, checkboxNav, bundleProductDiscount, bundleProductDiscountIncVat) { 1244 $(checkbox).siblings('#BundleProductDiscount').val(bundleProductDiscount); 1245 $(checkboxNav).siblings('#BundleProductDiscount').val(bundleProductDiscount); 1246 1247 $(checkbox).siblings('#BundleProductDiscountIncVat').val(bundleProductDiscountIncVat); 1248 $(checkboxNav).siblings('#BundleProductDiscountIncVat').val(bundleProductDiscountIncVat); 1249 }, 1250 1251 removeBundleProductDisocunt: function (checkbox, checkboxNav) { 1252 $(checkbox).siblings('#BundleProductDiscount').val(""); 1253 $(checkboxNav).siblings('#BundleProductDiscount').val(""); 1254 1255 $(checkbox).siblings('#BundleProductDiscountIncVat').val(""); 1256 $(checkboxNav).siblings('#BundleProductDiscountIncVat').val(""); 1257 }, 1258 1259 removeAllBundleProductDiscount: function () { 1260 $('[id=BundleProductDiscount]').val(''); 1261 $('[id=BundleProductDiscountIncVat]').val(''); 1262 }, 1263 1264 getBundleProductDisocuntExcVat: function (productId, bundleId) { 1265 var bundleProductPriceDifference = $("#BundleProductPriceDifference_" + productId + "_" + bundleId).val(); 1266 return bundleProductPriceDifference; 1267 }, 1268 1269 getBundleProductDisocuntIncVat: function (productId, bundleId) { 1270 var bundleProductPriceDifferenceIncVat = $("#BundleProductPriceDifferenceIncVat_" + productId + "_" + bundleId).val(); 1271 return bundleProductPriceDifferenceIncVat; 1272 } 1273}; 1274 1275function getProductCheckbox(selector, isLLC1Product) { 1276 var container = $(selector); 1277 var label; 1278 if (isLLC1Product === 'True') { 1279 //LLC1 product 1280 label = container.children( 1281 ProductSelection.checkLocalAuthorityLlc1ProductLabelText() 1282 ); 1283 } 1284 else { 1285 //CON29 product 1286 label = container.children( 1287 ProductSelection.checkLocalAuthorityProductLabelText() 1288 ); 1289 } 1290 1291 return label.siblings('input[type="checkbox"]'); 1292} 1293 1294var Amount = { 1295 1296 updateAmount: function (product, productnav) { 1297 var amount; 1298 if ($(product).prop("checked") == true || $(productnav).prop("checked") == true) { 1299 amount = (parseFloat($("#TotalAmountBeforeDiscount").val()) + parseFloat($(product).parents('tr').children('td.product-price').text().replace('£', ''))).toFixed(2); 1300 $("#TotalAmount").text(amount); 1301 } 1302 else { 1303 amount = (parseFloat($("#TotalAmountBeforeDiscount").val()) - parseFloat($(product).parents('tr').children('td.product-price').text().replace('£', ''))).toFixed(2); 1304 $("#TotalAmount").text(amount); 1305 } 1306 $('#TotalAmountBeforeDiscount').val(amount); 1307 $("#TotalProductAmount").val(parseFloat($("#TotalAmount").text()).toFixed(2)); 1308 }, 1309 1310 updateTotalAmountAfterApplyDiscount: function (discount) { 1311 1312 $('#TotalAmount').text((parseFloat($('#TotalAmountBeforeDiscount').val()).toFixed(2) - parseFloat(discount).toFixed(2)).toFixed(2)); 1313 $("#TotalProductAmount").val(parseFloat($("#TotalAmount").text()).toFixed(2)); 1314 } 1315} 1316 1317var Discount = { 1318 applyDiscount: function (selectedCheckbox) { 1319 var bundleDiscount = 0.00; 1320 var ploygonDiscount = 0.00; 1321 1322 if ($('#UserType').val() !== "InternalUser") { 1323 ploygonDiscount = Discount.applyPolygonDiscount(selectedCheckbox); 1324 } 1325 bundleDiscount = Discount.applyBundleDiscount(); 1326 if (ploygonDiscount === 0.00 && bundleDiscount === 0.00) { 1327 $('#m-totals').children('.search-order-discount').remove(); 1328 $('.search-order-totals').removeClass('highLightParagraph').removeAttr('style'); 1329 } 1330 var totalDiscount = bundleDiscount + ploygonDiscount;
1331 Amount.updateTotalAmountAfterApplyDiscount(totalDiscount); 1332 }, 1333 applyBundleDiscount: function () { 1334 var bundleDiscount = 0.00; 1335 var bundleName = ""; 1336 var bundleId = ""; 1337 if ($('.moduleCt--septenary').length != 0) { 1338 1339 var selectedBundle = $('.moduleCt--septenary').find('[id=Bundle]'); 1340 bundleName = $(selectedBundle).find('#bundleName').val(); 1341 bundleId = $(selectedBundle).find('#BundleId').val(); 1342 bundleDiscount = parseFloat($(selectedBundle).find('#bundleDiscount').val()); 1343 1344 if ($('#bundleDisCountParagraph').length !== 0) { 1345 if ($('#AppliedBundleName').val() === bundleName) { 1346 bundleDiscount = parseFloat($('#AppliedBundleDiscount').val()); 1347 return bundleDiscount; 1348 } 1349 else { 1350 $('.search-order-discount').children('#bundleDisCountParagraph').remove(); 1351 } 1352 } 1353 1354 if ($('.search-order-discount').length === 0) { 1355 var discountDiv = '<div class="search-order-discount"></div>'; 1356 $('.search-order-totals').addClass('highLightParagraph').css({ "padding-top": "0.8em;" }).before(discountDiv); 1357 } 1358 1359 var bundleDiscountParagraph = '<p id="bundleDisCountParagraph"><span class="left">' + bundleName + ' discount</span><span class="right bundle-discount-highlight">£ -' + bundleDiscount.toFixed(2) + '</span></p>'; 1360 $('.search-order-discount').append(bundleDiscountParagraph); 1361 1362 } 1363 else { 1364 $('.search-order-discount').children('#bundleDisCountParagraph').remove(); 1365 bundleDiscount = 0.00; 1366 1367 } 1368 $('#AppliedBundleDiscount').val(bundleDiscount.toFixed(2)); 1369 $('#AppliedBundleName').val(bundleName); 1370 $('#AppliedBundleId').val(bundleId); 1371 1372 return bundleDiscount; 1373 }, 1374 1375 applyPolygonDiscount: function (selectedCheckbox) { 1376 var ploygonDiscount = 0.00; 1377 var civicaDiscAllowedProducts = $("#CivicaDiscAllowedProducts").val().split(';'); 1378 var productName = ""; 1379 var productId = ""; 1380 var $code; 1381 if (selectedCheckbox !== undefined) { 1382 var checkbox = selectedCheckbox; 1383 if (selectedCheckbox.id != "" && jQuery.type(selectedCheckbox.id) == 'string') { 1384 $code = selectedCheckbox.id; 1385 } 1386 else if ($(selectedCheckbox).hasClass('product-nav')) { 1387 1388 var navCheckbox = $(selectedCheckbox).find('input').get(0); 1389 checkbox = navCheckbox; 1390 if (navCheckbox.id.indexOf("-nav") !== -1) { 1391 $code = navCheckbox.id.split("-nav")[0]; 1392 } 1393 else { 1394 $code = navCheckbox.id; 1395 } 1396 } 1397 1398 if (civicaDiscAllowedProducts.indexOf($code) >= 0 && $('#IsMapSubmit').val() === "True") { 1399 1400 if (checkbox.checked) { 1401 ploygonDiscount = parseFloat($('#CivicaDiscount').val()); 1402 if ($('#polyDiscountParagraph').length !== 0) { 1403 productName = $('#AppliedPolygonDiscountProductName').val(); 1404 productId = $('#AppliedPolygonDiscountProductId').val(); 1405 return ploygonDiscount; 1406 } 1407 productName = $(checkbox).siblings('label').text(); 1408 productId = $(checkbox).siblings('#ProductId').val(); 1409 if ($('.search-order-discount').length === 0) { 1410 var discountDiv = '<div class="search-order-discount"></div>'; 1411 $('.search-order-totals').addClass('highLightParagraph').css({ "padding-top": "0.8em;" }).before(discountDiv); 1412 } 1413 var polygonDiscountParagraph = '<p id="polyDiscountParagraph"><span class="left"> ' + productName + ' discount</span><span class="right bundle-discount-highlight">£ -' + ploygonDiscount.toFixed(2) + '</span></p>'; 1414 $('.search-order-discount').append(polygonDiscountParagraph); 1415 } 1416 else { 1417 $('.search-order-discount').children('#polyDiscountParagraph').remove(); 1418 ploygonDiscount = 0.00; 1419 productName = ""; 1420 productId = ""; 1421 } 1422 } 1423 else { 1424 if ($('#polyDiscountParagraph').length !== 0) { 1425 ploygonDiscount = parseFloat($('#CivicaDiscount').val()); 1426 productName = $('#AppliedPolygonDiscountProductName').val(); 1427 productId = $('#AppliedPolygonDiscountProductId').val(); 1428 } 1429 } 1430 } 1431 $('#AppliedPolygonDiscount').val(ploygonDiscount.toFixed(2)); 1432 $('#AppliedPolygonDiscountProductName').val(productName); 1433 $('#AppliedPolygonDiscountProductId').val(productId); 1434 return ploygonDiscount; 1435 } 1436} 1437 1438var ProductAdditionalQuestions = { 1439 1440 updateTextBoxes: function () { 1441 var textboxValue = this.value; 1442 var data = $('[id=' + this.id + ']'); 1443 $.each(data, function (index, item) { 1444 $(item).val(textboxValue); 1445 }); 1446 }, 1447 1448 updateRadioButton: function () { 1449 var radioButtonState = this.checked; 1450 $.each($('[id=' + this.id + ']'), function (index, radioButton) { 1451 radioButton.checked = radioButtonState; 1452 }); 1453 }, 1454 1455 updateList: function (element) { 1456 var listData = element[0].value; 1457 $.each($('[id=' + element[0].id + ']'), function (index, list) { 1458 list.value = listData; 1459 }); 1460 }, 1461 1462 updateCheckboxes: function () { 1463 1464 var selectedData = ""; 1465 var checkboxState = this.checked; 1466 var checkboxId = $(this).parent('div')[0].id + "_SelectedCheckboxes"; 1467 if (checkboxState) { 1468 selectedData = $("#" + checkboxId).val() + $(this).val() + ";"; 1469 1470 } else { 1471 selectedData = $("#" + checkboxId).val().replace($(this).val() + ";", ""); 1472 } 1473 1474 $("[id = " + checkboxId + "]").val(selectedData); 1475 $.each($('[id=' + this.id + ']'), function (index, checkbox) { 1476 checkbox.checked = checkboxState; 1477 ProductQuestionsValidation.vadiateInput($("#" + checkboxId)); 1478 }); 1479 }, 1480 1481 inputValidationOnFocus: function (element) { 1482 ProductQuestionsValidation.vadiateInputOnFocus(element); 1483 }, 1484} 1485 1486var ProductQuestionsValidation = { 1487 1488 validateForm: function (a) { 1489 var b = !1; 1490 if (a.find(".form--surrogate").each(function (a) { 1491 var c = $(this); 1492 c.find(".error").removeClass("error"), 1493 c.find(".form-error").removeClass("form-error"), 1494 b = ProductQuestionsValidation.isSectionValid(c) 1495 }), b == false) { 1496 var c = a.find(".error"); 1497 if (c.length > 0) { 1498 var d = $(c[0]); 1499 var checkbox = $(ProductQuestionsValidation.getParentProduct(d)); 1500 if (checkbox.is(":checked")) { 1501 var $thisoptions = $('[id=' + checkbox.attr('id') + '-options]'); 1502 if ($thisoptions.length > 0 && !$thisoptions.is(':visible')) { 1503 ProductOptions.showOptions($thisoptions); 1504 } 1505 } 1506 if (d.is(":visible")) { 1507 window.isformsubmitonce = true; 1508 ProductQuestionsValidation.bindFocusEvent(d); 1509 d.focus(); 1510 } 1511 } 1512 } 1513 return b; 1514 }, 1515 1516 isSectionValid: function (a) { 1517 ProductQuestionsValidation.validateSection(a); 1518 return a.find(".form-error").length ? !1 : !0; 1519 }, 1520 1521 validateSection: function (a) { 1522 1523 a.find("input, textarea, select").each(function () { 1524 var a = $(this); 1525 if (a.attr("data-validation") === "custom" && !a.parent().parent().is(".hidden") && !a.parent().parent().parent().is(".hidden")) 1526 if (a.is(".product-question")) { 1527 var b = $(ProductQuestionsValidation.getParentProduct(a)); 1528 if (b.is(":checked")) { 1529 ProductQuestionsValidation.vadiateInput(a); 1530 } 1531 } 1532 }) 1533 }, 1534 1535 getParentProduct: function (a) { 1536 var b = a.attr("id"), 1537 c = b.substr(0, b.indexOf("_")), 1538 d = document.getElementById(c); 1539 return d 1540 }, 1541 1542 vadiateInput: function (a) { 1543 var element = $('[id=' + a.attr('id') + ']'); 1544 var result; 1545 1546 if (element.last().attr('data-inputfortype') !== '' && element.last().attr('data-inputfortype') == "checkbox") { 1547 result = ProductQuestionsValidation.validateInputForCheckboxQuestion(element); 1548 } 1549 else { 1550 result = ProductQuestionsValidation.validateInputForRegex(element); 1551 } 1552 ProductQuestionsValidation.bindMessagesEvent(a); 1553 if (!result) { 1554 element.addClass('error'); 1555 $(element[0]).siblings('span.help-block').last().addClass('form-error'); 1556 $(element[1]).siblings('span.help-block').last().addClass('form-error'); 1557 1558 $(element[0]).siblings('span.help-blockinputfocus').last().addClass('form-error'); 1559 $(element[1]).siblings('span.help-blockinputfocus').last().addClass('form-error'); 1560 } 1561 else { 1562 element.removeClass('error'); 1563 $(element[0]).siblings('span.help-blockinputfocus').last().removeClass('form-error'); 1564 $(element[1]).siblings('span.help-blockinputfocus').last().removeClass('form-error'); 1565 $(element[0]).siblings('span.help-block').last().removeClass('form-error'); 1566 $(element[1]).siblings('span.help-block').last().removeClass('form-error'); 1567 } 1568 if ($(element[0]).siblings('span.help-block.form-error').length > 0 && $(element[0]).siblings('span.help-blockinputfocus.form-error').length > 0) { 1569 $(element[0]).siblings('span.help-blockinputfocus').last().removeClass('form-error'); 1570 } 1571 if ($(element[1]).siblings('span.help-block.form-error').length > 0 && $(element[1]).siblings('span.help-blockinputfocus.form-error').length > 0) { 1572 $(element[1]).siblings('span.help-blockinputfocus').last().removeClass('form-error'); 1573 } 1574 return result; 1575 }, 1576 1577 vadiateInputOnFocus: function (a) { 1578 $(a).siblings(".form-error").removeClass("form-error"); 1579 var element = $('[id=' + a.attr('id') + ']'); 1580 var result = ProductQuestionsValidation.validateInputForRegex(element); 1581 ProductQuestionsValidation.bindMessagesEvent(a); 1582 if (!result) { 1583 element.addClass('error'); 1584 if (window.isformsubmitonce !== true) { 1585 if ($('#BackToProductSelection').val() != "1") { 1586 $(element[0]).siblings('span.help-block').last().addClass('form-error'); 1587 $(element[1]).siblings('span.help-block').last().addClass('form-error'); 1588 } 1589 $(element[0]).siblings('span.help-blockinputfocus').last().addClass('form-error'); 1590 $(element[1]).siblings('span.help-blockinputfocus').last().addClass('form-error'); 1591 } 1592 } 1593 else { 1594 element.removeClass('error'); 1595 $(element[0]).siblings('span.help-blockinputfocus').last().removeClass('form-error'); 1596 $(element[1]).siblings('span.help-blockinputfocus').last().removeClass('form-error'); 1597 $(element[0]).siblings('span.help-block').last().removeClass('form-error'); 1598 $(element[1]).siblings('span.help-block').last().removeClass('form-error'); 1599 } 1600 if ($(element[0]).siblings('span.help-block.form-error').length > 0 && $(element[0]).siblings('span.help-blockinputfocus.form-error').length > 0) { 1601 $(element[0]).siblings('span.help-blockinputfocus').last().removeClass('form-error'); 1602 } 1603 if ($(element[1]).siblings('span.help-block.form-error').length > 0 && $(element[1]).siblings('span.help-blockinputfocus.form-error').length > 0) { 1604 $(element[1]).siblings('span.help-blockinputfocus').last().removeClass('form-error'); 1605 } 1606 return result; 1607 }, 1608 1609 validateInputForRegex: function (element) { 1610 var regx = new RegExp(element.last().attr('data-validation-regexp')); 1611 return regx.test(element.val()); 1612 }, 1613 1614 validateInputForCheckboxQuestion: function (element) { 1615 return element.val() !== ""; 1616 }, 1617 1618 bindMessagesEvent: function (element) { 1619 element.on("focusin", function () { 1620 element.siblings('span.helpmessage').first().fadeIn('slow'); 1621 }).on("focusout", function () { 1622 element.siblings('span.helpmessage').first().fadeOut('slow'); 1623 }); 1624 }, 1625 1626 bindFocusEvent: function (element) { 1627 element.on("keyup", ProductAdditionalQuestions.inputValidationOnFocus); 1628 element.on("focusout", ProductAdditionalQuestions.inputValidationOnFocus); 1629 window.isformsubmitonce = false; 1630 } 1631}
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.