|
131 | 131 | function objectifyForm(form, extend) { |
132 | 132 | var formArray = form.serializeArray(); |
133 | 133 | var returnArray = {}; |
| 134 | + var input_name = '', input_value = ''; |
134 | 135 | for (var i = 0; i < formArray.length; i++){ |
135 | | - returnArray[formArray[i]['name']] = formArray[i]['value']; |
| 136 | + input_name = formArray[i]['name']; |
| 137 | + input_value = formArray[i]['value']; |
| 138 | + if(input_name.indexOf('[]') != -1){ |
| 139 | + input_name = input_name.replace('[]', ''); |
| 140 | + if(returnArray[input_name] == undefined){ |
| 141 | + returnArray[input_name] = []; |
| 142 | + } |
| 143 | + returnArray[input_name].push(input_value); |
| 144 | + } else { |
| 145 | + returnArray[input_name] = input_value; |
| 146 | + } |
136 | 147 | } |
137 | 148 | if(extend != undefined){ |
138 | 149 | returnArray = $.extend(extend, returnArray); |
|
552 | 563 | function delayImportEntity(type){ |
553 | 564 | importEntity(type); |
554 | 565 | /*var time = parseFloat(settings.delay); |
555 | | - if(time > 0){ |
556 | | - var delay = time * 1000; |
557 | | - setTimeout(function(){ |
558 | | - importEntity(type); |
559 | | - }, delay); |
560 | | - } else { |
561 | | - importEntity(type); |
562 | | - }*/ |
| 566 | + if(time > 0){ |
| 567 | + var delay = time * 1000; |
| 568 | + setTimeout(function(){ |
| 569 | + importEntity(type); |
| 570 | + }, delay); |
| 571 | + } else { |
| 572 | + importEntity(type); |
| 573 | + }*/ |
563 | 574 | } |
564 | 575 |
|
565 | 576 | function processBarResult(entity, total, imported, error, point) |
|
656 | 667 | }); |
657 | 668 | } |
658 | 669 |
|
| 670 | + function activeValidateExtra(element){ |
| 671 | + element.addClass('section-validate-extra'); |
| 672 | + } |
| 673 | + |
| 674 | + function deactivateValidateExtra(element){ |
| 675 | + element.removeClass('section-validate-extra'); |
| 676 | + } |
| 677 | + |
| 678 | + function registerDrupalCommerceEvent(){ |
| 679 | + registerEvent('change-entities', function(e, elm){ |
| 680 | + var is_config_sdc_manufacturer = $('#section-sdc-manufacturer', container).length > 0; |
| 681 | + var is_config_sdc_category = $('#section-sdc-category', container).length > 0; |
| 682 | + var is_config_sdc_product = $('#section-sdc-product', container).length > 0; |
| 683 | + if(is_config_sdc_manufacturer || is_config_sdc_category || is_config_sdc_product){ |
| 684 | + $('#entity-section .entity-input-type', container).each(function(){ |
| 685 | + var input = $(this); |
| 686 | + var input_entity = input.data('entity'); |
| 687 | + var is_checked = input.is(':checked'); |
| 688 | + if(input_entity == 'manufacturers'){ |
| 689 | + if(is_checked){ |
| 690 | + $('#section-sdc-manufacturer', container).css({display: 'block'}); |
| 691 | + activeValidateExtra($('#section-sdc-manufacturer-type', container)); |
| 692 | + } else { |
| 693 | + $('#section-sdc-manufacturer', container).css({display: 'none'}); |
| 694 | + deactivateValidateExtra($('#section-sdc-manufacturer-type', container)); |
| 695 | + } |
| 696 | + } |
| 697 | + if(input_entity == 'categories'){ |
| 698 | + if(is_checked){ |
| 699 | + $('#section-sdc-category', container).css({display: 'block'}); |
| 700 | + activeValidateExtra($('#section-sdc-category-type', container)); |
| 701 | + } else { |
| 702 | + $('#section-sdc-category', container).css({display: 'none'}); |
| 703 | + deactivateValidateExtra($('#section-sdc-category-type', container)); |
| 704 | + } |
| 705 | + } |
| 706 | + if(input_entity == 'products'){ |
| 707 | + if(is_checked){ |
| 708 | + $('#section-sdc-product', container).css({display: 'block'}); |
| 709 | + } else { |
| 710 | + $('#section-sdc-product', container).css({display: 'none'}); |
| 711 | + } |
| 712 | + } |
| 713 | + }); |
| 714 | + } |
| 715 | + |
| 716 | + var is_config_tdc_manufacturer = $('#section-tdc-manufacturer', container).length > 0; |
| 717 | + var is_config_tdc_category = $('#section-tdc-category', container).length > 0; |
| 718 | + var is_config_tdc_product = $('#section-tdc-product', container).length > 0; |
| 719 | + if(is_config_tdc_manufacturer || is_config_tdc_category || is_config_tdc_product){ |
| 720 | + $('#entity-section .entity-input-type', container).each(function(){ |
| 721 | + var input = $(this); |
| 722 | + var input_entity = input.data('entity'); |
| 723 | + var is_checked = input.is(':checked'); |
| 724 | + if(input_entity == 'manufacturers'){ |
| 725 | + if(is_checked){ |
| 726 | + $('#section-tdc-manufacturer', container).css({display: 'block'}); |
| 727 | + activeValidateExtra($('#section-tdc-manufacturer-type', container)); |
| 728 | + activeValidateExtra($('#section-tdc-manufacturer .tdc-manufacturer-map', container)); |
| 729 | + } else { |
| 730 | + $('#section-tdc-manufacturer', container).css({display: 'none'}); |
| 731 | + deactivateValidateExtra($('#section-tdc-manufacturer-type', container)); |
| 732 | + deactivateValidateExtra($('#section-tdc-manufacturer .tdc-manufacturer-map', container)); |
| 733 | + } |
| 734 | + } |
| 735 | + if(input_entity == 'categories'){ |
| 736 | + if(is_checked){ |
| 737 | + $('#section-tdc-category', container).css({display: 'block'}); |
| 738 | + activeValidateExtra($('#section-tdc-category-type', container)); |
| 739 | + activeValidateExtra($('#section-tdc-category .tdc-category-map', container)); |
| 740 | + } else { |
| 741 | + $('#section-tdc-category', container).css({display: 'none'}); |
| 742 | + deactivateValidateExtra($('#section-tdc-category-type', container)); |
| 743 | + deactivateValidateExtra($('#section-tdc-category .tdc-category-map', container)); |
| 744 | + } |
| 745 | + } |
| 746 | + if(input_entity == 'products'){ |
| 747 | + if(is_checked){ |
| 748 | + $('#section-tdc-product', container).css({display: 'block'}); |
| 749 | + activeValidateExtra($('#section-tdc-product .tdc-product-map', container)); |
| 750 | + } else { |
| 751 | + $('#section-tdc-product', container).css({display: 'none'}); |
| 752 | + deactivateValidateExtra($('#section-tdc-product .tdc-product-map', container)); |
| 753 | + } |
| 754 | + } |
| 755 | + }); |
| 756 | + } |
| 757 | + }); |
| 758 | + |
| 759 | + $(container).on('change', '#sdc-manufacturer-types', function(){ |
| 760 | + var entityType = $(this).val(); |
| 761 | + $('#section-sdc-manufacturer .sdc-manufacturer-map', container).css({display: 'none'}); |
| 762 | + if(entityType != null){ |
| 763 | + entityType.forEach(function(entity_type){ |
| 764 | + $('#sdc-manufacturer-' + entity_type, container).css({display: 'block'}); |
| 765 | + }); |
| 766 | + } |
| 767 | + }); |
| 768 | + |
| 769 | + $(container).on('change', '#sdc-category-types', function(){ |
| 770 | + var categoryType = $(this).val(); |
| 771 | + $('#section-sdc-category .sdc-category-map', container).css({display: 'none'}); |
| 772 | + if(categoryType != null){ |
| 773 | + categoryType.forEach(function(category_type){ |
| 774 | + $('#sdc-category-' + category_type, container).css({display: 'block'}); |
| 775 | + }); |
| 776 | + } |
| 777 | + }); |
| 778 | + |
| 779 | + $(container).on('change', '#tdc-manufacturer-types', function(){ |
| 780 | + var entityType = $(this).val(); |
| 781 | + $('#section-tdc-manufacturer .tdc-manufacturer-map', container).css({display: 'none'}); |
| 782 | + if(entityType != null){ |
| 783 | + entityType.forEach(function(entity_type){ |
| 784 | + $('#tdc-manufacturer-' + entity_type, container).css({display: 'block'}); |
| 785 | + }); |
| 786 | + } |
| 787 | + }); |
| 788 | + |
| 789 | + $(container).on('change', '#tdc-category-types', function(){ |
| 790 | + var categoryType = $(this).val(); |
| 791 | + $('#section-tdc-category .tdc-category-map', container).css({display: 'none'}); |
| 792 | + if(categoryType != null){ |
| 793 | + categoryType.forEach(function(category_type){ |
| 794 | + $('#tdc-category-' + category_type, container).css({display: 'block'}); |
| 795 | + }); |
| 796 | + } |
| 797 | + }); |
| 798 | + } |
| 799 | + |
| 800 | + function triggerEvent(event_name, data){ |
| 801 | + $(container).trigger(event_name, data); |
| 802 | + } |
| 803 | + |
| 804 | + function registerEvent(event_name, callback){ |
| 805 | + $(container).on(event_name, callback); |
| 806 | + } |
| 807 | + |
| 808 | + function registerEvents(){ |
| 809 | + registerDrupalCommerceEvent(); |
| 810 | + } |
| 811 | + |
| 812 | + function validateExtraSection(){ |
| 813 | + if($('.section-validate-extra', container).length < 1){ |
| 814 | + return true; |
| 815 | + } |
| 816 | + var resultAll = true; |
| 817 | + $('.section-validate-extra.section-validate-required', container).each(function(i, v){ |
| 818 | + var section = $(this); |
| 819 | + var result = true; |
| 820 | + $('select', section).each(function(index, value) { |
| 821 | + var select = $(this); |
| 822 | + if(select.hasClass('ignore-required')){ |
| 823 | + return; |
| 824 | + } |
| 825 | + var elm_val = $(value).val(); |
| 826 | + if(!elm_val){ |
| 827 | + result = false; |
| 828 | + return false; |
| 829 | + } |
| 830 | + }); |
| 831 | + if(!result){ |
| 832 | + resultAll = false; |
| 833 | + $('.message-valid', section).html('The mapping is required. Please select the missing mapping!').show(); |
| 834 | + scrollToErrorMessage(section); |
| 835 | + } |
| 836 | + }); |
| 837 | + if(!resultAll){ |
| 838 | + return resultAll; |
| 839 | + } |
| 840 | + $('.section-validate-extra.section-validate-duplicate', container).each(function(i, v){ |
| 841 | + var section = $(this); |
| 842 | + var check = new Array(); |
| 843 | + $('select', section).each(function(index, value) { |
| 844 | + var elm_val = $(value).val(); |
| 845 | + var elm_opt = $(value).find(':selected'); |
| 846 | + var duplicate = elm_opt.data('ignore-duplicate'); |
| 847 | + if(duplicate == undefined || !duplicate){ |
| 848 | + duplicate = 0; |
| 849 | + } |
| 850 | + if(elm_val && duplicate == 0){ |
| 851 | + check[index] = elm_val; |
| 852 | + } |
| 853 | + }); |
| 854 | + var result = true; |
| 855 | + check.forEach(function(value, index) { |
| 856 | + check.forEach(function(value_tmp, index_tmp) { |
| 857 | + if (value_tmp === value && index !== index_tmp) { |
| 858 | + result = false; |
| 859 | + } |
| 860 | + }); |
| 861 | + }); |
| 862 | + if(!result){ |
| 863 | + $('.message-valid', section).html('Mapping value can\'t not be the same. Please change!').show(); |
| 864 | + scrollToErrorMessage(section); |
| 865 | + resultAll = false; |
| 866 | + } |
| 867 | + }); |
| 868 | + return resultAll; |
| 869 | + } |
| 870 | + |
659 | 871 | function run(){ |
660 | 872 |
|
661 | 873 | deleteCookie(); |
|
869 | 1081 | var current = _this.closest('li'); |
870 | 1082 | current.find('ul input.entity-input-type').prop('checked', false); |
871 | 1083 | } |
| 1084 | + triggerEvent('change-entities', this); |
872 | 1085 | }); |
873 | 1086 |
|
874 | 1087 | $(container).on('click', '#config-wrap #entity-section #entity-input-all', function(){ |
|
880 | 1093 | var current = _this.closest('#entity-section'); |
881 | 1094 | current.find('ul input.entity-input-type').prop('checked', false); |
882 | 1095 | } |
| 1096 | + triggerEvent('change-entities', this); |
883 | 1097 | }); |
884 | 1098 |
|
885 | 1099 | $(container).on('click', '#config-wrap .retry-action', function(){ |
|
909 | 1123 | || validateSelectDuplicate('#language-section') |
910 | 1124 | || !validateCheckRequired('#entity-section') |
911 | 1125 | || validateSelectsDuplicate('.cf-section-entity-map') |
912 | | - || validateCustomFieldMapType()){ |
| 1126 | + || validateCustomFieldMapType() |
| 1127 | + || !validateExtraSection()){ |
913 | 1128 | hideLoading(); |
914 | 1129 | return false; |
915 | 1130 | } |
|
1051 | 1266 | }); |
1052 | 1267 |
|
1053 | 1268 | $(container).on('click', '.download-gateway-direct', function(){ |
1054 | | - var token = $(this).parents('.form-group').find('input').val(); |
| 1269 | + var wrap = $(this).closest('.platform-type-info'); |
| 1270 | + var token_input = wrap.find('input.platform-connector-token'); |
| 1271 | + var token = token_input.val(); |
1055 | 1272 | if(!token){ |
1056 | 1273 | token = genToken(); |
1057 | 1274 | } |
1058 | | - $(this).parents('.form-group').find('input').val(token); |
| 1275 | + token_input.val(token); |
1059 | 1276 | var request_download = getRequestDownload(); |
1060 | 1277 | var data = $.extend({ |
1061 | 1278 | mg_token: token |
|
1074 | 1291 | }); |
1075 | 1292 |
|
1076 | 1293 | $(container).on('click', '.download-gateway', function(){ |
1077 | | - var token = $(this).parents('.form-group').find('input').val(); |
| 1294 | + var wrap = $(this).closest('.platform-type-info'); |
| 1295 | + var token_input = wrap.find('input.platform-connector-token'); |
| 1296 | + var token = token_input.val(); |
1078 | 1297 | if(!token){ |
1079 | 1298 | token = genToken(); |
1080 | 1299 | } |
1081 | | - $(this).parents('.form-group').find('input').val(token); |
| 1300 | + token_input.val(token); |
1082 | 1301 | var request = new XMLHttpRequest(); |
1083 | 1302 | request.open('POST', settings.url, true); |
1084 | 1303 | request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
|
1120 | 1339 | window.open(url, '_blank'); |
1121 | 1340 | }); |
1122 | 1341 |
|
| 1342 | + registerEvents(); |
| 1343 | + |
1123 | 1344 | } |
1124 | 1345 |
|
1125 | 1346 | return run(); |
|
0 commit comments