|
259 | 259 | function validateSelectDuplicate(elementId){
|
260 | 260 | var element = $(elementId);
|
261 | 261 | if(element.length < 0){
|
262 |
| - return true; |
| 262 | + return false; |
263 | 263 | }
|
264 | 264 | var check = new Array();
|
265 | 265 | $('select', element).each(function(index, value) {
|
266 | 266 | var elm_val = $(value).val();
|
267 |
| - if(elm_val){ |
| 267 | + var elm_opt = $(value).find(':selected'); |
| 268 | + var duplicate = elm_opt.data('duplicate'); |
| 269 | + if(duplicate == undefined || !duplicate){ |
| 270 | + duplicate = 0; |
| 271 | + } |
| 272 | + if(elm_val && duplicate == 0){ |
268 | 273 | check[index] = elm_val;
|
269 | 274 | }
|
270 | 275 | });
|
|
283 | 288 | return result;
|
284 | 289 | }
|
285 | 290 |
|
| 291 | + function validateSelectsDuplicate(elementClass){ |
| 292 | + var elements = $(elementClass); |
| 293 | + if(elements.length < 0){ |
| 294 | + return false; |
| 295 | + } |
| 296 | + var resultAll = false; |
| 297 | + elements.each(function(i, v){ |
| 298 | + var element = $(v); |
| 299 | + var check = new Array(); |
| 300 | + $('select', element).each(function(index, value) { |
| 301 | + var elm_val = $(value).val(); |
| 302 | + var elm_opt = $(value).find(':selected'); |
| 303 | + var duplicate = elm_opt.data('duplicate'); |
| 304 | + if(duplicate == undefined || !duplicate){ |
| 305 | + duplicate = 0; |
| 306 | + } |
| 307 | + if(elm_val && duplicate == 0){ |
| 308 | + check[index] = elm_val; |
| 309 | + } |
| 310 | + }); |
| 311 | + var result = false; |
| 312 | + check.forEach(function(value, index) { |
| 313 | + check.forEach(function(value_tmp, index_tmp) { |
| 314 | + if (value_tmp === value && index !== index_tmp) { |
| 315 | + result = true; |
| 316 | + } |
| 317 | + }); |
| 318 | + }); |
| 319 | + if(result){ |
| 320 | + $('.message-valid', element).html('Mapping value can\'t not be the same. Please change!').show(); |
| 321 | + scrollToErrorMessage(element); |
| 322 | + resultAll = true; |
| 323 | + } |
| 324 | + }); |
| 325 | + return resultAll; |
| 326 | + } |
| 327 | + |
| 328 | + function validateCustomFieldMapType(){ |
| 329 | + var elements = $('.cf-section-entity-map', container); |
| 330 | + if(elements.length < 0){ |
| 331 | + return false; |
| 332 | + } |
| 333 | + var resultAll = false; |
| 334 | + elements.each(function(i, v){ |
| 335 | + var element = $(v); |
| 336 | + var result = false; |
| 337 | + $('.form-group', element).each(function(i1, v1){ |
| 338 | + var group = $(v1); |
| 339 | + var sf = group.find('.cf_source'); |
| 340 | + var tf = group.find('.cf_target'); |
| 341 | + if(!sf.length || !tf.length){ |
| 342 | + return true; |
| 343 | + } |
| 344 | + var sfo = sf.find(':selected'); |
| 345 | + var tfo = tf.find(':selected'); |
| 346 | + var st = sfo.data('columnType'); |
| 347 | + var tt = tfo.data('columnType'); |
| 348 | + var sdt = sfo.data('detailType'); |
| 349 | + var tdt = tfo.data('detailType'); |
| 350 | + var check = (sdt == tdt); |
| 351 | + if(check){ |
| 352 | + if(!st || !tt || st == tt){ |
| 353 | + return true; |
| 354 | + } |
| 355 | + } |
| 356 | + check = isDbTypeMapRight(st, tt); |
| 357 | + if(!check){ |
| 358 | + $('.message-item-valid', group).html('Mapping type must be the similar. Please change!').show(); |
| 359 | + result = true; |
| 360 | + return false; |
| 361 | + } |
| 362 | + }); |
| 363 | + if(result){ |
| 364 | + scrollToElement(element); |
| 365 | + resultAll = true; |
| 366 | + } |
| 367 | + }); |
| 368 | + return resultAll; |
| 369 | + } |
| 370 | + |
| 371 | + function isDbTypeMapRight(source_type, target_type){ |
| 372 | + if(source_type == target_type){ |
| 373 | + return true; |
| 374 | + } |
| 375 | + var supports = { |
| 376 | + 'int': ['tinyint', 'smallint', 'mediumint'], |
| 377 | + 'bigint': ['int', 'tinyint', 'smallint', 'mediumint'], |
| 378 | + 'double': ['float'], |
| 379 | + 'decimal': ['double', 'float'], |
| 380 | + 'datetime': ['date'], |
| 381 | + 'varchar': ['int', 'tinyint', 'smallint', 'mediumint', 'bigint', 'double', 'float', 'decimal', 'date', 'datetime', 'timestamp', 'time', 'year', 'char'], |
| 382 | + 'mediumtext': ['int', 'tinyint', 'smallint', 'mediumint', 'bigint', 'double', 'float', 'decimal', 'date', 'datetime', 'timestamp', 'time', 'year', 'char', 'varchar', 'tinytext'], |
| 383 | + 'text': ['int', 'tinyint', 'smallint', 'mediumint', 'bigint', 'double', 'float', 'decimal', 'date', 'datetime', 'timestamp', 'time', 'year', 'char', 'varchar', 'tinytext', 'mediumtext'], |
| 384 | + 'longtext': ['int', 'tinyint', 'smallint', 'mediumint', 'bigint', 'double', 'float', 'decimal', 'date', 'datetime', 'timestamp', 'time', 'year', 'char', 'varchar', 'tinytext', 'mediumtext', 'text'], |
| 385 | + 'mediumblob': ['int', 'tinyint', 'smallint', 'mediumint', 'bigint', 'double', 'float', 'decimal', 'date', 'datetime', 'timestamp', 'time', 'year', 'char', 'varchar', 'tinytext', 'mediumtext', 'text', 'tinyblob'], |
| 386 | + 'blob': ['int', 'tinyint', 'smallint', 'mediumint', 'bigint', 'double', 'float', 'decimal', 'date', 'datetime', 'timestamp', 'time', 'year', 'char', 'varchar', 'tinytext', 'mediumtext', 'text', 'tinyblob', 'mediumblob'], |
| 387 | + 'longblob': ['int', 'tinyint', 'smallint', 'mediumint', 'bigint', 'double', 'float', 'decimal', 'date', 'datetime', 'timestamp', 'time', 'year', 'char', 'varchar', 'tinytext', 'mediumtext', 'text', 'tinyblob', 'mediumblob', 'blob'] |
| 388 | + }; |
| 389 | + if(supports[target_type] == undefined){ |
| 390 | + return false; |
| 391 | + } |
| 392 | + var support = supports[target_type]; |
| 393 | + return (support.indexOf(source_type) != -1); |
| 394 | + } |
| 395 | + |
286 | 396 | function validateCheckRequired(elementId){
|
287 | 397 | var element = $(elementId);
|
288 | 398 | if(element.length < 0){
|
|
298 | 408 |
|
299 | 409 | function resetValidate(elementId){
|
300 | 410 | $('.message-valid', elementId).hide();
|
| 411 | + $('.message-item-valid', elementId).hide(); |
301 | 412 | }
|
302 | 413 |
|
303 | 414 | function scrollToErrorMessage(element){
|
| 415 | + if(element.length < 1){ |
| 416 | + return false; |
| 417 | + } |
304 | 418 | $(window).scrollTop( $('.message-valid', element).offset().top - $(window).height() + 50);
|
305 | 419 | }
|
306 | 420 |
|
| 421 | + function scrollToElement(element){ |
| 422 | + $(window).scrollTop(element.offset().top + 50); |
| 423 | + } |
| 424 | + |
307 | 425 | function createCookie(value) {
|
308 | 426 | var date = new Date();
|
309 | 427 | date.setTime(date.getTime() + (24 * 60 * 60 * 1000));
|
|
416 | 534 | if(result.next_type){
|
417 | 535 | processBarAnimate(result.next_type, false);
|
418 | 536 | }
|
419 |
| - importEntity(result.next_type); |
| 537 | + delayImportEntity(result.next_type); |
420 | 538 | } else if(response.status == 'process'){
|
421 | 539 | var result = response.data;
|
422 | 540 | processBarResult(result.type, result.total, result.import, result.error, result.point);
|
423 | 541 | processBarAnimate(result.type, false);
|
424 |
| - importEntity(result.type); |
| 542 | + delayImportEntity(result.type); |
425 | 543 | } else {
|
426 | 544 | processRetry(type);
|
427 | 545 | }
|
|
431 | 549 | });
|
432 | 550 | }
|
433 | 551 |
|
| 552 | + function delayImportEntity(type){ |
| 553 | + importEntity(type); |
| 554 | + /*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 | + }*/ |
| 563 | + } |
| 564 | + |
434 | 565 | function processBarResult(entity, total, imported, error, point)
|
435 | 566 | {
|
436 | 567 | var id = '#import-wrap #' + entity + '-process';
|
|
510 | 641 | return result;
|
511 | 642 | }
|
512 | 643 |
|
| 644 | + function styleTable(element){ |
| 645 | + var i = 0; |
| 646 | + $('.form-group', element).each(function(i, v){ |
| 647 | + $(v).removeClass('even').removeClass('odd'); |
| 648 | + var style_class = ''; |
| 649 | + if(i%2){ |
| 650 | + style_class = 'odd'; |
| 651 | + } else { |
| 652 | + style_class = 'even'; |
| 653 | + } |
| 654 | + $(v).addClass(style_class); |
| 655 | + i++; |
| 656 | + }); |
| 657 | + } |
| 658 | + |
513 | 659 | function run(){
|
514 | 660 |
|
515 | 661 | deleteCookie();
|
|
761 | 907 | if(!validateSelectRequired('#website-section')
|
762 | 908 | || !validateSelectRequired('#language-section')
|
763 | 909 | || validateSelectDuplicate('#language-section')
|
764 |
| - || !validateCheckRequired('#entity-section')){ |
| 910 | + || !validateCheckRequired('#entity-section') |
| 911 | + || validateSelectsDuplicate('.cf-section-entity-map') |
| 912 | + || validateCustomFieldMapType()){ |
765 | 913 | hideLoading();
|
766 | 914 | return false;
|
767 | 915 | }
|
|
783 | 931 | });
|
784 | 932 | });
|
785 | 933 |
|
| 934 | + $(container).on('click', '#cf-section .cf-add-field', function(){ |
| 935 | + var _this = $(this); |
| 936 | + var cf_section = _this.closest('.cf-section-entity'); |
| 937 | + var clone = $('.cf-clone', cf_section); |
| 938 | + var content_table = $('.mapping-table', cf_section); |
| 939 | + var html = $(clone.html()); |
| 940 | + var index = cf_section.data('fieldIndex'); |
| 941 | + var entity = cf_section.data('entity'); |
| 942 | + html.find('.cf_source').attr('name', 'cf_source_' + entity + '[' + index + ']'); |
| 943 | + html.find('.cf_target').attr('name', 'cf_target_' + entity + '[' + index + ']'); |
| 944 | + content_table.append(html); |
| 945 | + index = index + 1; |
| 946 | + cf_section.data('fieldIndex', index); |
| 947 | + styleTable(content_table); |
| 948 | + $('select', html).select2({width: '100%'}); |
| 949 | + }); |
| 950 | + |
| 951 | + $(container).on('click', '#cf-section .remove-field', function(){ |
| 952 | + var _this = $(this); |
| 953 | + var form = _this.closest('.form-group'); |
| 954 | + var cf_section = _this.closest('.cf-section-entity'); |
| 955 | + form.remove(); |
| 956 | + var content_table = $('.mapping-table', cf_section); |
| 957 | + styleTable(content_table); |
| 958 | + }); |
| 959 | + |
| 960 | + $(container).on('change', '#seo-plugin-select', function(){ |
| 961 | + var _this = $(this); |
| 962 | + var seo_value = _this.val(); |
| 963 | + if(!seo_value){ |
| 964 | + return false; |
| 965 | + } |
| 966 | + var seoPlugin = seo_value.split('|##|'); |
| 967 | + $(container).find('.seo-config-section').css({display: 'none'}); |
| 968 | + seoPlugin.forEach(function(v, i){ |
| 969 | + $(container).find('#' + v).css({display: 'block'}); |
| 970 | + }); |
| 971 | + }); |
| 972 | + |
786 | 973 | $(container).on('click', '.toggle-element', function(){
|
787 | 974 | var _this = $(this);
|
788 | 975 | var check = _this.is(':checked');
|
|
0 commit comments