1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
|
/**
* Functions used in the export tab
*
*/
var Export = {};
/**
* Disables the "Dump some row(s)" sub-options
*/
Export.disableDumpSomeRowsSubOptions = function () {
$('label[for=\'limit_to\']').fadeTo('fast', 0.4);
$('label[for=\'limit_from\']').fadeTo('fast', 0.4);
$('input[type=\'text\'][name=\'limit_to\']').prop('disabled', 'disabled');
$('input[type=\'text\'][name=\'limit_from\']').prop('disabled', 'disabled');
};
/**
* Enables the "Dump some row(s)" sub-options
*/
Export.enableDumpSomeRowsSubOptions = function () {
$('label[for=\'limit_to\']').fadeTo('fast', 1);
$('label[for=\'limit_from\']').fadeTo('fast', 1);
$('input[type=\'text\'][name=\'limit_to\']').prop('disabled', '');
$('input[type=\'text\'][name=\'limit_from\']').prop('disabled', '');
};
/**
* Return template data as a json object
*
* @return {object} template data
*/
Export.getTemplateData = function () {
var $form = $('form[name="dump"]');
var excludeList = ['token', 'server', 'db', 'table', 'single_table',
'export_type', 'export_method', 'sql_query', 'template_id'];
var obj = {};
var arr = $form.serializeArray();
$.each(arr, function () {
if ($.inArray(this.name, excludeList) < 0) {
if (obj[this.name] !== undefined) {
if (! obj[this.name].push) {
obj[this.name] = [obj[this.name]];
}
obj[this.name].push(this.value || '');
} else {
obj[this.name] = this.value || '';
}
}
});
// include unchecked checkboxes (which are ignored by serializeArray()) with null
// to uncheck them when loading the template
$form.find('input[type="checkbox"]:not(:checked)').each(function () {
if (obj[this.name] === undefined) {
obj[this.name] = null;
}
});
// include empty multiselects
$form.find('select').each(function () {
if ($(this).find('option:selected').length === 0) {
obj[this.name] = [];
}
});
return obj;
};
/**
* Create a template with selected options
*
* @param name name of the template
*/
Export.createTemplate = function (name) {
var templateData = Export.getTemplateData();
var params = {
'ajax_request': true,
'server': CommonParams.get('server'),
'db': CommonParams.get('db'),
'table': CommonParams.get('table'),
'exportType': $('input[name="export_type"]').val(),
'templateName': name,
'templateData': JSON.stringify(templateData)
};
Functions.ajaxShowMessage();
$.post('index.php?route=/export/template/create', params, function (response) {
if (response.success === true) {
$('#templateName').val('');
$('#template').html(response.data);
$('#template').find('option').each(function () {
if ($(this).text() === name) {
$(this).prop('selected', true);
}
});
Functions.ajaxShowMessage(Messages.strTemplateCreated);
} else {
Functions.ajaxShowMessage(response.error, false);
}
});
};
/**
* Loads a template
*
* @param id ID of the template to load
*/
Export.loadTemplate = function (id) {
var params = {
'ajax_request': true,
'server': CommonParams.get('server'),
'db': CommonParams.get('db'),
'table': CommonParams.get('table'),
'exportType': $('input[name="export_type"]').val(),
'templateId': id,
};
Functions.ajaxShowMessage();
$.post('index.php?route=/export/template/load', params, function (response) {
if (response.success === true) {
var $form = $('form[name="dump"]');
var options = JSON.parse(response.data);
$.each(options, function (key, value) {
var localValue = value;
var $element = $form.find('[name="' + key + '"]');
if ($element.length) {
if (($element.is('input') && $element.attr('type') === 'checkbox') && localValue === null) {
$element.prop('checked', false);
} else {
if (($element.is('input') && $element.attr('type') === 'checkbox') ||
($element.is('input') && $element.attr('type') === 'radio') ||
($element.is('select') && $element.attr('multiple') === 'multiple')) {
if (! localValue.push) {
localValue = [localValue];
}
}
$element.val(localValue);
}
$element.trigger('change');
}
});
$('input[name="template_id"]').val(id);
Functions.ajaxShowMessage(Messages.strTemplateLoaded);
} else {
Functions.ajaxShowMessage(response.error, false);
}
});
};
/**
* Updates an existing template with current options
*
* @param id ID of the template to update
*/
Export.updateTemplate = function (id) {
var templateData = Export.getTemplateData();
var params = {
'ajax_request': true,
'server': CommonParams.get('server'),
'db': CommonParams.get('db'),
'table': CommonParams.get('table'),
'exportType': $('input[name="export_type"]').val(),
'templateId': id,
'templateData': JSON.stringify(templateData)
};
Functions.ajaxShowMessage();
$.post('index.php?route=/export/template/update', params, function (response) {
if (response.success === true) {
Functions.ajaxShowMessage(Messages.strTemplateUpdated);
} else {
Functions.ajaxShowMessage(response.error, false);
}
});
};
/**
* Delete a template
*
* @param id ID of the template to delete
*/
Export.deleteTemplate = function (id) {
var params = {
'ajax_request': true,
'server': CommonParams.get('server'),
'db': CommonParams.get('db'),
'table': CommonParams.get('table'),
'exportType': $('input[name="export_type"]').val(),
'templateId': id,
};
Functions.ajaxShowMessage();
$.post('index.php?route=/export/template/delete', params, function (response) {
if (response.success === true) {
$('#template').find('option[value="' + id + '"]').remove();
Functions.ajaxShowMessage(Messages.strTemplateDeleted);
} else {
Functions.ajaxShowMessage(response.error, false);
}
});
};
/**
* Unbind all event handlers before tearing down a page
*/
AJAX.registerTeardown('export.js', function () {
$('#plugins').off('change');
$('input[type=\'radio\'][name=\'sql_structure_or_data\']').off('change');
$('input[type=\'radio\'][name$=\'_structure_or_data\']').off('change');
$('input[type=\'radio\'][name=\'output_format\']').off('change');
$('#checkbox_sql_include_comments').off('change');
$('input[type=\'radio\'][name=\'quick_or_custom\']').off('change');
$('input[type=\'radio\'][name=\'allrows\']').off('change');
$('#btn_alias_config').off('click');
$('.alias_remove').off('click');
$('#db_alias_button').off('click');
$('#table_alias_button').off('click');
$('#column_alias_button').off('click');
$('input[name="table_select[]"]').off('change');
$('input[name="table_structure[]"]').off('change');
$('input[name="table_data[]"]').off('change');
$('#table_structure_all').off('change');
$('#table_data_all').off('change');
$('input[name="createTemplate"]').off('click');
$('select[name="template"]').off('change');
$('input[name="updateTemplate"]').off('click');
$('input[name="deleteTemplate"]').off('click');
});
AJAX.registerOnload('export.js', function () {
$('#showsqlquery').on('click', function () {
// Creating a dialog box similar to preview sql container to show sql query
var modal = $('#showSqlQueryModal');
modal.modal('show');
modal.on('shown.bs.modal', function () {
$('#showSqlQueryModalLabel').first().html(Messages.strQuery);
Functions.highlightSql(modal);
});
});
/**
* Export template handling code
*/
// create a new template
$('input[name="createTemplate"]').on('click', function (e) {
e.preventDefault();
var name = $('input[name="templateName"]').val();
if (name.length) {
Export.createTemplate(name);
}
});
// load an existing template
$('select[name="template"]').on('change', function (e) {
e.preventDefault();
var id = $(this).val();
if (id.length) {
Export.loadTemplate(id);
}
});
// update an existing template with new criteria
$('input[name="updateTemplate"]').on('click', function (e) {
e.preventDefault();
var id = $('select[name="template"]').val();
if (id.length) {
Export.updateTemplate(id);
}
});
// delete an existing template
$('input[name="deleteTemplate"]').on('click', function (e) {
e.preventDefault();
var id = $('select[name="template"]').val();
if (id.length) {
Export.deleteTemplate(id);
}
});
/**
* Toggles the hiding and showing of each plugin's options
* according to the currently selected plugin from the dropdown list
*/
$('#plugins').on('change', function () {
$('#format_specific_opts').find('div.format_specific_options').addClass('d-none');
var selectedPluginName = $('#plugins').find('option:selected').val();
$('#' + selectedPluginName + '_options').removeClass('d-none');
});
/**
* Toggles the enabling and disabling of the SQL plugin's comment options that apply only when exporting structure
*/
$('input[type=\'radio\'][name=\'sql_structure_or_data\']').on('change', function () {
var commentsArePresent = $('#checkbox_sql_include_comments').prop('checked');
var show = $('input[type=\'radio\'][name=\'sql_structure_or_data\']:checked').val();
if (show === 'data') {
// disable the SQL comment options
if (commentsArePresent) {
$('#checkbox_sql_dates').prop('disabled', true).parent().fadeTo('fast', 0.4);
}
$('#checkbox_sql_relation').prop('disabled', true).parent().fadeTo('fast', 0.4);
$('#checkbox_sql_mime').prop('disabled', true).parent().fadeTo('fast', 0.4);
} else {
// enable the SQL comment options
if (commentsArePresent) {
$('#checkbox_sql_dates').prop('disabled', false).parent().fadeTo('fast', 1);
}
$('#checkbox_sql_relation').prop('disabled', false).parent().fadeTo('fast', 1);
$('#checkbox_sql_mime').prop('disabled', false).parent().fadeTo('fast', 1);
}
if (show === 'structure') {
$('#checkbox_sql_auto_increment').prop('disabled', true).parent().fadeTo('fast', 0.4);
} else {
$('#checkbox_sql_auto_increment').prop('disabled', false).parent().fadeTo('fast', 1);
}
});
// When MS Excel is selected as the Format automatically Switch to Character Set as windows-1252
$('#plugins').on('change', function () {
var selectedPluginName = $('#plugins').find('option:selected').val();
if (selectedPluginName === 'excel') {
$('#select_charset').val('windows-1252');
} else {
$('#select_charset').val('utf-8');
}
});
// For separate-file exports only ZIP compression is allowed
$('input[type="checkbox"][name="as_separate_files"]').on('change', function () {
if ($(this).is(':checked')) {
$('#compression').val('zip');
}
});
$('#compression').on('change', function () {
if ($('option:selected').val() !== 'zip') {
$('input[type="checkbox"][name="as_separate_files"]').prop('checked', false);
}
});
});
Export.setupTableStructureOrData = function () {
if ($('input[name=\'export_type\']').val() !== 'database') {
return;
}
var pluginName = $('#plugins').find('option:selected').val();
var formElemName = pluginName + '_structure_or_data';
var forceStructureOrData = !($('input[name=\'' + formElemName + '_default\']').length);
if (forceStructureOrData === true) {
$('input[name="structure_or_data_forced"]').val(1);
$('.export_structure input[type="checkbox"], .export_data input[type="checkbox"]')
.prop('disabled', true);
$('.export_structure, .export_data').fadeTo('fast', 0.4);
} else {
$('input[name="structure_or_data_forced"]').val(0);
$('.export_structure input[type="checkbox"], .export_data input[type="checkbox"]')
.prop('disabled', false);
$('.export_structure, .export_data').fadeTo('fast', 1);
var structureOrData = $('input[name="' + formElemName + '_default"]').val();
if (structureOrData === 'structure') {
$('.export_data input[type="checkbox"]')
.prop('checked', false);
} else if (structureOrData === 'data') {
$('.export_structure input[type="checkbox"]')
.prop('checked', false);
}
if (structureOrData === 'structure' || structureOrData === 'structure_and_data') {
if (!$('.export_structure input[type="checkbox"]:checked').length) {
$('input[name="table_select[]"]:checked')
.closest('tr')
.find('.export_structure input[type="checkbox"]')
.prop('checked', true);
}
}
if (structureOrData === 'data' || structureOrData === 'structure_and_data') {
if (!$('.export_data input[type="checkbox"]:checked').length) {
$('input[name="table_select[]"]:checked')
.closest('tr')
.find('.export_data input[type="checkbox"]')
.prop('checked', true);
}
}
Export.checkSelectedTables();
Export.checkTableSelectAll();
Export.checkTableSelectStructureOrData();
}
};
/**
* Toggles the hiding and showing of plugin structure-specific and data-specific
* options
*/
Export.toggleStructureDataOpts = function () {
var pluginName = $('select#plugins').val();
var radioFormName = pluginName + '_structure_or_data';
var dataDiv = '#' + pluginName + '_data';
var structureDiv = '#' + pluginName + '_structure';
var show = $('input[type=\'radio\'][name=\'' + radioFormName + '\']:checked').val();
// Show the #rows if 'show' is not structure
$('#rows').toggle(show !== 'structure');
if (show === 'data') {
$(dataDiv).slideDown('slow');
$(structureDiv).slideUp('slow');
} else {
$(structureDiv).slideDown('slow');
if (show === 'structure') {
$(dataDiv).slideUp('slow');
} else {
$(dataDiv).slideDown('slow');
}
}
};
/**
* Toggles the disabling of the "save to file" options
*/
Export.toggleSaveToFile = function () {
var $ulSaveAsfile = $('#ul_save_asfile');
if (!$('#radio_dump_asfile').prop('checked')) {
$ulSaveAsfile.find('> li').fadeTo('fast', 0.4);
$ulSaveAsfile.find('> li > input').prop('disabled', true);
$ulSaveAsfile.find('> li > select').prop('disabled', true);
} else {
$ulSaveAsfile.find('> li').fadeTo('fast', 1);
$ulSaveAsfile.find('> li > input').prop('disabled', false);
$ulSaveAsfile.find('> li > select').prop('disabled', false);
}
};
AJAX.registerOnload('export.js', function () {
Export.toggleSaveToFile();
$('input[type=\'radio\'][name=\'output_format\']').on('change', Export.toggleSaveToFile);
});
/**
* For SQL plugin, toggles the disabling of the "display comments" options
*/
Export.toggleSqlIncludeComments = function () {
$('#checkbox_sql_include_comments').on('change', function () {
var $ulIncludeComments = $('#ul_include_comments');
if (!$('#checkbox_sql_include_comments').prop('checked')) {
$ulIncludeComments.find('> li').fadeTo('fast', 0.4);
$ulIncludeComments.find('> li > input').prop('disabled', true);
} else {
// If structure is not being exported, the comment options for structure should not be enabled
if ($('#radio_sql_structure_or_data_data').prop('checked')) {
$('#text_sql_header_comment').prop('disabled', false).parent('li').fadeTo('fast', 1);
} else {
$ulIncludeComments.find('> li').fadeTo('fast', 1);
$ulIncludeComments.find('> li > input').prop('disabled', false);
}
}
});
};
Export.checkTableSelectAll = function () {
var total = $('input[name="table_select[]"]').length;
var strChecked = $('input[name="table_structure[]"]:checked').length;
var dataChecked = $('input[name="table_data[]"]:checked').length;
var strAll = $('#table_structure_all');
var dataAll = $('#table_data_all');
if (strChecked === total) {
strAll
.prop('indeterminate', false)
.prop('checked', true);
} else if (strChecked === 0) {
strAll
.prop('indeterminate', false)
.prop('checked', false);
} else {
strAll
.prop('indeterminate', true)
.prop('checked', false);
}
if (dataChecked === total) {
dataAll
.prop('indeterminate', false)
.prop('checked', true);
} else if (dataChecked === 0) {
dataAll
.prop('indeterminate', false)
.prop('checked', false);
} else {
dataAll
.prop('indeterminate', true)
.prop('checked', false);
}
};
Export.checkTableSelectStructureOrData = function () {
var dataChecked = $('input[name="table_data[]"]:checked').length;
var autoIncrement = $('#checkbox_sql_auto_increment');
var pluginName = $('select#plugins').val();
var dataDiv = '#' + pluginName + '_data';
if (dataChecked === 0) {
$(dataDiv).slideUp('slow');
autoIncrement.prop('disabled', true).parent().fadeTo('fast', 0.4);
} else {
$(dataDiv).slideDown('slow');
autoIncrement.prop('disabled', false).parent().fadeTo('fast', 1);
}
};
Export.toggleTableSelectAllStr = function () {
var strAll = $('#table_structure_all').is(':checked');
if (strAll) {
$('input[name="table_structure[]"]').prop('checked', true);
} else {
$('input[name="table_structure[]"]').prop('checked', false);
}
};
Export.toggleTableSelectAllData = function () {
var dataAll = $('#table_data_all').is(':checked');
if (dataAll) {
$('input[name="table_data[]"]').prop('checked', true);
} else {
$('input[name="table_data[]"]').prop('checked', false);
}
};
Export.checkSelectedTables = function () {
$('.export_table_select tbody tr').each(function () {
Export.checkTableSelected(this);
});
};
Export.checkTableSelected = function (row) {
var $row = $(row);
var tableSelect = $row.find('input[name="table_select[]"]');
var strCheck = $row.find('input[name="table_structure[]"]');
var dataCheck = $row.find('input[name="table_data[]"]');
var data = dataCheck.is(':checked:not(:disabled)');
var structure = strCheck.is(':checked:not(:disabled)');
if (data && structure) {
tableSelect.prop({ checked: true, indeterminate: false });
$row.addClass('marked');
} else if (data || structure) {
tableSelect.prop({ checked: true, indeterminate: true });
$row.removeClass('marked');
} else {
tableSelect.prop({ checked: false, indeterminate: false });
$row.removeClass('marked');
}
};
Export.toggleTableSelect = function (row) {
var $row = $(row);
var tableSelected = $row.find('input[name="table_select[]"]').is(':checked');
if (tableSelected) {
$row.find('input[type="checkbox"]:not(:disabled)').prop('checked', true);
$row.addClass('marked');
} else {
$row.find('input[type="checkbox"]:not(:disabled)').prop('checked', false);
$row.removeClass('marked');
}
};
Export.handleAddProcCheckbox = function () {
if ($('#table_structure_all').is(':checked') === true
&& $('#table_data_all').is(':checked') === true
) {
$('#checkbox_sql_procedure_function').prop('checked', true);
} else {
$('#checkbox_sql_procedure_function').prop('checked', false);
}
};
AJAX.registerOnload('export.js', function () {
/**
* For SQL plugin, if "CREATE TABLE options" is checked/unchecked, check/uncheck each of its sub-options
*/
var $create = $('#checkbox_sql_create_table_statements');
var $createOptions = $('#ul_create_table_statements').find('input');
$create.on('change', function () {
$createOptions.prop('checked', $(this).prop('checked'));
});
$createOptions.on('change', function () {
if ($createOptions.is(':checked')) {
$create.prop('checked', true);
}
});
/**
* Disables the view output as text option if the output must be saved as a file
*/
$('#plugins').on('change', function () {
var activePlugin = $('#plugins').find('option:selected').val();
var forceFile = $('#force_file_' + activePlugin).val();
if (forceFile === 'true') {
if ($('#radio_dump_asfile').prop('checked') !== true) {
$('#radio_dump_asfile').prop('checked', true);
Export.toggleSaveToFile();
}
$('#radio_view_as_text').prop('disabled', true).parent().fadeTo('fast', 0.4);
} else {
$('#radio_view_as_text').prop('disabled', false).parent().fadeTo('fast', 1);
}
});
$('input[type=\'radio\'][name$=\'_structure_or_data\']').on('change', function () {
Export.toggleStructureDataOpts();
});
$('input[name="table_select[]"]').on('change', function () {
Export.toggleTableSelect($(this).closest('tr'));
Export.checkTableSelectAll();
Export.handleAddProcCheckbox();
Export.checkTableSelectStructureOrData();
});
$('input[name="table_structure[]"]').on('change', function () {
Export.checkTableSelected($(this).closest('tr'));
Export.checkTableSelectAll();
Export.handleAddProcCheckbox();
Export.checkTableSelectStructureOrData();
});
$('input[name="table_data[]"]').on('change', function () {
Export.checkTableSelected($(this).closest('tr'));
Export.checkTableSelectAll();
Export.handleAddProcCheckbox();
Export.checkTableSelectStructureOrData();
});
$('#table_structure_all').on('change', function () {
Export.toggleTableSelectAllStr();
Export.checkSelectedTables();
Export.handleAddProcCheckbox();
Export.checkTableSelectStructureOrData();
});
$('#table_data_all').on('change', function () {
Export.toggleTableSelectAllData();
Export.checkSelectedTables();
Export.handleAddProcCheckbox();
Export.checkTableSelectStructureOrData();
});
if ($('input[name=\'export_type\']').val() === 'database') {
// Hide structure or data radio buttons
$('input[type=\'radio\'][name$=\'_structure_or_data\']').each(function () {
var $this = $(this);
var name = $this.prop('name');
var val = $('input[name="' + name + '"]:checked').val();
var nameDefault = name + '_default';
if (!$('input[name="' + nameDefault + '"]').length) {
$this
.after(
$('<input type="hidden" name="' + nameDefault + '" value="' + val + '" disabled>')
)
.after(
$('<input type="hidden" name="' + name + '" value="structure_and_data">')
);
$this.parent().find('label').remove();
} else {
$this.parent().remove();
}
});
$('input[type=\'radio\'][name$=\'_structure_or_data\']').remove();
// Disable CREATE table checkbox for sql
var createTableCheckbox = $('#checkbox_sql_create_table');
createTableCheckbox.prop('checked', true);
var dummyCreateTable = $('#checkbox_sql_create_table')
.clone()
.removeAttr('id')
.attr('type', 'hidden');
createTableCheckbox
.prop('disabled', true)
.after(dummyCreateTable)
.parent()
.fadeTo('fast', 0.4);
Export.setupTableStructureOrData();
}
/**
* Handle force structure_or_data
*/
$('#plugins').on('change', Export.setupTableStructureOrData);
});
/**
* Toggles display of options when quick and custom export are selected
*/
Export.toggleQuickOrCustom = function () {
if ($('input[name=\'quick_or_custom\']').length === 0 // custom_no_form option
|| $('#radio_custom_export').prop('checked') // custom
) {
$('#databases_and_tables').show();
$('#rows').show();
$('#output').show();
$('#format_specific_opts').show();
$('#output_quick_export').addClass('d-none');
var selectedPluginName = $('#plugins').find('option:selected').val();
$('#' + selectedPluginName + '_options').removeClass('d-none');
} else { // quick
$('#databases_and_tables').hide();
$('#rows').hide();
$('#output').hide();
$('#format_specific_opts').hide();
$('#output_quick_export').removeClass('d-none');
}
};
var timeOut;
Export.checkTimeOut = function (timeLimit) {
var limit = timeLimit;
if (typeof limit === 'undefined' || limit === 0) {
return true;
}
// margin of one second to avoid race condition to set/access session variable
limit = limit + 1;
clearTimeout(timeOut);
timeOut = setTimeout(function () {
$.get('index.php?route=/export/check-time-out',
{
'ajax_request': true,
'server': CommonParams.get('server')
},
function (data) {
if (data.message === 'timeout') {
Functions.ajaxShowMessage(
'<div class="alert alert-danger" role="alert">' +
Messages.strTimeOutError +
'</div>',
false
);
}
}
);
}, limit * 1000);
};
/**
* Handler for Alias dialog box
*
* @param event object the event object
*
* @return {void}
*/
Export.createAliasModal = function (event) {
event.preventDefault();
var modal = $('#renameExportModal');
modal.modal('show');
modal.on('shown.bs.modal', function () {
modal.closest('.ui-dialog').find('.ui-button').addClass('btn btn-secondary');
var db = CommonParams.get('db');
if (db) {
var option = $('<option></option>');
option.text(db);
option.attr('value', db);
$('#db_alias_select').append(option).val(db).trigger('change');
} else {
var params = {
'ajax_request': true,
'server': CommonParams.get('server')
};
$.post('index.php?route=/databases', params, function (response) {
if (response.success === true) {
$.each(response.databases, function (idx, value) {
var option = $('<option></option>');
option.text(value);
option.attr('value', value);
$('#db_alias_select').append(option);
});
} else {
Functions.ajaxShowMessage(response.error, false);
}
});
}
});
modal.on('hidden.bs.modal', function () {
var isEmpty = true;
$(this).find('input[type="text"]').each(function () {
// trim empty input fields on close
if ($(this).val()) {
isEmpty = false;
} else {
$(this).parents('tr').remove();
}
});
// Toggle checkbox based on aliases
$('input#btn_alias_config').prop('checked', !isEmpty);
});
$('#saveAndCloseBtn').on('click', function () {
$('#alias_modal').parent().appendTo($('form[name="dump"]'));
});
};
Export.aliasToggleRow = function (elm) {
var inputs = elm.parents('tr').find('input,button');
if (elm.val()) {
inputs.attr('disabled', false);
} else {
inputs.attr('disabled', true);
}
};
Export.aliasRow = null;
Export.addAlias = function (type, name, field, value) {
if (value === '') {
return;
}
if (Export.aliasRow === null) {
Export.aliasRow = $('#alias_data tfoot tr');
}
var row = Export.aliasRow.clone();
row.find('th').text(type);
row.find('td').first().text(name);
row.find('input').attr('name', field);
row.find('input').val(value);
row.find('.alias_remove').on('click', function () {
$(this).parents('tr').remove();
});
var matching = $('#alias_data [name="' + $.escapeSelector(field) + '"]');
if (matching.length > 0) {
matching.parents('tr').remove();
}
$('#alias_data tbody').append(row);
};
AJAX.registerOnload('export.js', function () {
$('input[type=\'radio\'][name=\'quick_or_custom\']').on('change', Export.toggleQuickOrCustom);
$('#format_specific_opts').find('div.format_specific_options')
.addClass('d-none')
.find('h3')
.remove();
Export.toggleQuickOrCustom();
Export.toggleStructureDataOpts();
Export.toggleSqlIncludeComments();
Export.checkTableSelectAll();
Export.handleAddProcCheckbox();
/**
* Initially disables the "Dump some row(s)" sub-options
*/
Export.disableDumpSomeRowsSubOptions();
/**
* Disables the "Dump some row(s)" sub-options when it is not selected
*/
$('input[type=\'radio\'][name=\'allrows\']').on('change', function () {
if ($('#radio_allrows_0').prop('checked')) {
Export.enableDumpSomeRowsSubOptions();
} else {
Export.disableDumpSomeRowsSubOptions();
}
});
// Open Alias Modal Dialog on click
$('#btn_alias_config').on('click', Export.createAliasModal);
$('.alias_remove').on('click', function () {
$(this).parents('tr').remove();
});
$('#db_alias_select').on('change', function () {
Export.aliasToggleRow($(this));
var table = CommonParams.get('table');
if (table) {
var option = $('<option></option>');
option.text(table);
option.attr('value', table);
$('#table_alias_select').append(option).val(table).trigger('change');
} else {
var database = $(this).val();
var params = {
'ajax_request': true,
'server': CommonParams.get('server'),
'db': database,
};
var url = 'index.php?route=/tables';
$.post(url, params, function (response) {
if (response.success === true) {
$.each(response.tables, function (idx, value) {
var option = $('<option></option>');
option.text(value);
option.attr('value', value);
$('#table_alias_select').append(option);
});
} else {
Functions.ajaxShowMessage(response.error, false);
}
});
}
});
$('#table_alias_select').on('change', function () {
Export.aliasToggleRow($(this));
var database = $('#db_alias_select').val();
var table = $(this).val();
var params = {
'ajax_request': true,
'server': CommonParams.get('server'),
'db': database,
'table': table,
};
var url = 'index.php?route=/columns';
$.post(url, params, function (response) {
if (response.success === true) {
$.each(response.columns, function (idx, value) {
var option = $('<option></option>');
option.text(value);
option.attr('value', value);
$('#column_alias_select').append(option);
});
} else {
Functions.ajaxShowMessage(response.error, false);
}
});
});
$('#column_alias_select').on('change', function () {
Export.aliasToggleRow($(this));
});
$('#db_alias_button').on('click', function (e) {
e.preventDefault();
var db = $('#db_alias_select').val();
Export.addAlias(
Messages.strAliasDatabase,
db,
'aliases[' + db + '][alias]',
$('#db_alias_name').val()
);
$('#db_alias_name').val('');
});
$('#table_alias_button').on('click', function (e) {
e.preventDefault();
var db = $('#db_alias_select').val();
var table = $('#table_alias_select').val();
Export.addAlias(
Messages.strAliasTable,
db + '.' + table,
'aliases[' + db + '][tables][' + table + '][alias]',
$('#table_alias_name').val()
);
$('#table_alias_name').val('');
});
$('#column_alias_button').on('click', function (e) {
e.preventDefault();
var db = $('#db_alias_select').val();
var table = $('#table_alias_select').val();
var column = $('#column_alias_select').val();
Export.addAlias(
Messages.strAliasColumn,
db + '.' + table + '.' + column,
'aliases[' + db + '][tables][' + table + '][colums][' + column + ']',
$('#column_alias_name').val()
);
$('#column_alias_name').val('');
});
var setSelectOptions = function (doCheck) {
Functions.setSelectOptions('dump', 'db_select[]', doCheck);
};
$('#db_select_all').on('click', function (e) {
e.preventDefault();
setSelectOptions(true);
});
$('#db_unselect_all').on('click', function (e) {
e.preventDefault();
setSelectOptions(false);
});
$('#buttonGo').on('click', function () {
var timeLimit = parseInt($(this).attr('data-exec-time-limit'));
// If the time limit set is zero,
// then time out won't occur so no need to check for time out.
if (timeLimit > 0) {
Export.checkTimeOut(timeLimit);
}
});
});
|