1//global vars 2var DwBasket = {}; 3 4//jquery 5$(function () { 6 //modern mode 7 "use strict"; 8 9 //constants for fast customization 10 const classNameCluster = { 11 //main 12 order: "DwBasketOrder", 13 basket: "DwBasket", 14 15 //select fields 16 personType: "personSelect", 17 personTypeModules: "personTypeModules", 18 19 //stores 20 storesSwitch: "storeSelect", 21 storesContainer: "storeSelectContainer", 22 23 //form 24 orderForm: "orderForm", 25 orderFormActive: "orderForm.active", 26 27 //checkbox fields 28 budgetContainer: "payFromBudget", 29 budget: "budgetSwitch", 30 31 //input fields 32 quantityField: "qty", 33 34 //extra services 35 extraService: "extraServiceSwitch", 36 extraServiceItem: "extraServicesItem", 37 extraServiceItems: "extraServiceItems", 38 extraServiceItemSum: "extraServiceItemSum", 39 extraServiceItemContainer: "extraServicesItemContainer", 40 41 //delivery 42 delivery: "deliverySelect", 43 deliverySum: "deliverySum", 44 deliveryProps: "deliveryProps", 45 deliveryDescription: "deliveryDescription", 46 deliveryPeriod: "deliveryPeriod", 47 deliveryPeriodDescription: "deliveryPeriodDescription", 48 deliveryModulesContainer: "deliveryModulesContainer", 49 deliveryModulesContainerDesc: "deliveryModulesContainerDesc", 50 51 //paysystem 52 paysystem: "paySelect", 53 paysystemProps: "payProps", 54 55 //location 56 locationField: "location", 57 locationSwitchLink: "locationSwitchLink", 58 locationSwitchContainer: "locationSwitchContainer", 59 60 //coupon 61 couponButton: "couponActivate", 62 couponField: "couponField", 63 64 //confirm 65 confirmForm: "confirmForm", 66 confirmSend: "confirmSend", 67 confirmField: "confirmCode", 68 confirmTimer: "confirmTimer", 69 confirmReplay: "confirmReplay", 70 confirmErrors: "confirmErrors", 71 confirmErrorItem: "confirmErrorItem", 72 confirmSubstrate: "confirmSubstrate", 73 74 //link 75 remove: "delete", 76 minus: "minus", 77 plus: "plus", 78 79 //basket items 80 productItemList: "productList", 81 productItem: "parent", 82 83 //product fields 84 productPrice: "priceContainer", 85 productDiscount: "discountContainer", 86 87 //properties 88 propertyItem: "propItem", 89 90 //special 91 dropDownSelected: "dropDownSelected", 92 clearAll: "clearAllBasketItems", 93 giftContainer: "giftContainer", 94 dropDownItems: "dropDownItems", 95 dropDownItem: "dropDownItem", 96 minPayment: "minimumPayment", 97 orderComment: "orderComment", 98 fastBuy: "fastBayContainer", 99 dropDownActive: "selected", 100 dropDownOpened: "opened", 101 countItems: "countItems", 102 orderAreas: "orderAreas", 103 orderMove: "orderMove", 104 basketSum: "basketSum", 105 goToOrder: "goToOrder", 106 orderSum: "orderSum", 107 propActive: "active", 108 propHidden: "hidden", 109 dropDown: "dropDown", 110 111 //erros 112 errorWindowClose: "basketErrorClose", 113 errorWindowMessage: "errorMessage", 114 errorWindow: "basketError", 115 error: "error", 116 117 //new order 118 orderMake: "orderMake" 119 }; 120 121 //error form ids 122 const errorIds = { 123 maxQuantity: "error1", 124 orderErrors: "error2", 125 couponError: "error3" 126 }; 127 128 //other constants 129 const timeoutDelay = 400; 130 131 //vars 132 var timeoutId = 0; 133 var deliveryId = 0; 134 var compilation = {}; 135 136 //application object map 137 var application = { 138 calculate: {}, 139 binding: { 140 keypress: {}, 141 keydown: {}, 142 mouseup: {}, 143 change: {}, 144 submit: {}, 145 input: {}, 146 click: {}, 147 focus: {}, 148 keyup: {}, 149 blur: {} 150 }, 151 event: {}, 152 tools: {}, 153 commit: { 154 basket: {}, 155 location: {} 156 }, 157 flags: { 158 location: { 159 open: false 160 }, 161 dropDown: { 162 open: false 163 } 164 }, 165 check: {}, 166 price: {}, 167 ajax: {}, 168 push: {}, 169 pull: {} 170 }; 171 172 //binding functions 173 174 //click events 175 application.binding.click.stop = function (event) { 176 return event.stopImmediatePropagation(); 177 }; 178 179 application.binding.click.closeout = function (event) { 180 //location 181 if (application.flags.location.open === true) { 182 application.tools.resetLocation(event); 183 } 184 185 //dropdown select 186 if (application.flags.dropDown.open === true) { 187 application.tools.closeDropDown(); 188 } 189 }; 190 191 application.binding.click.openDropDown = function (event) { 192 //jquery vars 193 var $this = $(this); 194 var $dropContainer = $this.siblings("." + classNameCluster.dropDownItems); 195 var $dropItems = $dropContainer.find("." + classNameCluster.dropDownItem); 196 197 //check opened 198 if (!$dropContainer.hasClass(classNameCluster.dropDownOpened)) { 199 //show 200 $dropContainer.addClass(classNameCluster.dropDownOpened); 201 202 //set opened flag 203 application.flags.dropDown.open = true; 204 } 205 206 //close 207 else { 208 application.tools.closeDropDown(); 209 } 210 211 //block actions 212 return event.preventDefault(); 213 }; 214 215 application.binding.click.selectDropDown = function (event) { 216 //jquery vars 217 var $this = $(this); 218 219 //vars 220 var $dropContainer = $this.parents("." + classNameCluster.dropDown); 221 var $dropItems = $dropContainer.find("." + classNameCluster.dropDownItem); 222 var $selectedContainer = $dropContainer.find("." + classNameCluster.dropDownSelected); 223 var $nativeElement = $dropContainer.find("select"); 224 225 //other 226 var value = $this.data("value"); 227 var selected = $this.hasClass(classNameCluster.dropDownActive); 228 var triggerId = $dropContainer.data("trigger-id"); 229 230 //reset 231 $dropItems.removeClass(classNameCluster.dropDownActive); 232 233 //set selected 234 $this.addClass(classNameCluster.dropDownActive); 235 236 //change selected html 237 $selectedContainer.html($this.html()); 238 239 //show 240 $dropContainer 241 .find("." + classNameCluster.dropDownItems) 242 .removeClass(classNameCluster.dropDownOpened); 243 244 //set opened flag 245 application.flags.dropDown.open = false;
246 247 //check selected 248 if (selected == false) { 249 //check data-trigger for event & native change 250 if (typeof $nativeElement != "undefined" && $nativeElement.length > 0) { 251 //change selected option 252 $nativeElement.find("option").prop("selected", false); 253 $nativeElement.find('option[value="' + value + '"]').prop("selected", true); 254 255 //activate event 256 $nativeElement.trigger("change"); 257 } 258 259 //activate event 260 $dropContainer.trigger("change"); 261 } 262 263 //block actions 264 return event.preventDefault(); 265 }; 266 267 //set sms confirm 268 application.binding.click.confirmSend = function (event) { 269 //jquery vars 270 var $this = $(this); 271 var $confirmErrorContainer = $("." + classNameCluster.confirmErrors); 272 var $confirmReplay = $("." + classNameCluster.confirmReplay); 273 var $confirmField = $("." + classNameCluster.confirmField); 274 var $confirmForm = $("." + classNameCluster.confirmForm); 275 276 //other 277 var sendObject = new FormData(); 278 var smsCode = $confirmField.val(); 279 var orderId = $confirmField.data("order-id"); 280 var successText = $this.data("success"); 281 282 //push request params 283 sendObject.append("siteId", siteId); 284 sendObject.append("orderId", orderId); 285 sendObject.append("actionType", "smsConfirm"); 286 287 //check filling & length 288 if (typeof smsCode != "undefined" && smsCode != "" && smsCode.length == 4) { 289 //sms code 290 sendObject.append("smsCode", smsCode); 291
292 //push arParams 293 sendObject = application.push.params(sendObject); 294 295 //remove error class 296 application.tools.removeError($this); 297 application.tools.removeError($confirmForm); 298 299 //clear error container 300 application.tools.clear($confirmErrorContainer); 301 302 //hide old errors 303 $confirmErrorContainer.removeClass("opened"); 304 305 //start loader 306 application.tools.launchLoader($this); 307 308 //send data 309 application.ajax.sendData( 310 ajaxDir + "/ajax.php", 311 sendObject, 312 "post", 313 "json", 314 dataProcessing, 315 false 316 ); 317 318 //proccesing data after request 319 function dataProcessing(jsonData) { 320 //check state 321 if (jsonData["status"] === true) { 322 //set success state 323 $confirmForm.addClass("success"); 324 325 //hide replay button 326 application.tools.hideByFlag($confirmReplay, true); 327 328 //change button text 329 $this.text(successText); 330 } 331 332 //check errors 333 else { 334 //check exist error messages 335 if (jsonData["error"] === true && typeof jsonData["errors"] == "object") { 336 //push errors to container 337 $.each(jsonData["errors"], function () { 338 if (typeof this == "string") { 339 $confirmErrorContainer.append( 340 $("<div/>", { class: classNameCluster.confirmErrorItem }).html( 341 this 342 ) 343 ); 344 } 345 }); 346 347 //show error container 348 $confirmErrorContainer.addClass("opened"); 349 350 //add error class 351 application.tools.addError($this); 352 application.tools.addError($confirmForm); 353 354 //push to console 355 console.error(jsonData); 356 } 357 } 358 359 //remove loader 360 application.tools.stopLoader($this); 361 } 362 } 363 364 //block actions 365 return event.preventDefault(); 366 }; 367 368 //replay sms code 369 application.binding.click.confirmReplay = function () { 370 //jquery vars 371 var $this = $(this); 372 var $confirmErrorContainer = $("." + classNameCluster.confirmErrors); 373 374 //other 375 var sendObject = new FormData(); 376 var orderId = $this.data("order-id"); 377 378 //push request params 379 sendObject.append("siteId", siteId); 380 sendObject.append("orderId", orderId); 381 sendObject.append("actionType", "smsReplay"); 382 383 //clear error container 384 application.tools.clear($confirmErrorContainer); 385 386 //hide old errors 387 $confirmErrorContainer.removeClass("opened"); 388 389 //start loader 390 application.tools.launchLoader($this); 391 392 //send data 393 application.ajax.sendData( 394 ajaxDir + "/ajax.php", 395 sendObject, 396 "post", 397 "json", 398 dataProcessing, 399 false 400 ); 401 402 //proccesing data after request 403 function dataProcessing(jsonData) { 404 //check state 405 if (jsonData["status"] === true) { 406 //set new timer 407 application.tools.startTimer( 408 "." + classNameCluster.confirmTimer, 409 "." + classNameCluster.confirmReplay 410 ); 411 412 //set success state 413 $this.addClass("success"); 414 $this.removeClass("ready"); 415 } 416 417 //check errors 418 else { 419 //check exist error messages 420 if (jsonData["error"] === true && typeof jsonData["errors"] == "object") { 421 //push errors to container 422 $.each(jsonData["errors"], function () { 423 if (typeof this == "string") { 424 $confirmErrorContainer.append( 425 $("<div/>", { class: classNameCluster.confirmErrorItem }).html(this) 426 ); 427 } 428 }); 429 430 //show error container 431 $confirmErrorContainer.addClass("opened"); 432 433 //push to console 434 console.error(jsonData); 435 } 436 } 437 438 //remove loader 439 application.tools.stopLoader($this); 440 } 441 442 //block actions 443 return event.preventDefault(); 444 }; 445 446 //create order 447 application.binding.click.orderMake = function (event) { 448 //jquery vars 449 var $this = $(this); 450 451 //other 452 var sendObject = new FormData(); 453 454 //push request params 455 sendObject.append("actionType", "orderMake"); 456 sendObject.append("siteId", siteId); 457 458 //get orderFields 459 var $orderFields = application.pull.getOrderFields(); 460 461 //check required fields 462 if (application.check.required($orderFields)) { 463 //push order fields values 464 sendObject = application.push.serializeFields($orderFields, sendObject); 465 466 //push order comment 467 sendObject = application.push.orderComment(sendObject); 468 469 //push basket fields values 470 sendObject = application.push.fields(sendObject); 471
472 //push arParams 473 sendObject = application.push.params(sendObject); 474 475 //start loader 476 application.tools.launchLoader($this); 477 478 //send data 479 application.ajax.sendData( 480 ajaxDir + "/ajax.php", 481 sendObject, 482 "post", 483 "json", 484 dataProcessing, 485 false 486 ); 487 488 //proccesing data after request 489 function dataProcessing(jsonData) { 490 //check state 491 if ( 492 jsonData["status"] === true && 493 typeof jsonData["orderResult"]["orderId"] != undefined 494 ) { 495 //metrica 496 if ( 497 typeof globalSettings != "undefined" && 498 typeof globalSettings["TEMPLATE_METRICA_ORDER"] != "undefined" && 499 typeof globalSettings["TEMPLATE_METRICA_ID"] != "undefined" && 500 typeof window["yaCounter" + globalSettings["TEMPLATE_METRICA_ID"]] != 501 "undefined" 502 ) { 503 window["yaCounter" + globalSettings["TEMPLATE_METRICA_ID"]].reachGoal( 504 globalSettings["TEMPLATE_METRICA_ORDER"] 505 ); 506 } 507 508 //redirect 509 window.location.href = application.tools.addParamToUrl({ 510 orderId: jsonData["orderResult"]["orderId"] 511 }); 512 } 513 514 //check errors 515 else { 516 if (jsonData["error"] === true) { 517 application.tools.addError($this); 518 application.tools.pushAjaxErrors(jsonData); 519 console.error(jsonData); 520 } 521 } 522 523 //remove loader 524 application.tools.stopLoader($this); 525 } 526 } 527 528 return event.preventDefault(); 529 }; 530 531 application.binding.click.setCoupon = function (event) { 532 //jquery vars 533 var $couponField = $("." + classNameCluster.couponField); 534 var $this = $(this); 535 536 //other 537 var couponValue = $couponField.val(); 538 539 //check empty 540 if (couponValue != "undefined" && couponValue != "") { 541 //create formData 542 var sendObject = new FormData(); 543 544 //push request params 545 sendObject.append("actionType", "setCoupon"); 546 sendObject.append("coupon", couponValue); 547 sendObject.append("siteId", siteId); 548 549 //start loader 550 application.tools.launchLoader($this); 551 552 //send data 553 application.ajax.sendData( 554 ajaxDir + "/ajax.php", 555 sendObject, 556 "post", 557 "json", 558 dataProcessing, 559 false 560 ); 561 562 //proccesing data after request 563 function dataProcessing(jsonData) { 564 //check state 565 if (jsonData["status"] === true && jsonData["success"] === true) { 566 //page reload 567 window.location.reload(); 568 } 569 570 //check errors 571 else { 572 if (jsonData["error"] === true) { 573 //set errors 574 application.tools.addError($couponField); 575 application.tools.pushAjaxErrors(jsonData, "couponError"); 576 console.error(jsonData); 577 } 578 } 579 580 //remove loader 581 application.tools.stopLoader($this); 582 } 583 } 584 585 //set error 586 else { 587 application.tools.addError($couponField); 588 } 589 590 //block actions 591 return event.preventDefault(); 592 }; 593 594 application.binding.click.clearAll = function (event) { 595 //jquery vars 596 var $this = $(this); 597 598 //create formData 599 var sendObject = new FormData(); 600 601 //push request params 602 sendObject.append("actionType", "clearAll"); 603 sendObject.append("siteId", siteId); 604 605 //start loader 606 application.tools.launchLoader($this); 607 608 //send data 609 application.ajax.sendData( 610 ajaxDir + "/ajax.php", 611 sendObject, 612 "post", 613 "json", 614 dataProcessing, 615 false 616 ); 617 618 //proccesing data after request 619 function dataProcessing(jsonData) { 620 //check state 621 if (jsonData["status"] === true) { 622 //page reload 623 window.location.reload(); 624 } 625 626 //check errors 627 else { 628 if (jsonData["error"] === true) { 629 application.tools.pushAjaxErrors(jsonData); 630 console.error(jsonData); 631 } 632 } 633 634 //remove loader 635 application.tools.stopLoader($this); 636 } 637 638 //block actions 639 return event.preventDefault(); 640 }; 641 642 application.binding.click.deleteItem = function (event) { 643 //jquery vars 644 var $this = $(this); 645 646 //other 647 var basketItemId = $this.data("id"); 648 var sendObject = new FormData(); 649 650 //push request params 651 sendObject.append("actionType", "removeItem"); 652 sendObject.append("basketId", basketItemId); 653 sendObject.append("siteId", siteId); 654
655 //push arParams 656 sendObject = application.push.params(sendObject); 657 658 //push basket fields values 659 sendObject = application.push.fields(sendObject); 660 661 //start loader 662 application.tools.launchLoader($this); 663 664 //send data 665 application.ajax.sendData( 666 ajaxDir + "/ajax.php", 667 sendObject, 668 "post", 669 "json", 670 dataProcessing, 671 false 672 ); 673 674 //proccesing data after request 675 function dataProcessing(jsonData) { 676 //check state 677 if (jsonData["status"] === true) { 678 //reloading page if not find items 679 if ( 680 $this 681 .parents("." + classNameCluster.productItemList) 682 .find("." + classNameCluster.productItem).length <= 1 683 ) { 684 //page reload 685 window.location.reload(); 686 } else { 687 //delete dom item 688 $this.parents("." + classNameCluster.productItem).remove(); 689 //commit result data 690 application.commit.basket.proccesing(jsonData); 691 } 692 } 693 694 //check errors 695 else { 696 if (jsonData["error"] === true) { 697 application.tools.pushAjaxErrors(jsonData); 698 console.error(jsonData); 699 } 700 } 701 } 702 703 //block actions 704 return event.preventDefault(); 705 }; 706 707 application.binding.click.quantityMinus = function (event) { 708 //jquery vars 709 var $this = $(this); 710 var $basketItem = $this.parents("." + classNameCluster.productItem); 711 var $quantityField = $basketItem.find("." + classNameCluster.quantityField); 712 713 //other 714 var measureRatio = parseFloat($quantityField.data("ratio")); 715 var currentQuantity = parseFloat($quantityField.val()); 716 717 //need changing 718 if (currentQuantity > measureRatio) { 719 //pre calculate quantity 720 var preQuantity = currentQuantity - measureRatio; 721 722 //set value 723 $quantityField.val(+preQuantity.toFixed(5)); 724 $quantityField.trigger("change"); 725 } 726 727 //block actions 728 return event.preventDefault(); 729 }; 730 731 application.binding.click.quantityPlus = function (event) { 732 //jquery vars 733 var $this = $(this); 734 var $basketItem = $this.parents("." + classNameCluster.productItem); 735 var $quantityField = $basketItem.find("." + classNameCluster.quantityField); 736 737 //other 738 var measureRatio = parseFloat($quantityField.data("ratio")); 739 var currentQuantity = parseFloat($quantityField.val()); 740 741 //pre calculate quantity 742 var preQuantity = currentQuantity + measureRatio; 743 744 //set value 745 $quantityField.val(+preQuantity.toFixed(5)); 746 $quantityField.trigger("change"); 747 748 //block actions 749 return event.preventDefault(); 750 }; 751 752 application.binding.click.locationLink = function (event) { 753 //jquery vars 754 var $this = $(this); 755 var $locationContainer = $this.parents("." + classNameCluster.locationSwitchContainer); 756 var $locationField = $locationContainer.siblings("." + classNameCluster.locationField); 757 758 //other 759 var locationName = $this.data("path"); 760 var locationId = $this.data("id"); 761 762 //set values 763 $locationField.val(locationName); 764 $locationField.data("location", locationId); 765 766 //close 767 application.tools.closeLocationDropdown($locationContainer); 768 769 //flush basket 770 application.commit.basket.flush(); 771 772 //block actions 773 return event.preventDefault(); 774 }; 775 776 application.binding.click.orderMove = function () { 777 //vars 778 var $order = $("." + classNameCluster.order); 779 var $minPayment = $("." + classNameCluster.minPayment); 780 781 //other 782 var blockActions = true; 783 784 //check object 785 if (typeof $order === "object" && $order.is(":visible")) { 786 application.tools.scrollTo($order); 787 } 788 789 //check min payment to scroll 790 else { 791 //check object 792 if (typeof $minPayment === "object" && !$.isEmptyObject($minPayment)) { 793 //check for available 794 if ($minPayment.is(":visible")) { 795 application.tools.scrollTo($minPayment); 796 } else { 797 blockActions = false; 798 } 799 } 800 } 801 802 //block actions 803 if (blockActions === true) { 804 return event.preventDefault(); 805 } 806 }; 807 808 application.binding.click.closeErrorWindow = function () { 809 //jquery vars 810 var $this = $(this); 811 var $errorWindow = $this.parents("." + classNameCluster.errorWindow); 812 813 //hide 814 application.tools.closeWindow($errorWindow); 815 816 //block actions 817 return event.preventDefault(); 818 }; 819 820 //submit events 821 application.binding.submit.confirmForm = function (event) { 822 //emulation send button click 823 $("." + classNameCluster.confirmSend).trigger("click"); 824 825 //block actions 826 return event.preventDefault(); 827 }; 828 829 //keyup events 830 application.binding.keyup.location = function (event) { 831 //remove previous 832 clearTimeout(timeoutId); 833 834 //realtime calc 835 timeoutId = setTimeout(application.commit.location.pushComponent, timeoutDelay); 836 }; 837 838 //on input events 839 application.binding.input.confirm = function (event) { 840 //jquery vars 841 var $this = $(this); 842 843 //other 844 var currentValue = $this.val(); 845 846 //clear not allowed 847 currentValue = currentValue.replace(/[^0-9]/gim, "").substr(0, 4); 848 849 //reset input value 850 $this.val(currentValue); 851 852 //check lenght 853 if (typeof currentValue != "undefined" && currentValue.length <= 4) { 854 //get substrate field 855 var $substrate = $("." + classNameCluster.confirmSubstrate); 856 857 //supplement zero 858 while (currentValue.length < 4) { 859 currentValue += "0"; 860 } 861 } 862 863 //write 864 $substrate.html(currentValue); 865 }; 866 867 //keypress events 868 application.binding.keypress.quantity = function (event) { 869 //available characters 870 var allowedChars = [44, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57]; 871 872 //check which 873 if (allowedChars.indexOf(event.which) === -1) { 874 //block actions 875 return event.preventDefault(); 876 } 877 }; 878 879 //focus events 880 application.binding.focus.location = function (event) { 881 //jquery vars 882 var $this = $(this); 883 884 //other 885 var currentValue = $this.val().toString(); 886 var currentId = $this.data("location"); 887 888 //save last value 889 $this.data("last-value", currentValue); 890 $this.data("last-id", currentId); 891 892 //reset 893 $this.val(""); 894 $this.data("location", ""); 895 }; 896 897 application.binding.focus.coupon = function (event) { 898 //jquery vars 899 var $this = $(this); 900 901 //clear errors 902 application.tools.removeError($this); 903 }; 904 905 //blur events 906 application.binding.blur.location = function (event) { 907 if (application.flags.location.open === false) { 908 application.tools.resetLocation(event); 909 } 910 911 return false;
912 }; 913 914 //change events 915 application.binding.change.quantity = function (event) { 916 //jquery vars 917 var $this = $(this); 918 919 //other 920 var basketItemId = $this.data("id"); 921 var maxAmount = parseFloat($this.data("max-quantity")); 922 var measureRatio = parseFloat($this.data("ratio")); 923 var currentQuantity = parseFloat($this.val()); 924 var multiplicity = +(currentQuantity / measureRatio).toFixed(5); 925 var defQuantity = currentQuantity; 926 927 //reset errors 928 application.tools.removeError($this); 929 930 //need changing 931 //check max amount 932 if (typeof maxAmount !== undefined && currentQuantity > maxAmount) { 933 //set max value 934 currentQuantity = maxAmount; 935 936 //commit 937 $this.val(currentQuantity); 938 939 //set error 940 application.tools.addError($this); 941 942 //show error window flag 1 943 application.tools.openWindow(errorIds.maxQuantity); 944 } 945 946 //check nan & min value 947 else if (isNaN(currentQuantity) || currentQuantity < measureRatio) { 948 //set min value 949 currentQuantity = measureRatio; 950 951 //commit 952 $this.val(currentQuantity); 953 } 954 955 //check multiple of number 956 else if ((multiplicity ^ 0) !== multiplicity) { 957 //get near quantity 958 var currentQuantity = Math.ceil(currentQuantity / measureRatio) * measureRatio; 959 960 //commit 961 $this.val(currentQuantity); 962 } 963 964 // 965 else { 966 //save value 967 $this.data("last-value", currentQuantity); 968 $this.val(currentQuantity); 969 } 970 971 //remove previous 972 clearTimeout(timeoutId); 973 974 //realtime calc 975 timeoutId = setTimeout(function () { 976 application.commit.basket.updateProduct(basketItemId, currentQuantity); 977 }, timeoutDelay); 978 }; 979 980 application.binding.change.person = function (event) { 981 //jquery vars 982 var $this = $(this); 983 var $orderForm = $("." + classNameCluster.orderForm); 984 var $orderAreas = $("." + classNameCluster.orderAreas); 985 var $personTypeModules = $("." + classNameCluster.personTypeModules); 986 987 //other 988 var personTypeId = parseInt($this.val()); 989 990 //change state 991 $personTypeModules.filter('[data-id="' + personTypeId + '"]').prop("checked", true); 992 993 //reset delivery 994 deliveryId = 0; 995 996 //hide all areas 997 application.tools.hideByFlag($orderAreas, false, "active"); 998 999 //show actual areas 1000 application.tools.hideByFlag( 1001 $orderAreas.filter('[data-person-id="' + personTypeId + '"]'), 1002 true, 1003 "active" 1004 ); 1005 1006 //remove active class for order form 1007 application.tools.hideByFlag($orderForm, false, "active"); 1008 1009 //select active order form 1010 application.tools.hideByFlag( 1011 $orderForm.filter('[data-id="' + personTypeId + '"]'), 1012 true, 1013 "active" 1014 ); 1015 1016 //flush 1017 application.commit.basket.flush(); 1018 }; 1019 1020 application.binding.change.delivery = function (event) { 1021 application.commit.basket.flush(); 1022 }; 1023 1024 application.binding.change.paysystem = function (event) { 1025 application.commit.basket.flush(); 1026 }; 1027 1028 application.binding.change.budget = function (event) { 1029 application.commit.basket.realtime(); 1030 }; 1031 1032 application.binding.change.extraService = function (event) { 1033 //jquery vars 1034 var $this = $(this); 1035 var $basket = $("." + classNameCluster.basket); 1036 var $deliveryField = $basket.find("." + classNameCluster.delivery).find("option:selected"); 1037 1038 //get input type 1039 var type = $this.attr("type"); 1040 var tagName = $this.prop("tagName").toLowerCase(); 1041 1042 //get values 1043 var values = { 1044 current: parseFloat($this.val()), 1045 default: parseFloat($this.data("default")), 1046 price: parseFloat($this.data("price")), 1047 last: parseFloat($this.data("last")) 1048 }; 1049 1050 //delivery info 1051 var delivery = { 1052 price: parseFloat($deliveryField.data("price")), 1053 name: $deliveryField.data("name") 1054 }; 1055 1056 //special 1057 var final = {}, 1058 last = {}; 1059 1060 //check type 1061 if (type == "text") { 1062 //jquery vars 1063 var $sumContainer = $this 1064 .parents("." + classNameCluster.extraServiceItem) 1065 .find("." + classNameCluster.extraServiceItemSum); 1066 1067 //check nan & min value 1068 if (isNaN(values.current) || values.current < 0) { 1069 values.current = values.default; 1070 } 1071 1072 //calculate final sum 1073 final.sum = values.current * values.price; 1074 1075 //calculate last sum 1076 last.sum = values.last * values.price; 1077 1078 //calculate final delivery sum 1079 delivery.sum = delivery.price - last.sum + final.sum; 1080 1081 //update sum container 1082 $sumContainer.html(application.price.format(final.sum, false, false, false, true)); 1083 1084 //update quantity 1085 $this.val(values.current).data("last", values.current); 1086 } else if (type == "checkbox") { 1087 delivery.sum = $this.is(":checked") 1088 ? delivery.price + values.price 1089 : delivery.price - values.price; 1090 } else if (tagName == "select") { 1091 //get price 1092 values.current = parseFloat($this.find("option:selected").data("price")); 1093 1094 //calculate total delivery sum 1095 delivery.sum = delivery.price - values.last + values.current; 1096 1097 //update last 1098 $this.data("last", values.current); 1099 } 1100 1101 //flush basket 1102 application.commit.basket.flush(); 1103 }; 1104 1105 //commit functions 1106 1107 //basket 1108 application.commit.basket.updateProduct = function (basketId, quantity) {
1109 if (typeof basketId === "number" && typeof quantity === "number") { 1110 //jquery vars 1111 var $self = $("." + classNameCluster.basket); 1112 1113 //other 1114 var sendObject = new FormData(); 1115 1116 //push request params 1117 sendObject.append("actionType", "updateItem"); 1118 sendObject.append("basketId", basketId); 1119 sendObject.append("quantity", quantity); 1120 sendObject.append("siteId", siteId); 1121 1122 //push arParams 1123 sendObject = application.push.params(sendObject); 1124 1125 //push basket fields values 1126 sendObject = application.push.fields(sendObject); 1127 1128 //start loader 1129 application.tools.launchLoader($self, "wait"); 1130 1131 //send data 1132 application.ajax.sendData( 1133 ajaxDir + "/ajax.php", 1134 sendObject, 1135 "post", 1136 "json", 1137 dataProcessing, 1138 false 1139 ); 1140 1141 //proccesing data after request 1142 function dataProcessing(jsonData) { 1143 //check state 1144 if (jsonData["status"] === true) { 1145 //commit result data 1146 application.commit.basket.proccesing(jsonData); 1147 } 1148 1149 //check errors 1150 else { 1151 if (jsonData["error"] === true) { 1152 application.tools.pushAjaxErrors(jsonData); 1153 console.error(jsonData); 1154 } 1155 } 1156 1157 //remove loader 1158 application.tools.stopLoader($self, "wait"); 1159 } 1160 } else { 1161 console.error("check transmitted data"); 1162 } 1163 }; 1164 1165 application.commit.basket.flush = function () { 1166 //jquery vars 1167 var $self = $("." + classNameCluster.basket); 1168 1169 //other 1170 var sendObject = new FormData(); 1171 1172 //push request params 1173 sendObject.append("actionType", "getCompilation"); 1174 sendObject.append("siteId", siteId); 1175 1176 //push basket fields values 1177 sendObject = application.push.fields(sendObject); 1178
1179 //push arParams 1180 sendObject = application.push.params(sendObject); 1181 1182 //start loader 1183 application.tools.launchLoader($self, "wait"); 1184 1185 //send data 1186 application.ajax.sendData( 1187 ajaxDir + "/ajax.php", 1188 sendObject, 1189 "post", 1190 "json", 1191 dataProcessing, 1192 false 1193 ); 1194 1195 //proccesing data after request 1196 function dataProcessing(jsonData) { 1197 //check state 1198 if (jsonData["status"] === true) { 1199 //commit result data 1200 application.commit.basket.proccesing(jsonData); 1201 } 1202 1203 //check errors 1204 else { 1205 if (jsonData["error"] === true) { 1206 application.tools.pushAjaxErrors(jsonData); 1207 console.error(jsonData); 1208 } 1209 } 1210 1211 //remove loader 1212 application.tools.stopLoader($self, "wait"); 1213 } 1214 }; 1215 1216 application.commit.basket.proccesing = function (jsonData) { 1217 //set global compilation for fast access 1218 application.commit.basket.setCompilation(jsonData); 1219 1220 //commit other 1221 application.commit.basket.items(); 1222 application.commit.basket.deliveries(); 1223 application.commit.basket.paysystems(); 1224 application.commit.basket.minOrderPrice(); 1225 1226 //gifts 1227 application.commit.basket.gifts(jsonData); 1228 1229 //update basket fields 1230 application.commit.basket.realtime(); 1231 1232 //event 1233 application.event.trigger("processing", jsonData); 1234 }; 1235 1236 application.commit.basket.items = function () { 1237 //check empty 1238 if (typeof compilation["items"] === "object" && !$.isEmptyObject(compilation["items"])) { 1239 //get items data from last compilation data 1240 var basketItems = compilation["items"]; 1241 1242 //get basket items DOM 1243 var $basketItems = $("." + classNameCluster.productItem); 1244 1245 //each data 1246 $.each(basketItems, function (currentIndex, basketItem) { 1247 //find current product 1248 var $basketItem = $basketItems.filter( 1249 '[data-id="' + basketItem["PRODUCT_ID"] + '"]' 1250 ); 1251 //find price container 1252 var $basketItemPrice = $basketItem.find("." + classNameCluster.productPrice); 1253 //find discount container 1254 var $basketItemDiscount = $basketItem 1255 .find("." + classNameCluster.productDiscount) 1256 .addClass("hidden"); 1257 1258 //commit price 1259 $basketItemPrice.html(basketItem["PRICE_FORMATED"]); 1260 $basketItemPrice.data("price", basketItem["PRICE"]); 1261 1262 //commit discount price 1263 if (basketItem["DISCOUNT"] > 0) { 1264 $basketItemDiscount 1265 .html(basketItem["BASE_PRICE_FORMATED"]) 1266 .removeClass("hidden"); 1267 } 1268 }); 1269 } 1270 }; 1271 1272 application.commit.basket.deliveries = function () { 1273 //check empty 1274 if ( 1275 typeof compilation["order"]["DELIVERIES"] === "object" && 1276 !$.isEmptyObject(compilation["order"]["DELIVERIES"]) 1277 ) { 1278 //jquery vars 1279 var $this = $("." + classNameCluster.propActive + " ." + classNameCluster.delivery); 1280 1281 //get dropdown container 1282 var $dropDown = $this.parents("." + classNameCluster.dropDown); 1283 var $dropDownItems = $dropDown.find("." + classNameCluster.dropDownItems); 1284 var $dropDownSelected = $dropDown.find("." + classNameCluster.dropDownSelected); 1285 var $dropDownItemFirst = false; 1286 1287 //other 1288 var currentId = parseInt($this.val()); 1289 var selectedId = 0; 1290 1291 //get deliveries from last compilation data 1292 var deliveries = compilation["order"]["DELIVERIES"]; 1293 1294 //get delivery sorted indexes 1295 var sortDeliveries = application.tools.sortByIndex(deliveries); 1296 1297 //get last delivery id 1298 deliveryId = application.pull.getLastDeliveryId(); 1299 1300 //clear 1301 application.tools.clear($this); 1302 application.tools.clear($dropDownItems); 1303 1304 //each data 1305 $.each(sortDeliveries, function (currentIndex, nextDeliveryId) { 1306 //get next delivery 1307 var nextDelivery = deliveries[nextDeliveryId]; 1308 1309 //create next delivery item 1310 var $deliveryItem = $("<option/>").val(nextDelivery["ID"]); 1311 var $dropDownItem = $("<div/>", { class: classNameCluster.dropDownItem }).data( 1312 "value", 1313 nextDelivery["ID"] 1314 ); 1315 1316 //set data attrs (price, name) 1317 $deliveryItem.data({ 1318 price: nextDelivery["PRICE"], 1319 name: nextDelivery["NAME"] 1320 }); 1321 1322 //set title 1323 $deliveryItem.html(nextDelivery["NAME"] + " " + nextDelivery["PRICE_FORMATED"]); 1324 $dropDownItem.html(nextDelivery["NAME"] + " " + nextDelivery["PRICE_FORMATED"]); 1325 1326 //set selected 1327 if (currentId == nextDelivery["ID"]) { 1328 //set option selected 1329 $deliveryItem.attr("selected", "selected"); 1330 1331 //set selected in dropdown 1332 $dropDownItem.addClass(classNameCluster.dropDownActive); 1333 1334 //change title in dropdown selected item 1335 $dropDownSelected.html( 1336 nextDelivery["NAME"] + " " + nextDelivery["PRICE_FORMATED"] 1337 ); 1338 1339 //write selected id 1340 selectedId = nextDelivery["ID"]; 1341 } 1342 1343 //save first item 1344 if ($dropDownItemFirst == false) { 1345 $dropDownItemFirst = $dropDownItem; 1346 } 1347 1348 //push 1349 $this.append($deliveryItem); 1350 $dropDownItems.append($dropDownItem); 1351 }); 1352 1353 //refresh var 1354 currentId = parseInt($this.val()); 1355 1356 //check selected id 1357 if (selectedId == 0 && currentId != "") { 1358 //get delivery from result 1359 var currentDelivery = deliveries[currentId]; 1360 1361 //check current delivery 1362 if (typeof currentDelivery != "undefined" && !$.isEmptyObject(currentDelivery)) { 1363 //add selected class 1364 $dropDownItemFirst.addClass(classNameCluster.dropDownActive); 1365 1366 //set title 1367 $dropDownSelected.html( 1368 currentDelivery["NAME"] + " " + currentDelivery["PRICE_FORMATED"] 1369 ); 1370 } 1371 } 1372 1373 //processing 1374 application.commit.basket.deliveryStores(currentId); 1375 application.commit.basket.deliveryProperties(currentId); 1376 1377 //check delivery id change 1378 if (deliveryId != currentId) { 1379 //need refresh extra services 1380 application.commit.basket.deliveryServices(currentId); 1381 1382 //refresh delivery period 1383 //marketplace modules must append html content into delivery period 1384 application.commit.basket.deliveryPeriod(currentId); 1385 1386 //refresh delivery desctiption 1387 application.commit.basket.deliveryDescription(currentId); 1388 } 1389 1390 return (deliveryId = currentId); 1391 } 1392 }; 1393 1394 application.commit.basket.deliveryStores = function (deliveryId) { 1395 //check types 1396 if ( 1397 typeof deliveryId !== "number" || 1398 isNaN(deliveryId) || 1399 typeof compilation["order"]["DELIVERIES"] !== "object" || 1400 typeof compilation["stores"] !== "object" 1401 ) { 1402 return false;
1403 } 1404 1405 //jquery vars 1406 var $storesContainer = $( 1407 "." + classNameCluster.propActive + " ." + classNameCluster.storesContainer 1408 ); 1409 var $storesSwitch = $storesContainer.find("." + classNameCluster.storesSwitch); 1410 1411 //get dropdown container 1412 var $dropDown = $storesSwitch.parents("." + classNameCluster.dropDown); 1413 var $dropDownItems = $dropDown.find("." + classNameCluster.dropDownItems); 1414 var $dropDownSelected = $dropDown.find("." + classNameCluster.dropDownSelected); 1415 var $dropDownItemFirst = false; 1416 1417 //other 1418 var hideContainer = true; 1419 var selectedId = false; 1420 var currentId = parseInt($storesSwitch.val()); 1421 1422 //clear 1423 application.tools.clear($storesSwitch); 1424 application.tools.clear($dropDownItems); 1425 1426 //get deliveries from last compilation data 1427 var deliveriesData = compilation["order"]["DELIVERIES"]; 1428 var storesData = compilation["stores"]; 1429 1430 //check stores 1431 if ( 1432 typeof deliveriesData[deliveryId]["STORES"] === "object" && 1433 !$.isEmptyObject(deliveriesData[deliveryId]["STORES"]) 1434 ) { 1435 //each stores 1436 $.each(storesData, function (index, nextStore) { 1437 //check exist 1438 if ($.inArray(nextStore["ID"], deliveriesData[deliveryId]["STORES"]) != -1) { 1439 //create next store item 1440 var $storeItem = $("<option/>").val(nextStore["ID"]); 1441 var $dropDownItem = $("<div/>", { class: classNameCluster.dropDownItem }).data( 1442 "value", 1443 nextStore["ID"] 1444 ); 1445 1446 //set title 1447 $storeItem.html( 1448 nextStore["TITLE"] + 1449 " - " + 1450 nextStore["ADDRESS"] + 1451 " - " + 1452 nextStore["PRODUCTS_STATUS"] 1453 ); 1454 $dropDownItem.html( 1455 nextStore["TITLE"] + 1456 " - " + 1457 nextStore["ADDRESS"] + 1458 " - " + 1459 nextStore["PRODUCTS_STATUS"] 1460 ); 1461 1462 //set selected 1463 if (currentId == nextStore["ID"]) { 1464 //set option selected 1465 $storeItem.attr("selected", "selected"); 1466 1467 //set selected in dropdown 1468 $dropDownItem.addClass(classNameCluster.dropDownActive); 1469 1470 //change title in dropdown selected item 1471 $dropDownSelected.html( 1472 nextStore["TITLE"] + 1473 " - " + 1474 nextStore["ADDRESS"] + 1475 " - " + 1476 nextStore["PRODUCTS_STATUS"] 1477 ); 1478 1479 //write selected id 1480 selectedId = nextStore["ID"]; 1481 } 1482 1483 //save first item 1484 if ($dropDownItemFirst == false) { 1485 $dropDownItemFirst = $dropDownItem; 1486 } 1487 1488 //push 1489 $storesSwitch.append($storeItem); 1490 $dropDownItems.append($dropDownItem); 1491 1492 //set flag (no hide) 1493 hideContainer = false; 1494 } 1495 }); 1496 1497 //refresh var 1498 currentId = parseInt($storesSwitch.val()); 1499 1500 //check selected id 1501 if (selectedId == 0 && currentId != "") { 1502 //get delivery from result 1503 var currentStore = storesData[currentId]; 1504 1505 //add selected class 1506 $dropDownItemFirst.addClass(classNameCluster.dropDownActive); 1507 1508 //set title 1509 $dropDownSelected.html( 1510 currentStore["TITLE"] + 1511 " - " + 1512 currentStore["ADDRESS"] + 1513 " - " + 1514 currentStore["PRODUCTS_STATUS"] 1515 ); 1516 } 1517 } 1518 1519 //hide if not exist stores 1520 application.tools.hideByFlag($storesContainer, hideContainer); 1521 }; 1522 1523 application.commit.basket.deliveryServices = function (deliveryId) { 1524 //check types 1525 if (typeof deliveryId !== "number" || isNaN(deliveryId) == true || deliveryId <= 0) { 1526 return false; 1527 } 1528 1529 //check extra service html 1530 if ( 1531 typeof compilation["order"]["DELIVERIES"][deliveryId]["EXTRA_SERVICES_HTML"] != 1532 "undefined" 1533 ) { 1534 var extraServiceHTML = 1535 compilation["order"]["DELIVERIES"][deliveryId]["EXTRA_SERVICES_HTML"]; 1536 } 1537 1538 //jquery vars 1539 var $serviceItems = $( 1540 "." + classNameCluster.propActive + " ." + classNameCluster.extraServiceItems 1541 ); 1542 1543 //other 1544 var serviceDisabled = typeof extraServiceHTML == "undefined" || extraServiceHTML == ""; 1545 1546 //hide / display extra services container 1547 application.tools.hideByFlag($serviceItems, serviceDisabled); 1548 1549 //push html 1550 serviceDisabled === false 1551 ? $serviceItems.html(extraServiceHTML) 1552 : application.tools.clear($serviceItems); 1553 }; 1554 1555 application.commit.basket.deliveryProperties = function (deliveryId) { 1556 //check types 1557 if ( 1558 typeof deliveryId !== "number" || 1559 typeof compilation["order"]["PROPERTIES"] !== "object" 1560 ) { 1561 return false;
1562 } 1563 1564 //jquery vars 1565 var $deliveryProperties = $( 1566 "." + classNameCluster.propActive + " ." + classNameCluster.deliveryProps 1567 ); 1568 1569 //get properties from last compilation data 1570 var orderProperties = compilation["order"]["PROPERTIES"]["PROPERTIES"]; 1571 1572 //hide all delivery properties 1573 application.tools.hideByFlag($deliveryProperties, true); 1574 1575 //show properties from current delivery 1576 $.each(orderProperties, function () { 1577 if (typeof this["RELATION"] === "object" && !$.isEmptyObject(this["RELATION"])) { 1578 if ( 1579 typeof this["DELIVERY_RELATION"] !== undefined && 1580 this["DELIVERY_RELATION"] === "Y" 1581 ) { 1582 application.tools.hideByFlag( 1583 $deliveryProperties.filter('[data-property-id="' + this["ID"] + '"]') 1584 ); 1585 } 1586 } 1587 }); 1588 }; 1589 1590 application.commit.basket.deliveryPeriod = function (deliveryId) { 1591 //check types 1592 if ( 1593 typeof deliveryId !== "number" || 1594 isNaN(deliveryId) || 1595 typeof compilation["order"]["DELIVERIES"] !== "object" 1596 ) { 1597 return false; 1598 } 1599 1600 //jquery vars 1601 var $deliveryPeriod = $( 1602 "." + classNameCluster.propActive + " ." + classNameCluster.deliveryPeriod 1603 ); 1604 var $deliveryPeriodDescription = $deliveryPeriod.find( 1605 "." + classNameCluster.deliveryPeriodDescription 1606 ); 1607 1608 //other 1609 var periodDescription = 1610 compilation["order"]["DELIVERIES"][deliveryId]["PERIOD_DESCRIPTION"]; 1611 1612 //clear 1613 application.tools.clear($deliveryPeriodDescription); 1614 1615 //get current delivery info 1616 if (typeof compilation["order"]["DELIVERIES"][deliveryId] === "object") { 1617 if (periodDescription != "") { 1618 $deliveryPeriodDescription.html(periodDescription); 1619 } 1620 } 1621 1622 //set visible/unvisible peroiod container 1623 application.tools.hideByFlag($deliveryPeriod, periodDescription == ""); 1624 }; 1625 1626 application.commit.basket.deliveryDescription = function (deliveryId) { 1627 //check types 1628 if ( 1629 typeof deliveryId !== "number" || 1630 isNaN(deliveryId) || 1631 typeof compilation["order"]["DELIVERIES"] !== "object" 1632 ) { 1633 return false; 1634 } 1635 1636 //jquery vars 1637 var $deliveryDescription = $( 1638 "." + classNameCluster.propActive + " ." + classNameCluster.deliveryDescription 1639 ); 1640 var $deliveryModulesContainer = $( 1641 "." + classNameCluster.propActive + " ." + classNameCluster.deliveryModulesContainer 1642 ); 1643 var $deliveryModulesContainerDesc = $deliveryModulesContainer.find( 1644 "." + classNameCluster.deliveryModulesContainerDesc 1645 ); 1646 1647 //other 1648 var description = compilation["order"]["DELIVERIES"][deliveryId]["DESCRIPTION"]; 1649 1650 //clear 1651 application.tools.clear($deliveryDescription); 1652 application.tools.clear($deliveryModulesContainer); 1653 1654 //append to modules container description block 1655 $deliveryModulesContainer.append($deliveryModulesContainerDesc); 1656 1657 //get current delivery info 1658 if (typeof compilation["order"]["DELIVERIES"][deliveryId] === "object") { 1659 if (description != "") { 1660 $deliveryDescription.html(description); 1661 } 1662 } 1663 1664 //set visible/unvisible peroiod container 1665 application.tools.hideByFlag($deliveryDescription, description == ""); 1666 }; 1667 1668 application.commit.basket.gifts = function (jdata) { 1669 //jquery vars 1670 var $giftContainer = $("." + classNameCluster.giftContainer); 1671 1672 //get & check gift component 1673 var giftComponent = typeof jdata["gifts"] !== "undefined" ? jdata["gifts"] : ""; 1674 1675 //push gifts component 1676 $giftContainer.html(giftComponent); 1677 }; 1678 1679 application.commit.basket.paysystems = function () { 1680 //check empty 1681 if ( 1682 typeof compilation["order"]["PAYSYSTEMS"] !== "object" || 1683 $.isEmptyObject(compilation["order"]["PAYSYSTEMS"]) 1684 ) { 1685 //for display error message 1686 compilation["order"]["PAYSYSTEMS"] = { 1687 0: { 1688 ID: 0, 1689 NAME: basketLang["empty-paysystems"] 1690 } 1691 }; 1692 } 1693 1694 //jquery vars 1695 var $this = $("." + classNameCluster.propActive + " ." + classNameCluster.paysystem); 1696 1697 //get dropdown container 1698 var $dropDown = $this.parents("." + classNameCluster.dropDown); 1699 var $dropDownItems = $dropDown.find("." + classNameCluster.dropDownItems); 1700 var $dropDownSelected = $dropDown.find("." + classNameCluster.dropDownSelected); 1701 var $dropDownItemFirst = false; 1702 1703 //other 1704 var currentId = parseInt($this.val()); 1705 var selectedId = 0; 1706 1707 //get paysystems from last compilation data 1708 var paysystems = compilation["order"]["PAYSYSTEMS"]; 1709 1710 //get paysystems sorted indexes 1711 var sortPaysystems = application.tools.sortByIndex(paysystems); 1712 1713 //clear 1714 application.tools.clear($this); 1715 application.tools.clear($dropDownItems); 1716 1717 //each data 1718 $.each(sortPaysystems, function (currentIndex, nextPaysystemId) { 1719 //get next paysystem 1720 var nextPaysystem = paysystems[nextPaysystemId]; 1721 1722 //create next delivery item 1723 var $paysystemItem = $("<option/>").val(nextPaysystem["ID"]); 1724 var $dropDownItem = $("<div/>", { class: classNameCluster.dropDownItem }).data( 1725 "value", 1726 nextPaysystem["ID"] 1727 ); 1728 1729 //set title 1730 $paysystemItem.html(nextPaysystem["NAME"]); 1731 $dropDownItem.html(nextPaysystem["NAME"]); 1732 1733 //set selected 1734 if (currentId == nextPaysystem["ID"]) { 1735 //set option selected 1736 $paysystemItem.attr("selected", "selected"); 1737 1738 //set selected in dropdown 1739 $dropDownItem.addClass(classNameCluster.dropDownActive); 1740 1741 //change title in dropdown selected item 1742 $dropDownSelected.html(nextPaysystem["NAME"]); 1743 1744 //write selected id 1745 selectedId = nextPaysystem["ID"]; 1746 } 1747 1748 //save first item 1749 if ($dropDownItemFirst == false) { 1750 $dropDownItemFirst = $dropDownItem; 1751 } 1752 1753 //push 1754 $this.append($paysystemItem); 1755 $dropDownItems.append($dropDownItem); 1756 }); 1757 1758 //refresh var 1759 currentId = parseInt($this.val()); 1760 1761 //check selected id 1762 if (selectedId == 0 && currentId != "") { 1763 //get delivery from result 1764 var currentPaysystem = paysystems[currentId]; 1765 1766 //check current paysystem 1767 if (typeof currentPaysystem != "undefined" && !$.isEmptyObject(currentPaysystem)) { 1768 //add selected class 1769 $dropDownItemFirst.addClass(classNameCluster.dropDownActive); 1770 1771 //set title 1772 $dropDownSelected.html(currentPaysystem["NAME"]); 1773 } 1774 } 1775 1776 //processing 1777 application.commit.basket.payProperties(); 1778 application.commit.basket.payInner(); 1779 }; 1780 1781 application.commit.basket.payProperties = function () { 1782 //check types 1783 if (typeof compilation["order"]["PROPERTIES"] !== "object") { 1784 return false;
1785 } 1786 1787 //jquery vars 1788 var $paysystemProperties = $( 1789 "." + classNameCluster.propActive + " ." + classNameCluster.paysystemProps 1790 ); 1791 1792 //get properties from last compilation data 1793 var orderProperties = compilation["order"]["PROPERTIES"]["PROPERTIES"]; 1794 1795 //hide all delivery properties 1796 application.tools.hideByFlag($paysystemProperties, true); 1797 1798 //show properties from current delivery 1799 $.each(orderProperties, function () { 1800 if (typeof this["RELATION"] === "object" && !$.isEmptyObject(this["RELATION"])) { 1801 if ( 1802 typeof this["PAYSYSTEM_RELATION"] !== undefined && 1803 this["PAYSYSTEM_RELATION"] === "Y" 1804 ) { 1805 application.tools.hideByFlag( 1806 $paysystemProperties.filter('[data-property-id="' + this["ID"] + '"]') 1807 ); 1808 } 1809 } 1810 }); 1811 }; 1812 1813 application.commit.basket.payInner = function () { 1814 //jquery vars 1815 var $innerPaymentContainer = $("." + classNameCluster.budgetContainer); 1816 var $innerPayment = $("." + classNameCluster.budget); 1817 1818 //other 1819 var flags = { 1820 container: true 1821 }; 1822 1823 //check empty 1824 if (!$.isEmptyObject(compilation["order"]["INNER_PAYMENT"])) { 1825 //set flag 1826 flags.container = false; 1827 1828 //max amount to write off 1829 if ($.isEmptyObject(compilation["order"]["INNER_PAYMENT"]["RANGE"]["MAX"])) { 1830 $innerPayment.data("max", compilation["order"]["INNER_PAYMENT"]["RANGE"]["MAX"]); 1831 } 1832 } 1833 1834 //reset 1835 if (flags.container === true) { 1836 $innerPayment.removeAttr("checked"); 1837 } 1838 1839 //hide / show inner payment container 1840 application.tools.hideByFlag($innerPaymentContainer, flags.container); 1841 }; 1842 1843 application.commit.basket.minOrderPrice = function () { 1844 //check empty 1845 if (typeof compilation["min_order_amount"] !== "undefined") { 1846 //jquery vars 1847 var $order = $("." + classNameCluster.order); 1848 var $fastBuy = $("." + classNameCluster.fastBuy); 1849 var $goToOrder = $("." + classNameCluster.goToOrder); 1850 var $minPayment = $("." + classNameCluster.minPayment); 1851 1852 //hide / show blocks 1853 application.tools.hideByFlag($order, !compilation["min_order_amount"]); 1854 application.tools.hideByFlag($fastBuy, !compilation["min_order_amount"]); 1855 application.tools.hideByFlag($goToOrder, !compilation["min_order_amount"]); 1856 application.tools.hideByFlag($minPayment, compilation["min_order_amount"]); 1857 } 1858 }; 1859 1860 //realtime calculate sum & tools fields 1861 application.commit.basket.realtime = function () { 1862 //object map 1863 var self = { 1864 fields: {}, 1865 calculate: {} 1866 }; 1867 1868 //get fields 1869 self.fields.basket = $("." + classNameCluster.basket); 1870 self.fields.budget = self.fields.basket.find( 1871 "." + classNameCluster.propActive + " ." + classNameCluster.budget 1872 ); 1873 self.fields.delivery = self.fields.basket.find( 1874 "." + classNameCluster.propActive + " ." + classNameCluster.delivery 1875 ); 1876 self.fields.basketSum = self.fields.basket.find("." + classNameCluster.basketSum); 1877 self.fields.deliverySum = self.fields.basket.find("." + classNameCluster.deliverySum); 1878 self.fields.basketItems = self.fields.basket.find("." + classNameCluster.productItem); 1879 self.fields.orderSumContainer = self.fields.basket.find("." + classNameCluster.orderSum); 1880 self.fields.countItemsContainer = self.fields.basket.find( 1881 "." + classNameCluster.countItems 1882 ); 1883 1884 //calculate 1885 self.calculate.amount = application.calculate.getAmountProducts(self.fields.basketItems); 1886 self.calculate.basketSum = application.calculate.getBasketSum(self.fields.basketItems); 1887 self.calculate.orderSum = application.calculate.getOrderSum( 1888 self.fields.basketItems, 1889 self.fields.delivery, 1890 self.fields.budget, 1891 self.calculate.basketSum 1892 ); 1893 self.calculate.deliverySum = application.calculate.getDeliverySum(self.fields.delivery); 1894 1895 //push values 1896 self.fields.countItemsContainer.html(self.calculate.amount); 1897 self.fields.orderSumContainer.html( 1898 application.price.format(self.calculate.orderSum, false, false, false, true) 1899 ); 1900 self.fields.deliverySum.html( 1901 application.price.format(self.calculate.deliverySum, false, false, false, true) 1902 ); 1903 self.fields.basketSum.html( 1904 application.price.format(self.calculate.basketSum, false, false, false, true) 1905 ); 1906 }; 1907 1908 application.commit.basket.setCompilation = function (jsonData) { 1909 if (typeof jsonData === "object" && !$.isEmptyObject(jsonData)) { 1910 if (typeof jsonData["compilation"] === "object" && !$.isEmptyObject(jsonData)) { 1911 return (compilation = jsonData["compilation"]); 1912 } 1913 } 1914 1915 return (compilation = {}); 1916 }; 1917 1918 //location 1919 application.commit.location.pushComponent = function () { 1920 //jquery vars 1921 var $this = $("." + classNameCluster.propActive + " ." + classNameCluster.locationField); 1922 var $swichContainer = $this.siblings("." + classNameCluster.locationSwitchContainer); 1923 1924 //other 1925 var currentValue = $this.val().toString(); 1926 var sendObject = new FormData(); 1927 1928 //check filling 1929 if (currentValue == "") { 1930 return false;
1931 } 1932 1933 //push request params 1934 sendObject.append("actionType", "pushLocation"); 1935 sendObject.append("value", currentValue); 1936 sendObject.append("siteId", siteId); 1937 1938 //start loader 1939 application.tools.launchLoader($this); 1940 1941 //send data 1942 application.ajax.sendData( 1943 ajaxDir + "/ajax.php", 1944 sendObject, 1945 "post", 1946 "json", 1947 dataProcessing, 1948 false 1949 ); 1950 1951 //proccesing data after request 1952 function dataProcessing(jsonData) { 1953 //check state 1954 if (typeof jsonData["component"] == "string" && jsonData["component"] != "") { 1955 //set flag 1956 application.flags.location.open = true; 1957 1958 //push component data 1959 $swichContainer.html(jsonData["component"]); 1960 } 1961 1962 //check errors 1963 else { 1964 if (jsonData["error"] === true) { 1965 console.error(jsonData); 1966 } 1967 } 1968 1969 //remove loader 1970 application.tools.stopLoader($this); 1971 } 1972 }; 1973 1974 //calculate all order sum 1975 application.calculate.getOrderSum = function ( 1976 $basketItems, 1977 $deliveryField, 1978 $budgetSwitch, 1979 totalSum 1980 ) { 1981 //check total sum 1982 if (typeof totalSum == "undefined") { 1983 totalSum = 0; 1984 } 1985 1986 //check delivery 1987 if (typeof $deliveryField === "object") { 1988 totalSum += application.calculate.getDeliverySum($deliveryField); 1989 } 1990 1991 //check budget 1992 if (typeof $budgetSwitch === "object") { 1993 totalSum -= application.calculate.getBudgetMaxSum($budgetSwitch); 1994 } 1995 1996 return totalSum >= 0 ? totalSum : 0; 1997 }; 1998 1999 //calculate products sum 2000 application.calculate.getBasketSum = function ($basketItems) { 2001 //var 2002 var totalSum = 0; 2003 2004 //check empty 2005 if (typeof $basketItems === "object") { 2006 //get price containers 2007 var $priceFields = $basketItems.find("." + classNameCluster.productPrice); 2008 2009 //get quantity containers 2010 var $quantityFields = $basketItems.find("." + classNameCluster.quantityField); 2011 2012 //calculate 2013 $priceFields.each(function (currentIndex) { 2014 //get values 2015 var currentPrice = parseFloat($(this).data("price")); 2016 var currentQuantity = parseFloat($quantityFields.eq(currentIndex).val()); 2017 2018 //calculate 2019 totalSum += currentPrice * currentQuantity; 2020 }); 2021 } 2022 2023 return totalSum; 2024 }; 2025 2026 //calculate number of units products 2027 application.calculate.getAmountProducts = function ($basketItems, countItems) { 2028 //check count items 2029 if (typeof countItems == "undefined") { 2030 countItems = 0; 2031 } 2032 2033 //check empty 2034 if (typeof $basketItems === "object" && !$.isEmptyObject($basketItems)) { 2035 //get quantity containers 2036 var $quantityFields = $basketItems.find("." + classNameCluster.quantityField); 2037 2038 //calculate 2039 $quantityFields.each(function () { 2040 countItems += parseFloat($(this).val()); 2041 }); 2042 } 2043 2044 return countItems; 2045 }; 2046 2047 //delivery sum 2048 application.calculate.getDeliverySum = function ($deliveryField) { 2049 //check empty 2050 if (typeof $deliveryField === "object" && !$.isEmptyObject($deliveryField)) { 2051 var getDeliverySum = parseFloat($deliveryField.find("option:selected").data("price")); 2052 if (!isNaN(getDeliverySum) && getDeliverySum > 0) { 2053 return getDeliverySum; 2054 } 2055 } 2056 2057 return 0; 2058 }; 2059 2060 application.calculate.getBudgetMaxSum = function ($budgetSwitch) { 2061 //check object 2062 if (typeof $budgetSwitch === "object" && !$.isEmptyObject($budgetSwitch)) { 2063 //check state 2064 if ($budgetSwitch.is(":checked")) { 2065 //get balance 2066 var accountBalance = parseFloat($budgetSwitch.data("account-balance")); 2067 var maxSpend = parseFloat($budgetSwitch.data("max")); 2068 2069 //check max spend 2070 if (!isNaN(maxSpend) && maxSpend !== undefined) { 2071 if (accountBalance > maxSpend) { 2072 accountBalance = maxSpend; 2073 } 2074 } 2075 2076 //check balance 2077 if (accountBalance > 0) { 2078 return accountBalance; 2079 } 2080 } 2081 } 2082 2083 return 0; 2084 }; 2085 2086 //push functions 2087 2088 application.push.serializeFields = function ($orderFields, sendObject) { 2089 //check send object 2090 if (typeof sendObject == "undefined") { 2091 sendObject = {}; 2092 } 2093 2094 //check transmitted 2095 if (typeof $orderFields !== "undefined" && !$.isEmptyObject($orderFields)) { 2096 //collect 2097 $.each($orderFields, function () { 2098 //get field 2099 var $this = $(this); 2100 2101 //field data 2102 var field = { 2103 multiple: $this.prop("multiple"), 2104 tagName: $this.prop("tagName").toLowerCase(), 2105 checked: $this.prop("checked"), 2106 type: $this.attr("type"), 2107 name: $this.attr("name").toLowerCase(), 2108 id: $this.data("id"), 2109 val: $this.val() 2110 }; 2111 2112 if (field.id === "undefined") { 2113 console.error("undefined id"); 2114 } 2115 2116 //processing 2117 if (field.tagName == "input") { 2118 //text & checkbox (radio) 2119 if ( 2120 field.type == "text" || 2121 field.type == "date" || 2122 (field.type == "number" && field.val != "") || 2123 field.type == "checkbox" || 2124 (field.type == "radio" && field.checked == true) 2125 ) { 2126 sendObject.append("properties[" + field.id + "]", field.val); 2127 } 2128 //file 2129 else if (field.type == "file" && field.val != "") { 2130 //check multi file 2131 if ($this[0].files.length > 1) { 2132 $.each($this[0].files, function () { 2133 sendObject.append("properties[" + field.id + "][]", this); 2134 }); 2135 } //one 2136 else { 2137 sendObject.append("properties[" + field.id + "]", $this[0].files[0]); 2138 } 2139 } 2140 } 2141 2142 //textarea 2143 else if (field.tagName == "textarea" && field.val != "") { 2144 sendObject.append("properties[" + field.id + "]", field.val); 2145 } 2146 2147 //select 2148 else if (field.tagName == "select") { 2149 //multiselect 2150 if (field.multiple == true) { 2151 //get selected options 2152 var $options = $this.find("option:selected"); 2153 2154 //check count 2155 if ($options.length > 0) { 2156 //push values 2157 $.each($options, function () { 2158 sendObject.append("properties[" + field.id + "][]", $(this).val()); 2159 }); 2160 } 2161 } 2162 2163 //one 2164 else { 2165 sendObject.append("properties[" + field.id + "]", field.val); 2166 } 2167 } 2168 }); 2169 } 2170 2171 return sendObject; 2172 }; 2173 2174 application.push.fields = function (sendObject) { 2175 //push request params 2176 sendObject = application.push.formData( 2177 sendObject, 2178 application.pull.getExtraServices(), 2179 "extraServices" 2180 ); 2181 sendObject = application.push.formData( 2182 sendObject, 2183 application.pull.getPersonTypeId(), 2184 "personTypeId" 2185 ); 2186 sendObject = application.push.formData( 2187 sendObject, 2188 application.pull.getInnerPayment(), 2189 "innerPayment" 2190 ); 2191 sendObject = application.push.formData( 2192 sendObject, 2193 application.pull.getPaysystemId(), 2194 "paysystemId" 2195 ); 2196 sendObject = application.push.formData( 2197 sendObject, 2198 application.pull.getDeliveryId(), 2199 "deliveryId" 2200 ); 2201 sendObject = application.push.formData( 2202 sendObject, 2203 application.pull.getLocationId(), 2204 "locationId" 2205 ); 2206 sendObject = application.push.formData(sendObject, application.pull.getStoreId(), "store"); 2207 2208 return sendObject; 2209 }; 2210 2211 application.push.params = function (sendObject) { 2212 //append component params 2213 if (typeof basketParams === "object") { 2214 sendObject = application.push.formData(sendObject, basketParams, "params"); 2215 } 2216 2217 return sendObject; 2218 }; 2219 2220 application.push.orderComment = function (sendObject) { 2221 //get comment field 2222 var $comment = $("." + classNameCluster.propActive + " ." + classNameCluster.orderComment); 2223 2224 //check object 2225 if (typeof $comment === "object" && !$.isEmptyObject($comment)) { 2226 var commentValue = $comment.val(); 2227 2228 //check empty
2229 if (commentValue != undefined && commentValue != "") { 2230 sendObject = application.push.formData( 2231 sendObject, 2232 commentValue.toString(), 2233 "comment" 2234 ); 2235 } 2236 } 2237 2238 return sendObject; 2239 }; 2240 2241 application.push.formData = function (sendObject, values, name) { 2242 //sendObject(formData) 2243 //multi 2244 if (typeof values == "object") { 2245 //each values 2246 for (var index in values) { 2247 //recursion 2248 if (typeof values[index] == "object") { 2249 application.push.formData(sendObject, values[index], name + "[" + index + "]"); 2250 } 2251 2252 //one 2253 else { 2254 sendObject.append(name + "[" + index + "]", values[index]); 2255 } 2256 } 2257 } 2258 2259 //one 2260 else { 2261 sendObject.append(name, values); 2262 } 2263 2264 return sendObject; 2265 }; 2266 2267 //pull functions 2268 2269 application.pull.getOrderFields = function () { 2270 //main data 2271 var $orderFields = $([]); 2272 2273 //jquery vars 2274 var $self = $("." + classNameCluster.basket); 2275 2276 //write 2277 $orderFields.push.apply( 2278 $orderFields, 2279 $self.find( 2280 "." + 2281 classNameCluster.propActive + 2282 " ." + 2283 classNameCluster.propertyItem + 2284 ':not(".' + 2285 classNameCluster.propHidden + 2286 '") input' 2287 ) 2288 ); 2289 $orderFields.push.apply( 2290 $orderFields, 2291 $self.find( 2292 "." + 2293 classNameCluster.propActive + 2294 " ." + 2295 classNameCluster.propertyItem + 2296 ':not(".' + 2297 classNameCluster.propHidden + 2298 '") select' 2299 ) 2300 ); 2301 $orderFields.push.apply( 2302 $orderFields, 2303 $self.find( 2304 "." + 2305 classNameCluster.propActive + 2306 " ." + 2307 classNameCluster.propertyItem + 2308 ':not(".' + 2309 classNameCluster.propHidden + 2310 '") textarea' 2311 ) 2312 ); 2313 2314 return $orderFields; 2315 }; 2316 2317 application.pull.getLocationId = function () { 2318 //jquery vars 2319 var $locationField = $( 2320 "." + classNameCluster.propActive + " ." + classNameCluster.locationField 2321 ); 2322 2323 //other 2324 var locationId = parseFloat($locationField.data("location")); 2325 2326 //check empty 2327 if (!isNaN(locationId)) { 2328 return locationId; 2329 } 2330 2331 return 0; 2332 }; 2333 2334 application.pull.getStoreId = function () { 2335 return application.tools.getFieldValue( 2336 "." + 2337 classNameCluster.propActive + 2338 " ." + 2339 classNameCluster.storesContainer + 2340 ':not(".' + 2341 classNameCluster.propHidden + 2342 '") .' + 2343 classNameCluster.storesSwitch 2344 ); 2345 }; 2346 2347 application.pull.getInnerPayment = function () { 2348 return application.tools.getFieldValue( 2349 "." + 2350 classNameCluster.propActive + 2351 " ." + 2352 classNameCluster.budgetContainer + 2353 ':not(".' + 2354 classNameCluster.propHidden + 2355 '") .' + 2356 classNameCluster.budget 2357 ); 2358 }; 2359 2360 application.pull.getPaysystemId = function () { 2361 return application.tools.getFieldValue( 2362 "." + classNameCluster.propActive + " ." + classNameCluster.paysystem 2363 ); 2364 }; 2365 2366 application.pull.getDeliveryId = function () { 2367 return application.tools.getFieldValue( 2368 "." + classNameCluster.propActive + " ." + classNameCluster.delivery 2369 ); 2370 }; 2371 2372 application.pull.getPersonTypeId = function () { 2373 return application.tools.getFieldValue("." + classNameCluster.personType); 2374 }; 2375 2376 application.pull.getExtraServices = function () { 2377 //jquery vars 2378 var $serviceFieldsContainers = $( 2379 "." + 2380 classNameCluster.propActive + 2381 " ." + 2382 classNameCluster.extraServiceItemContainer + 2383 ':not(".' + 2384 classNameCluster.propHidden + 2385 '")' 2386 ); 2387 var $serviceFields = $serviceFieldsContainers.find("." + classNameCluster.extraService); 2388 var $deliveryField = $( 2389 "." + classNameCluster.propActive + " ." + classNameCluster.delivery 2390 ); 2391 2392 //other 2393 var extraServices = []; 2394 var currentDeliveryId = application.pull.getDeliveryId(); 2395 var deliverylastId = application.pull.getLastDeliveryId(); 2396 2397 //check empty 2398 if (typeof $serviceFields === "object" && $serviceFields.length > 0) { 2399 //get values 2400 $.each($serviceFields, function () { 2401 //get jquery object 2402 var $item = $(this); 2403 2404 //get field data 2405 var field = { 2406 value: application.tools.getFieldValue($item, false), 2407 id: $item.data("id") 2408 }; 2409 2410 //push 2411 if (field.value != "") { 2412 extraServices.push(field); 2413 } 2414 }); 2415 } 2416 2417 return extraServices; 2418 }; 2419 2420 application.pull.getLastDeliveryId = function () { 2421 //check filling 2422 if (deliveryId == 0) { 2423 //jquery vars 2424 var $deliveryField = $( 2425 "." + classNameCluster.propActive + " ." + classNameCluster.delivery 2426 ); 2427 2428 //get default delivery id 2429 if (typeof $deliveryField === "object" && !$.isEmptyObject($deliveryField)) { 2430 deliveryId = parseInt($deliveryField.data("default")); 2431 } 2432 } 2433 2434 return deliveryId; 2435 }; 2436 2437 //check functions 2438 application.check.required = function ($orderFields) { 2439 //vars 2440 var control = true; 2441 2442 //check transmitted 2443 if (typeof $orderFields === "undefined" && !$.isEmptyObject($orderFields)) { 2444 var $orderFields = application.pull.getOrderFields(); 2445 } 2446 2447 //check required 2448 $.each($orderFields, function () { 2449 //get jquery object 2450 var $this = $(this); 2451 2452 //check data 2453 if ($this.data("required") == "Y") { 2454 //check filling 2455 if (!application.check.filling($this)) { 2456 //add error marker 2457 application.tools.addError($this); 2458 2459 //check control / scroll 2460 if (control === true) { 2461 control = application.tools.scrollTo($this); 2462 } 2463 } 2464 } 2465 }); 2466 2467 return control; 2468 }; 2469 2470 //check functions 2471 application.check.filling = function ($field) { 2472 //check transmitted 2473 if (typeof $field !== "undefined" && !$.isEmptyObject($field)) { 2474 //field data 2475 var field = { 2476 tagName: $field.prop("tagName").toLowerCase(), 2477 checked: $field.prop("checked"), 2478 mail: $field.data("mail"), 2479 type: $field.attr("type"), 2480 name: $field.attr("name"), 2481 val: $field.val() 2482 }; 2483 2484 //check email 2485 if (field.mail != "undefined" && field.mail == "Y") { 2486 if (!application.tools.validateEmail(field.val)) { 2487 return false;
2488 } 2489 } 2490 2491 //check filling 2492 if ( 2493 (field.type == "checkbox" && field.checked == true) || 2494 (field.tagName == "textarea" && field.val != "") || 2495 (field.type == "number" && field.val != "") || 2496 (field.type == "text" && field.val != "") || 2497 (field.type == "date" && field.val != "") || 2498 (field.type == "file" && field.val != "") 2499 ) { 2500 return true; 2501 } 2502 } 2503 2504 return false; 2505 }; 2506 2507 //price functions 2508 application.price.format = function (price, decimals, decPoint, thousands, langFormat) { 2509 //set default values 2510 decimals = typeof decimals != "undefined" ? decimals : 2; 2511 decPoint = typeof decPoint != "undefined" ? decPoint : "."; 2512 thousands = typeof thousands != "undefined" ? thousands : " "; 2513 langFormat = typeof langFormat != "undefined" ? langFormat : false; 2514 2515 //check empty 2516 if (typeof price !== "undefined" && price !== null && price !== "") { 2517 //check global vars 2518 if (decPoint === false && siteCurrency["DEC_POINT"] !== undefined) { 2519 decPoint = siteCurrency["DEC_POINT"]; 2520 } 2521 2522 if (decimals === false && siteCurrency["DECIMALS"] !== undefined) { 2523 decimals = siteCurrency["DECIMALS"]; 2524 } 2525 2526 if (thousands === false && siteCurrency["THOUSANDS_VARIANT"] !== undefined) { 2527 thousands = application.price.thousandsVariant(siteCurrency["THOUSANDS_VARIANT"]); 2528 } 2529 2530 //vars 2531 var fsplit = price.toString().split("."); 2532 var whole = fsplit[0].replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, "$1" + thousands); 2533 var rest = ""; 2534 2535 //check rest 2536 if (fsplit[1] !== undefined && decimals > 0) { 2537 rest = decPoint + fsplit[1].substr(0, decimals); 2538 } 2539 2540 if (langFormat === true) { 2541 return application.price.langFormat(whole + rest); 2542 } else { 2543 return whole + rest; 2544 } 2545 } 2546 2547 return false; 2548 }; 2549 2550 application.price.langFormat = function (price) { 2551 return siteCurrency["FORMAT_STRING"].toString().replace("#", price); 2552 }; 2553 2554 application.price.thousandsVariant = function (thousands) { 2555 thousands = typeof thousands != "undefined" ? thousands : "N"; 2556 return siteCurrency["SEPARATORS"][thousands]; 2557 }; 2558 2559 //ajax functions 2560 application.ajax.sendData = function ( 2561 url, 2562 data, 2563 type, 2564 dataType, 2565 success, 2566 forEngageloader, 2567 contentType 2568 ) { 2569 //set default values 2570 forEngageloader = typeof forEngageloader != "undefined" ? forEngageloader : false;
2571 contentType = typeof contentType != "undefined" ? contentType : false; 2572 2573 //send request 2574 $.ajax({ 2575 contentType: contentType, 2576 dataType: dataType, 2577 processData: false, 2578 cache: false, 2579 url: url, 2580 type: type, 2581 data: data, 2582 success: success, 2583 beforeSend: function (jqXHR, settings) { 2584 application.tools.launchLoader(forEngageloader); 2585 }, 2586 complete: function (jqXHR, textStatus) { 2587 application.tools.stopLoader(forEngageloader); 2588 }, 2589 error: function (jqXHR, textStatus, errorThrown) { 2590 console.error({ httpResponse: jqXHR.responseText, status: jqXHR.statusText }); 2591 console.error(jqXHR, textStatus, errorThrown); 2592 } 2593 }); 2594 }; 2595 2596 //event functions 2597 application.event.trigger = function (eventName, eventData) { 2598 //set default values 2599 eventName = typeof eventName != "undefined" ? eventName : ""; 2600 eventData = typeof eventData != "undefined" ? eventData : []; 2601 2602 //check name 2603 if (eventName != "") { 2604 $(document).trigger("DwBasket." + eventName, eventData); 2605 } 2606 }; 2607 2608 //tools functions 2609 application.tools.resetLocation = function (event) { 2610 //jquery vars 2611 var $locationField = $( 2612 "." + classNameCluster.propActive + " ." + classNameCluster.locationField 2613 ); 2614 var $locationContainer = $locationField.siblings( 2615 "." + classNameCluster.locationSwitchContainer 2616 ); 2617 2618 //other 2619 var currentValue = $locationField.val().toString(); 2620 var currentId = $locationField.data("location").toString(); 2621 2622 //close dropdown 2623 application.tools.closeLocationDropdown($locationContainer); 2624 2625 //check filling 2626 if (currentValue == "" || currentId == "") { 2627 //get last values 2628 var lastId = $locationField.data("last-id"); 2629 var lastValue = $locationField.data("last-value"); 2630 2631 //white last values 2632 $locationField.data("location", lastId); 2633 $locationField.val(lastValue); 2634 } 2635 }; 2636 2637 application.tools.closeLocationDropdown = function ($container) { 2638 //set default 2639 $container = typeof $container != "undefined" ? $container : null; 2640 2641 //check object 2642 if (typeof $container === "object") { 2643 //check flag 2644 if (application.flags.location.open === true) { 2645 //set flag 2646 application.flags.location.open = false; 2647 2648 //clear 2649 application.tools.clear($container); 2650 } 2651 } 2652 }; 2653 2654 application.tools.getFieldValue = function (item, onlyChecked) { 2655 //set default 2656 onlyChecked = typeof onlyChecked != "undefined" ? onlyChecked : true; 2657 2658 //check empty 2659 if ( 2660 (typeof item === "string" && item !== "") || 2661 (typeof item === "object" && item.length > 0) 2662 ) { 2663 //jquery vars 2664 var $field = typeof item === "object" ? item : $(item); 2665 2666 //check 2667 if (typeof $field === "object" && $field.length > 0) { 2668 //other 2669 var field = { 2670 tagName: $field.prop("tagName").toLowerCase(), 2671 checked: $field.prop("checked"), 2672 type: $field.attr("type"), 2673 val: $field.val() 2674 }; 2675 2676 //select 2677 if ( 2678 field.tagName == "select" && 2679 field.val !== undefined && 2680 field.val !== null && 2681 field.val !== "" 2682 ) { 2683 return field.val.toString(); 2684 } 2685 2686 //checkbox / radio 2687 else if ( 2688 field.tagName == "input" && 2689 typeof field.type !== undefined && 2690 (field.type == "checkbox" || field.type == "radio") 2691 ) { 2692 if (field.checked == true) { 2693 return field.val.toString(); 2694 } else if (onlyChecked === false) { 2695 return "N"; 2696 } 2697 } 2698 2699 //text / number 2700 else if ( 2701 field.tagName == "input" && 2702 typeof field.type !== undefined && 2703 (field.type == "text" || field.type == "number") 2704 ) { 2705 if (field.val != "") { 2706 return field.val.toString(); 2707 } 2708 } 2709 } 2710 } 2711 2712 return 0; 2713 }; 2714 2715 application.tools.startTimer = function (selector, readySelector, seconds) { 2716 //set default 2717 readySelector = typeof readySelector != "undefined" ? readySelector : false; 2718 seconds = typeof seconds != "undefined" ? seconds : 60; 2719 2720 //check empty 2721 if (typeof selector != "undefined" && selector != "") { 2722 //jquery vars 2723 var $timer = $(selector); 2724 2725 //show timer 2726 application.tools.hideByFlag($timer, false); 2727 2728 //other 2729 var dates = { 2730 current: new Date(), 2731 end: new Date(Date.now() + seconds * 1000) 2732 }; 2733 2734 //is timer discovered 2735 if (typeof $timer == "object" && !$.isEmptyObject($timer)) { 2736 //check second settings 2737 if (typeof seconds == "number" && seconds > 0) { 2738 //indication 2739 var timerId = setInterval(function () { 2740 //set current date 2741 dates.current = new Date(); 2742 2743 //change html 2744 if (dates.end.getTime() > dates.current.getTime()) { 2745 //calculate 2746 dates.remaining = new Date( 2747 dates.end.getTime() - dates.current.getTime() 2748 ); 2749 dates.minutes = Math.floor((dates.remaining / 1000 / 60) % 60); 2750 dates.seconds = Math.floor((dates.remaining / 1000) % 60); 2751 2752 //push 2753 $timer.text(dates.minutes + ":" + dates.seconds); 2754 } 2755 2756 //off 2757 else { 2758 //hide timer 2759 application.tools.hideByFlag($timer, true); 2760 2761 //block indication 2762 clearInterval(timerId); 2763 2764 //set ready 2765 if (readySelector != false) { 2766 $(readySelector).addClass("ready"); 2767 } 2768 } 2769 }, 900); 2770 } 2771 } 2772 } 2773 }; 2774 2775 application.tools.clear = function ($item) { 2776 if (typeof $item === "object") { 2777 return $item.html(""); 2778 } 2779 }; 2780 2781 application.tools.hideByFlag = function ($item, flag, className) { 2782 //set default 2783 flag = typeof flag != "undefined" ? flag : false;
2784 className = typeof className != "undefined" ? className : "hidden"; 2785 2786 //check object 2787 if (typeof $item === "object") { 2788 return flag === true ? $item.addClass(className) : $item.removeClass(className); 2789 } 2790 }; 2791 2792 application.tools.launchLoader = function ($item, loaderClassName) { 2793 //set default 2794 loaderClassName = typeof loaderClassName != "undefined" ? loaderClassName : "loading"; 2795 2796 //check transmitted item 2797 if (typeof $item === "object") { 2798 return $item.addClass(loaderClassName); 2799 } 2800 }; 2801 2802 application.tools.stopLoader = function ($item, loaderClassName) { 2803 //set default 2804 loaderClassName = typeof loaderClassName != "undefined" ? loaderClassName : "loading"; 2805 2806 //check transmitted item 2807 if (typeof $item === "object") { 2808 return $item.removeClass(loaderClassName); 2809 } 2810 }; 2811 2812 //errors 2813 application.tools.addError = function ($item, errorClassName) { 2814 //set default 2815 errorClassName = 2816 typeof errorClassName != "undefined" ? errorClassName : classNameCluster.error; 2817 2818 //check transmitted item 2819 if (typeof $item === "object") { 2820 return $item.addClass(errorClassName); 2821 } 2822 }; 2823 2824 application.tools.removeError = function ($item, errorClassName) { 2825 //set default 2826 errorClassName = 2827 typeof errorClassName != "undefined" ? errorClassName : classNameCluster.error; 2828 2829 //check transmitted item 2830 if (typeof $item === "object") { 2831 return $item.removeClass(errorClassName); 2832 } 2833 }; 2834 2835 application.tools.addParamToUrl = function (params) { 2836 //set default 2837 params = typeof params != "undefined" ? params : {}; 2838 2839 //get current url 2840 var url = window.location.href; 2841 var separator = url.indexOf("?") === -1 ? "?" : "&"; 2842 2843 //check empty 2844 if (typeof params === "object" && !$.isEmptyObject(params)) { 2845 //append params 2846 $.each(params, function (param, value) { 2847 url = url + separator + param + "=" + value; 2848 separator = url.indexOf("?") === -1 ? "?" : "&"; 2849 }); 2850 } 2851 2852 return url; 2853 }; 2854 2855 application.tools.validateEmail = function (email) { 2856 //vars 2857 var regularEx = 2858 /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/; 2859 2860 //check empty 2861 if (typeof email === "string" && email != "") { 2862 return regularEx.test(String(email).toLowerCase()); 2863 } 2864 2865 return false; 2866 }; 2867 2868 application.tools.scrollTo = function ($item) { 2869 if (typeof $item === "object") { 2870 $([document.documentElement, document.body]).animate( 2871 { 2872 scrollTop: $item.offset().top - 300 2873 }, 2874 600 2875 ); 2876 } 2877 2878 return false; 2879 }; 2880 2881 application.tools.pushAjaxErrors = function (errorData, errorId) { 2882 //set default 2883 errorData = typeof errorData != "undefined" ? errorData : {}; 2884 errorId = typeof errorId != "undefined" ? errorId : "orderErrors"; 2885 2886 //check empty 2887 if (typeof errorData === "object" && !$.isEmptyObject(errorData)) { 2888 //jquery vars 2889 var $errorWindow = $("." + errorIds[errorId]); 2890 var $windowMessage = $errorWindow.find("." + classNameCluster.errorWindowMessage); 2891 2892 //confirm 2893 if (!$.isEmptyObject($errorWindow) && !$.isEmptyObject($windowMessage)) { 2894 //push errors 2895 $windowMessage.html(readError(errorData)); 2896 2897 //show 2898 application.tools.openWindow(errorIds[errorId]); 2899 } 2900 } 2901 2902 //recursive 2903 function readError(data, concated) { 2904 //set default 2905 concated = typeof concated != "undefined" ? concated : ""; 2906 2907 //vars 2908 var delimiter = " • "; 2909 2910 //one 2911 if (typeof data == "string" && data != "") { 2912 concated += (concated != "" ? delimiter : "") + data; 2913 } 2914 2915 //multi 2916 else if (typeof data == "object") { 2917 $.each(data, function () { 2918 concated = readError(this, concated); 2919 }); 2920 } 2921 2922 return concated; 2923 } 2924 2925 return false; 2926 }; 2927 2928 application.tools.sortByIndex = function (data) { 2929 //vars 2930 var sortedItems = {}; 2931 2932 //check data 2933 if (typeof data != "undefined" && !$.isEmptyObject(data)) { 2934 $.each(data, function (currentIndex, nextDataItem) { 2935 if (typeof nextDataItem["INDEX"] != "undefined") { 2936 sortedItems[nextDataItem["INDEX"]] = nextDataItem["ID"]; 2937 } 2938 }); 2939 } 2940 2941 return sortedItems; 2942 }; 2943 2944 //openWindow 2945 application.tools.openWindow = function (errorClass) { 2946 if (typeof errorClass != "undefined" && errorClass != "") { 2947 var $errorWindow = $("." + errorClass); 2948 if (typeof $errorWindow === "object" && !$.isEmptyObject($errorWindow)) { 2949 $errorWindow.css({ display: "block" }); 2950 } 2951 } 2952 }; 2953 2954 application.tools.closeWindow = function ($errorWindow) { 2955 if (typeof $errorWindow === "object" && !$.isEmptyObject($errorWindow)) { 2956 $errorWindow.css({ display: "none" }); 2957 } 2958 }; 2959 2960 application.tools.getNamesFromCluster = function () { 2961 return classNameCluster; 2962 }; 2963 2964 application.tools.closeDropDown = function () { 2965 //check opened items 2966 if (application.flags.dropDown.open === true) { 2967 //hide 2968 $("." + classNameCluster.dropDownItems).removeClass(classNameCluster.dropDownOpened); 2969 2970 //set opened flag 2971 application.flags.dropDown.open = false;
2972 } 2973 }; 2974 2975 //write to global var 2976 DwBasket = application; 2977 2978 //jquery binding functions 2979 //you must edit constants for fast customization 2980 2981 //click 2982 $(document).on( 2983 "click", 2984 "." + classNameCluster.order + " ." + classNameCluster.dropDownSelected, 2985 application.binding.click.openDropDown 2986 ); 2987 $(document).on( 2988 "click", 2989 "." + classNameCluster.order + " ." + classNameCluster.dropDownItem, 2990 application.binding.click.selectDropDown 2991 ); 2992 $(document).on( 2993 "click", 2994 "." + classNameCluster.order + " ." + classNameCluster.dropDown, 2995 application.binding.click.stop 2996 ); 2997 $(document).on( 2998 "click", 2999 "." + classNameCluster.errorWindowClose, 3000 application.binding.click.closeErrorWindow 3001 ); 3002 $(document).on( 3003 "click", 3004 "." + classNameCluster.locationSwitchLink, 3005 application.binding.click.locationLink 3006 ); 3007 $(document).on( 3008 "click", 3009 "." + classNameCluster.locationSwitchContainer, 3010 application.binding.click.stop 3011 ); 3012 $(document).on( 3013 "click", 3014 "." + classNameCluster.confirmReplay, 3015 application.binding.click.confirmReplay 3016 ); 3017 $(document).on( 3018 "click", 3019 "." + classNameCluster.confirmSend, 3020 application.binding.click.confirmSend 3021 ); 3022 $(document).on( 3023 "click", 3024 "." + classNameCluster.couponButton, 3025 application.binding.click.setCoupon 3026 ); 3027 $(document).on("click", "." + classNameCluster.remove, application.binding.click.deleteItem); 3028 $(document).on("click", "." + classNameCluster.minus, application.binding.click.quantityMinus); 3029 $(document).on("click", "." + classNameCluster.plus, application.binding.click.quantityPlus); 3030 $(document).on("click", "." + classNameCluster.orderMake, application.binding.click.orderMake); 3031 $(document).on("click", "." + classNameCluster.orderMove, application.binding.click.orderMove); 3032 $(document).on("click", "." + classNameCluster.clearAll, application.binding.click.clearAll); 3033 $(document).on("click", "", application.binding.click.closeout); 3034 3035 //submit 3036 $(document).on( 3037 "submit", 3038 "." + classNameCluster.confirmForm, 3039 application.binding.submit.confirmForm 3040 ); 3041 3042 //keyup 3043 $(document).on( 3044 "keyup", 3045 "." + classNameCluster.locationField, 3046 application.binding.keyup.location 3047 ); 3048 3049 //input 3050 $(document).on("input", "." + classNameCluster.confirmField, application.binding.input.confirm); 3051 3052 //keypress 3053 $(document).on( 3054 "keypress", 3055 "." + classNameCluster.quantityField, 3056 application.binding.keypress.quantity 3057 ); 3058 $(document).on( 3059 "keypress", 3060 "." + classNameCluster.extraService, 3061 application.binding.keypress.quantity 3062 ); 3063 3064 //focus 3065 $(document).on( 3066 "focus", 3067 "." + classNameCluster.locationField, 3068 application.binding.focus.location 3069 ); 3070 $(document).on("focus", "." + classNameCluster.couponField, application.binding.focus.coupon); 3071 3072 //focus 3073 $(document).on("blur", "." + classNameCluster.locationField, application.binding.blur.location); 3074 3075 //change 3076 $(document).on( 3077 "change", 3078 "." + classNameCluster.extraService, 3079 application.binding.change.extraService 3080 ); 3081 $(document).on( 3082 "change", 3083 "." + classNameCluster.quantityField, 3084 application.binding.change.quantity 3085 ); 3086 $(document).on( 3087 "change", 3088 "." + classNameCluster.paysystem, 3089 application.binding.change.paysystem 3090 ); 3091 $(document).on("change", "." + classNameCluster.personType, application.binding.change.person); 3092 $(document).on("change", "." + classNameCluster.delivery, application.binding.change.delivery); 3093 $(document).on("change", "." + classNameCluster.budget, application.binding.change.budget); 3094});
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.