Skip to content

Commit f283935

Browse files
committed
u20220808 - generate token
1 parent 85c9e3c commit f283935

File tree

1 file changed

+235
-14
lines changed

1 file changed

+235
-14
lines changed

view/adminhtml/web/js/jquery.migration.js

Lines changed: 235 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,19 @@
131131
function objectifyForm(form, extend) {
132132
var formArray = form.serializeArray();
133133
var returnArray = {};
134+
var input_name = '', input_value = '';
134135
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+
}
136147
}
137148
if(extend != undefined){
138149
returnArray = $.extend(extend, returnArray);
@@ -552,14 +563,14 @@
552563
function delayImportEntity(type){
553564
importEntity(type);
554565
/*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+
}*/
563574
}
564575

565576
function processBarResult(entity, total, imported, error, point)
@@ -656,6 +667,207 @@
656667
});
657668
}
658669

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+
659871
function run(){
660872

661873
deleteCookie();
@@ -869,6 +1081,7 @@
8691081
var current = _this.closest('li');
8701082
current.find('ul input.entity-input-type').prop('checked', false);
8711083
}
1084+
triggerEvent('change-entities', this);
8721085
});
8731086

8741087
$(container).on('click', '#config-wrap #entity-section #entity-input-all', function(){
@@ -880,6 +1093,7 @@
8801093
var current = _this.closest('#entity-section');
8811094
current.find('ul input.entity-input-type').prop('checked', false);
8821095
}
1096+
triggerEvent('change-entities', this);
8831097
});
8841098

8851099
$(container).on('click', '#config-wrap .retry-action', function(){
@@ -909,7 +1123,8 @@
9091123
|| validateSelectDuplicate('#language-section')
9101124
|| !validateCheckRequired('#entity-section')
9111125
|| validateSelectsDuplicate('.cf-section-entity-map')
912-
|| validateCustomFieldMapType()){
1126+
|| validateCustomFieldMapType()
1127+
|| !validateExtraSection()){
9131128
hideLoading();
9141129
return false;
9151130
}
@@ -1051,11 +1266,13 @@
10511266
});
10521267

10531268
$(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();
10551272
if(!token){
10561273
token = genToken();
10571274
}
1058-
$(this).parents('.form-group').find('input').val(token);
1275+
token_input.val(token);
10591276
var request_download = getRequestDownload();
10601277
var data = $.extend({
10611278
mg_token: token
@@ -1074,11 +1291,13 @@
10741291
});
10751292

10761293
$(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();
10781297
if(!token){
10791298
token = genToken();
10801299
}
1081-
$(this).parents('.form-group').find('input').val(token);
1300+
token_input.val(token);
10821301
var request = new XMLHttpRequest();
10831302
request.open('POST', settings.url, true);
10841303
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
@@ -1120,6 +1339,8 @@
11201339
window.open(url, '_blank');
11211340
});
11221341

1342+
registerEvents();
1343+
11231344
}
11241345

11251346
return run();

0 commit comments

Comments
 (0)