2 * Functions used in the export tab
9 * Disables the "Dump some row(s)" sub-options
11 Export.disableDumpSomeRowsSubOptions = function () {
12 $('label[for=\'limit_to\']').fadeTo('fast', 0.4);
13 $('label[for=\'limit_from\']').fadeTo('fast', 0.4);
14 $('input[type=\'text\'][name=\'limit_to\']').prop('disabled', 'disabled');
15 $('input[type=\'text\'][name=\'limit_from\']').prop('disabled', 'disabled');
19 * Enables the "Dump some row(s)" sub-options
21 Export.enableDumpSomeRowsSubOptions = function () {
22 $('label[for=\'limit_to\']').fadeTo('fast', 1);
23 $('label[for=\'limit_from\']').fadeTo('fast', 1);
24 $('input[type=\'text\'][name=\'limit_to\']').prop('disabled', '');
25 $('input[type=\'text\'][name=\'limit_from\']').prop('disabled', '');
29 * Return template data as a json object
31 * @returns template data
33 Export.getTemplateData = function () {
34 var $form = $('form[name="dump"]');
35 var blacklist = ['token', 'server', 'db', 'table', 'single_table',
36 'export_type', 'export_method', 'sql_query', 'template_id'];
38 var arr = $form.serializeArray();
39 $.each(arr, function () {
40 if ($.inArray(this.name, blacklist) < 0) {
41 if (obj[this.name] !== undefined) {
42 if (! obj[this.name].push) {
43 obj[this.name] = [obj[this.name]];
45 obj[this.name].push(this.value || '');
47 obj[this.name] = this.value || '';
51 // include unchecked checboxes (which are ignored by serializeArray()) with null
52 // to uncheck them when loading the template
53 $form.find('input[type="checkbox"]:not(:checked)').each(function () {
54 if (obj[this.name] === undefined) {
55 obj[this.name] = null;
58 // include empty multiselects
59 $form.find('select').each(function () {
60 if ($(this).find('option:selected').length === 0) {
68 * Create a template with selected options
70 * @param name name of the template
72 Export.createTemplate = function (name) {
73 var templateData = Export.getTemplateData();
77 'server': CommonParams.get('server'),
78 'db': CommonParams.get('db'),
79 'table': CommonParams.get('table'),
80 'exportType': $('input[name="export_type"]').val(),
81 'templateAction': 'create',
83 'templateData': JSON.stringify(templateData)
86 Functions.ajaxShowMessage();
87 $.post('index.php?route=/table/export', params, function (response) {
88 if (response.success === true) {
89 $('#templateName').val('');
90 $('#template').html(response.data);
91 $('#template').find('option').each(function () {
92 if ($(this).text() === name) {
93 $(this).prop('selected', true);
96 Functions.ajaxShowMessage(Messages.strTemplateCreated);
98 Functions.ajaxShowMessage(response.error, false);
106 * @param id ID of the template to load
108 Export.loadTemplate = function (id) {
110 'ajax_request': true,
111 'server': CommonParams.get('server'),
112 'db': CommonParams.get('db'),
113 'table': CommonParams.get('table'),
114 'exportType': $('input[name="export_type"]').val(),
115 'templateAction': 'load',
119 Functions.ajaxShowMessage();
120 $.post('index.php?route=/table/export', params, function (response) {
121 if (response.success === true) {
122 var $form = $('form[name="dump"]');
123 var options = JSON.parse(response.data);
124 $.each(options, function (key, value) {
125 var localValue = value;
126 var $element = $form.find('[name="' + key + '"]');
127 if ($element.length) {
128 if (($element.is('input') && $element.attr('type') === 'checkbox') && localValue === null) {
129 $element.prop('checked', false);
131 if (($element.is('input') && $element.attr('type') === 'checkbox') ||
132 ($element.is('input') && $element.attr('type') === 'radio') ||
133 ($element.is('select') && $element.attr('multiple') === 'multiple')) {
134 if (! localValue.push) {
135 localValue = [localValue];
138 $element.val(localValue);
140 $element.trigger('change');
143 $('input[name="template_id"]').val(id);
144 Functions.ajaxShowMessage(Messages.strTemplateLoaded);
146 Functions.ajaxShowMessage(response.error, false);
152 * Updates an existing template with current options
154 * @param id ID of the template to update
156 Export.updateTemplate = function (id) {
157 var templateData = Export.getTemplateData();
160 'ajax_request': true,
161 'server': CommonParams.get('server'),
162 'db': CommonParams.get('db'),
163 'table': CommonParams.get('table'),
164 'exportType': $('input[name="export_type"]').val(),
165 'templateAction': 'update',
167 'templateData': JSON.stringify(templateData)
170 Functions.ajaxShowMessage();
171 $.post('index.php?route=/table/export', params, function (response) {
172 if (response.success === true) {
173 Functions.ajaxShowMessage(Messages.strTemplateUpdated);
175 Functions.ajaxShowMessage(response.error, false);
183 * @param id ID of the template to delete
185 Export.deleteTemplate = function (id) {
187 'ajax_request': true,
188 'server': CommonParams.get('server'),
189 'db': CommonParams.get('db'),
190 'table': CommonParams.get('table'),
191 'exportType': $('input[name="export_type"]').val(),
192 'templateAction': 'delete',
196 Functions.ajaxShowMessage();
197 $.post('index.php?route=/table/export', params, function (response) {
198 if (response.success === true) {
199 $('#template').find('option[value="' + id + '"]').remove();
200 Functions.ajaxShowMessage(Messages.strTemplateDeleted);
202 Functions.ajaxShowMessage(response.error, false);
208 * Unbind all event handlers before tearing down a page
210 AJAX.registerTeardown('export.js', function () {
211 $('#plugins').off('change');
212 $('input[type=\'radio\'][name=\'sql_structure_or_data\']').off('change');
213 $('input[type=\'radio\'][name$=\'_structure_or_data\']').off('change');
214 $('input[type=\'radio\'][name=\'output_format\']').off('change');
215 $('#checkbox_sql_include_comments').off('change');
216 $('input[type=\'radio\'][name=\'quick_or_custom\']').off('change');
217 $('input[type=\'radio\'][name=\'allrows\']').off('change');
218 $('#btn_alias_config').off('click');
219 $('.alias_remove').off('click');
220 $('#db_alias_button').off('click');
221 $('#table_alias_button').off('click');
222 $('#column_alias_button').off('click');
223 $('input[name="table_select[]"]').off('change');
224 $('input[name="table_structure[]"]').off('change');
225 $('input[name="table_data[]"]').off('change');
226 $('#table_structure_all').off('change');
227 $('#table_data_all').off('change');
228 $('input[name="createTemplate"]').off('click');
229 $('select[name="template"]').off('change');
230 $('input[name="updateTemplate"]').off('click');
231 $('input[name="deleteTemplate"]').off('click');
234 AJAX.registerOnload('export.js', function () {
236 * Export template handling code
238 // create a new template
239 $('input[name="createTemplate"]').on('click', function (e) {
241 var name = $('input[name="templateName"]').val();
243 Export.createTemplate(name);
247 // load an existing template
248 $('select[name="template"]').on('change', function (e) {
250 var id = $(this).val();
252 Export.loadTemplate(id);
256 // udpate an existing template with new criteria
257 $('input[name="updateTemplate"]').on('click', function (e) {
259 var id = $('select[name="template"]').val();
261 Export.updateTemplate(id);
265 // delete an existing template
266 $('input[name="deleteTemplate"]').on('click', function (e) {
268 var id = $('select[name="template"]').val();
270 Export.deleteTemplate(id);
275 * Toggles the hiding and showing of each plugin's options
276 * according to the currently selected plugin from the dropdown list
278 $('#plugins').on('change', function () {
279 $('#format_specific_opts').find('div.format_specific_options').hide();
280 var selectedPluginName = $('#plugins').find('option:selected').val();
281 $('#' + selectedPluginName + '_options').show();
285 * Toggles the enabling and disabling of the SQL plugin's comment options that apply only when exporting structure
287 $('input[type=\'radio\'][name=\'sql_structure_or_data\']').on('change', function () {
288 var commentsArePresent = $('#checkbox_sql_include_comments').prop('checked');
289 var show = $('input[type=\'radio\'][name=\'sql_structure_or_data\']:checked').val();
290 if (show === 'data') {
291 // disable the SQL comment options
292 if (commentsArePresent) {
293 $('#checkbox_sql_dates').prop('disabled', true).parent().fadeTo('fast', 0.4);
295 $('#checkbox_sql_relation').prop('disabled', true).parent().fadeTo('fast', 0.4);
296 $('#checkbox_sql_mime').prop('disabled', true).parent().fadeTo('fast', 0.4);
298 // enable the SQL comment options
299 if (commentsArePresent) {
300 $('#checkbox_sql_dates').prop('disabled', false).parent().fadeTo('fast', 1);
302 $('#checkbox_sql_relation').prop('disabled', false).parent().fadeTo('fast', 1);
303 $('#checkbox_sql_mime').prop('disabled', false).parent().fadeTo('fast', 1);
306 if (show === 'structure') {
307 $('#checkbox_sql_auto_increment').prop('disabled', true).parent().fadeTo('fast', 0.4);
309 $('#checkbox_sql_auto_increment').prop('disabled', false).parent().fadeTo('fast', 1);
313 // When MS Excel is selected as the Format automatically Switch to Character Set as windows-1252
314 $('#plugins').on('change', function () {
315 var selectedPluginName = $('#plugins').find('option:selected').val();
316 if (selectedPluginName === 'excel') {
317 $('#select_charset').val('windows-1252');
319 $('#select_charset').val('utf-8');
323 // For separate-file exports only ZIP compression is allowed
324 $('input[type="checkbox"][name="as_separate_files"]').on('change', function () {
325 if ($(this).is(':checked')) {
326 $('#compression').val('zip');
330 $('#compression').on('change', function () {
331 if ($('option:selected').val() !== 'zip') {
332 $('input[type="checkbox"][name="as_separate_files"]').prop('checked', false);
337 Export.setupTableStructureOrData = function () {
338 if ($('input[name=\'export_type\']').val() !== 'database') {
341 var pluginName = $('#plugins').find('option:selected').val();
342 var formElemName = pluginName + '_structure_or_data';
343 var forceStructureOrData = !($('input[name=\'' + formElemName + '_default\']').length);
345 if (forceStructureOrData === true) {
346 $('input[name="structure_or_data_forced"]').val(1);
347 $('.export_structure input[type="checkbox"], .export_data input[type="checkbox"]')
348 .prop('disabled', true);
349 $('.export_structure, .export_data').fadeTo('fast', 0.4);
351 $('input[name="structure_or_data_forced"]').val(0);
352 $('.export_structure input[type="checkbox"], .export_data input[type="checkbox"]')
353 .prop('disabled', false);
354 $('.export_structure, .export_data').fadeTo('fast', 1);
356 var structureOrData = $('input[name="' + formElemName + '_default"]').val();
358 if (structureOrData === 'structure') {
359 $('.export_data input[type="checkbox"]')
360 .prop('checked', false);
361 } else if (structureOrData === 'data') {
362 $('.export_structure input[type="checkbox"]')
363 .prop('checked', false);
365 if (structureOrData === 'structure' || structureOrData === 'structure_and_data') {
366 if (!$('.export_structure input[type="checkbox"]:checked').length) {
367 $('input[name="table_select[]"]:checked')
369 .find('.export_structure input[type="checkbox"]')
370 .prop('checked', true);
373 if (structureOrData === 'data' || structureOrData === 'structure_and_data') {
374 if (!$('.export_data input[type="checkbox"]:checked').length) {
375 $('input[name="table_select[]"]:checked')
377 .find('.export_data input[type="checkbox"]')
378 .prop('checked', true);
382 Export.checkSelectedTables();
383 Export.checkTableSelectAll();
384 Export.checkTableSelectStrutureOrData();
389 * Toggles the hiding and showing of plugin structure-specific and data-specific
392 Export.toggleStructureDataOpts = function () {
393 var pluginName = $('select#plugins').val();
394 var radioFormName = pluginName + '_structure_or_data';
395 var dataDiv = '#' + pluginName + '_data';
396 var structureDiv = '#' + pluginName + '_structure';
397 var show = $('input[type=\'radio\'][name=\'' + radioFormName + '\']:checked').val();
398 // Show the #rows if 'show' is not structure
399 $('#rows').toggle(show !== 'structure');
400 if (show === 'data') {
401 $(dataDiv).slideDown('slow');
402 $(structureDiv).slideUp('slow');
404 $(structureDiv).slideDown('slow');
405 if (show === 'structure') {
406 $(dataDiv).slideUp('slow');
408 $(dataDiv).slideDown('slow');
414 * Toggles the disabling of the "save to file" options
416 Export.toggleSaveToFile = function () {
417 var $ulSaveAsfile = $('#ul_save_asfile');
418 if (!$('#radio_dump_asfile').prop('checked')) {
419 $ulSaveAsfile.find('> li').fadeTo('fast', 0.4);
420 $ulSaveAsfile.find('> li > input').prop('disabled', true);
421 $ulSaveAsfile.find('> li > select').prop('disabled', true);
423 $ulSaveAsfile.find('> li').fadeTo('fast', 1);
424 $ulSaveAsfile.find('> li > input').prop('disabled', false);
425 $ulSaveAsfile.find('> li > select').prop('disabled', false);
429 AJAX.registerOnload('export.js', function () {
430 Export.toggleSaveToFile();
431 $('input[type=\'radio\'][name=\'output_format\']').on('change', Export.toggleSaveToFile);
435 * For SQL plugin, toggles the disabling of the "display comments" options
437 Export.toggleSqlIncludeComments = function () {
438 $('#checkbox_sql_include_comments').on('change', function () {
439 var $ulIncludeComments = $('#ul_include_comments');
440 if (!$('#checkbox_sql_include_comments').prop('checked')) {
441 $ulIncludeComments.find('> li').fadeTo('fast', 0.4);
442 $ulIncludeComments.find('> li > input').prop('disabled', true);
444 // If structure is not being exported, the comment options for structure should not be enabled
445 if ($('#radio_sql_structure_or_data_data').prop('checked')) {
446 $('#text_sql_header_comment').prop('disabled', false).parent('li').fadeTo('fast', 1);
448 $ulIncludeComments.find('> li').fadeTo('fast', 1);
449 $ulIncludeComments.find('> li > input').prop('disabled', false);
455 Export.checkTableSelectAll = function () {
456 var total = $('input[name="table_select[]"]').length;
457 var strChecked = $('input[name="table_structure[]"]:checked').length;
458 var dataChecked = $('input[name="table_data[]"]:checked').length;
459 var strAll = $('#table_structure_all');
460 var dataAll = $('#table_data_all');
462 if (strChecked === total) {
464 .prop('indeterminate', false)
465 .prop('checked', true);
466 } else if (strChecked === 0) {
468 .prop('indeterminate', false)
469 .prop('checked', false);
472 .prop('indeterminate', true)
473 .prop('checked', false);
476 if (dataChecked === total) {
478 .prop('indeterminate', false)
479 .prop('checked', true);
480 } else if (dataChecked === 0) {
482 .prop('indeterminate', false)
483 .prop('checked', false);
486 .prop('indeterminate', true)
487 .prop('checked', false);
491 Export.checkTableSelectStrutureOrData = function () {
492 var strChecked = $('input[name="table_structure[]"]:checked').length;
493 var dataChecked = $('input[name="table_data[]"]:checked').length;
494 var autoIncrement = $('#checkbox_sql_auto_increment');
496 var pluginName = $('select#plugins').val();
497 var dataDiv = '#' + pluginName + '_data';
498 var structureDiv = '#' + pluginName + '_structure';
500 if (strChecked === 0) {
501 $(structureDiv).slideUp('slow');
503 $(structureDiv).slideDown('slow');
506 if (dataChecked === 0) {
507 $(dataDiv).slideUp('slow');
508 autoIncrement.prop('disabled', true).parent().fadeTo('fast', 0.4);
510 $(dataDiv).slideDown('slow');
511 autoIncrement.prop('disabled', false).parent().fadeTo('fast', 1);
515 Export.toggleTableSelectAllStr = function () {
516 var strAll = $('#table_structure_all').is(':checked');
518 $('input[name="table_structure[]"]').prop('checked', true);
520 $('input[name="table_structure[]"]').prop('checked', false);
524 Export.toggleTableSelectAllData = function () {
525 var dataAll = $('#table_data_all').is(':checked');
527 $('input[name="table_data[]"]').prop('checked', true);
529 $('input[name="table_data[]"]').prop('checked', false);
533 Export.checkSelectedTables = function () {
534 $('.export_table_select tbody tr').each(function () {
535 Export.checkTableSelected(this);
539 Export.checkTableSelected = function (row) {
541 var tableSelect = $row.find('input[name="table_select[]"]');
542 var strCheck = $row.find('input[name="table_structure[]"]');
543 var dataCheck = $row.find('input[name="table_data[]"]');
545 var data = dataCheck.is(':checked:not(:disabled)');
546 var structure = strCheck.is(':checked:not(:disabled)');
548 if (data && structure) {
549 tableSelect.prop({ checked: true, indeterminate: false });
550 $row.addClass('marked');
551 } else if (data || structure) {
552 tableSelect.prop({ checked: true, indeterminate: true });
553 $row.removeClass('marked');
555 tableSelect.prop({ checked: false, indeterminate: false });
556 $row.removeClass('marked');
560 Export.toggleTableSelect = function (row) {
562 var tableSelected = $row.find('input[name="table_select[]"]').is(':checked');
565 $row.find('input[type="checkbox"]:not(:disabled)').prop('checked', true);
566 $row.addClass('marked');
568 $row.find('input[type="checkbox"]:not(:disabled)').prop('checked', false);
569 $row.removeClass('marked');
573 Export.handleAddProcCheckbox = function () {
574 if ($('#table_structure_all').is(':checked') === true
575 && $('#table_data_all').is(':checked') === true
577 $('#checkbox_sql_procedure_function').prop('checked', true);
579 $('#checkbox_sql_procedure_function').prop('checked', false);
583 AJAX.registerOnload('export.js', function () {
585 * For SQL plugin, if "CREATE TABLE options" is checked/unchecked, check/uncheck each of its sub-options
587 var $create = $('#checkbox_sql_create_table_statements');
588 var $createOptions = $('#ul_create_table_statements').find('input');
589 $create.on('change', function () {
590 $createOptions.prop('checked', $(this).prop('checked'));
592 $createOptions.on('change', function () {
593 if ($createOptions.is(':checked')) {
594 $create.prop('checked', true);
599 * Disables the view output as text option if the output must be saved as a file
601 $('#plugins').on('change', function () {
602 var activePlugin = $('#plugins').find('option:selected').val();
603 var forceFile = $('#force_file_' + activePlugin).val();
604 if (forceFile === 'true') {
605 if ($('#radio_dump_asfile').prop('checked') !== true) {
606 $('#radio_dump_asfile').prop('checked', true);
607 Export.toggleSaveToFile();
609 $('#radio_view_as_text').prop('disabled', true).parent().fadeTo('fast', 0.4);
611 $('#radio_view_as_text').prop('disabled', false).parent().fadeTo('fast', 1);
615 $('input[type=\'radio\'][name$=\'_structure_or_data\']').on('change', function () {
616 Export.toggleStructureDataOpts();
619 $('input[name="table_select[]"]').on('change', function () {
620 Export.toggleTableSelect($(this).closest('tr'));
621 Export.checkTableSelectAll();
622 Export.handleAddProcCheckbox();
623 Export.checkTableSelectStrutureOrData();
626 $('input[name="table_structure[]"]').on('change', function () {
627 Export.checkTableSelected($(this).closest('tr'));
628 Export.checkTableSelectAll();
629 Export.handleAddProcCheckbox();
630 Export.checkTableSelectStrutureOrData();
633 $('input[name="table_data[]"]').on('change', function () {
634 Export.checkTableSelected($(this).closest('tr'));
635 Export.checkTableSelectAll();
636 Export.handleAddProcCheckbox();
637 Export.checkTableSelectStrutureOrData();
640 $('#table_structure_all').on('change', function () {
641 Export.toggleTableSelectAllStr();
642 Export.checkSelectedTables();
643 Export.handleAddProcCheckbox();
644 Export.checkTableSelectStrutureOrData();
647 $('#table_data_all').on('change', function () {
648 Export.toggleTableSelectAllData();
649 Export.checkSelectedTables();
650 Export.handleAddProcCheckbox();
651 Export.checkTableSelectStrutureOrData();
654 if ($('input[name=\'export_type\']').val() === 'database') {
655 // Hide structure or data radio buttons
656 $('input[type=\'radio\'][name$=\'_structure_or_data\']').each(function () {
658 var name = $this.prop('name');
659 var val = $('input[name="' + name + '"]:checked').val();
660 var nameDefault = name + '_default';
661 if (!$('input[name="' + nameDefault + '"]').length) {
664 $('<input type="hidden" name="' + nameDefault + '" value="' + val + '" disabled>')
667 $('<input type="hidden" name="' + name + '" value="structure_and_data">')
669 $this.parent().find('label').remove();
671 $this.parent().remove();
674 $('input[type=\'radio\'][name$=\'_structure_or_data\']').remove();
676 // Disable CREATE table checkbox for sql
677 var createTableCheckbox = $('#checkbox_sql_create_table');
678 createTableCheckbox.prop('checked', true);
679 var dummyCreateTable = $('#checkbox_sql_create_table')
682 .attr('type', 'hidden');
684 .prop('disabled', true)
685 .after(dummyCreateTable)
687 .fadeTo('fast', 0.4);
689 Export.setupTableStructureOrData();
693 * Handle force structure_or_data
695 $('#plugins').on('change', Export.setupTableStructureOrData);
699 * Toggles display of options when quick and custom export are selected
701 Export.toggleQuickOrCustom = function () {
702 if ($('input[name=\'quick_or_custom\']').length === 0 // custom_no_form option
703 || $('#radio_custom_export').prop('checked') // custom
705 $('#databases_and_tables').show();
708 $('#format_specific_opts').show();
709 $('#output_quick_export').hide();
710 var selectedPluginName = $('#plugins').find('option:selected').val();
711 $('#' + selectedPluginName + '_options').show();
713 $('#databases_and_tables').hide();
716 $('#format_specific_opts').hide();
717 $('#output_quick_export').show();
723 Export.checkTimeOut = function (timeLimit) {
724 var limit = timeLimit;
725 if (typeof limit === 'undefined' || limit === 0) {
728 // margin of one second to avoid race condition to set/access session variable
731 'ajax_request' : true,
732 'check_time_out' : true
734 clearTimeout(timeOut);
735 timeOut = setTimeout(function () {
736 $.get('index.php?route=/export', params, function (data) {
737 if (data.message === 'timeout') {
738 Functions.ajaxShowMessage(
739 '<div class="alert alert-danger" role="alert">' +
740 Messages.strTimeOutError +
750 * Handler for Database/table alias select
752 * @param event object the event object
756 Export.aliasSelectHandler = function (event) {
757 var sel = event.data.sel;
758 var type = event.data.type;
759 var inputId = $(this).val();
760 var $label = $(this).next('label');
761 $('input#' + $label.attr('for')).addClass('hide');
762 $('input#' + inputId).removeClass('hide');
763 $label.attr('for', inputId);
764 $('#alias_modal ' + sel + '[id$=' + type + ']:visible').addClass('hide');
765 var $inputWrapper = $('#alias_modal ' + sel + '#' + inputId + type);
766 $inputWrapper.removeClass('hide');
767 if (type === '_cols' && $inputWrapper.length > 0) {
768 var outer = $inputWrapper[0].outerHTML;
769 // Replace opening tags
770 var regex = /<dummy_inp/gi;
771 if (outer.match(regex)) {
772 var newTag = outer.replace(regex, '<input');
773 // Replace closing tags
774 regex = /<\/dummy_inp/gi;
775 newTag = newTag.replace(regex, '</input');
776 // Assign replacement
777 $inputWrapper.replaceWith(newTag);
779 } else if (type === '_tables') {
780 $('.table_alias_select:visible').trigger('change');
782 $('#alias_modal').dialog('option', 'position', 'center');
786 * Handler for Alias dialog box
788 * @param event object the event object
792 Export.createAliasModal = function (event) {
793 event.preventDefault();
795 dlgButtons[Messages.strSaveAndClose] = function () {
796 $(this).dialog('close');
797 $('#alias_modal').parent().appendTo($('form[name="dump"]'));
799 $('#alias_modal').dialog({
800 width: Math.min($(window).width() - 100, 700),
801 maxHeight: $(window).height(),
803 dialogClass: 'alias-dialog',
805 create: function () {
806 $(this).closest('.ui-dialog').find('.ui-button').addClass('btn btn-secondary');
807 $(this).css('maxHeight', $(window).height() - 150);
808 var db = CommonParams.get('db');
810 var option = $('<option></option>');
812 option.attr('value', db);
813 $('#db_alias_select').append(option).val(db).trigger('change');
816 'ajax_request': true,
817 'server': CommonParams.get('server')
819 $.post('index.php?route=/ajax/list-databases', params, function (response) {
820 if (response.success === true) {
821 $.each(response.databases, function (idx, value) {
822 var option = $('<option></option>');
824 option.attr('value', value);
825 $('#db_alias_select').append(option);
828 Functions.ajaxShowMessage(response.error, false);
835 $(this).find('input[type="text"]').each(function () {
836 // trim empty input fields on close
840 $(this).parents('tr').remove();
843 // Toggle checkbox based on aliases
844 $('input#btn_alias_config').prop('checked', !isEmpty);
846 position: { my: 'center top', at: 'center top', of: window }
850 Export.aliasToggleRow = function (elm) {
851 var inputs = elm.parents('tr').find('input,button');
853 inputs.attr('disabled', false);
855 inputs.attr('disabled', true);
859 Export.addAlias = function (type, name, field, value) {
864 var row = $('#alias_data tfoot tr').clone();
865 row.find('th').text(type);
866 row.find('td').first().text(name);
867 row.find('input').attr('name', field);
868 row.find('input').val(value);
869 row.find('.alias_remove').on('click', function () {
870 $(this).parents('tr').remove();
873 var matching = $('#alias_data [name="' + $.escapeSelector(field) + '"]');
874 if (matching.length > 0) {
875 matching.parents('tr').remove();
878 $('#alias_data tbody').append(row);
881 AJAX.registerOnload('export.js', function () {
882 $('input[type=\'radio\'][name=\'quick_or_custom\']').on('change', Export.toggleQuickOrCustom);
884 $('#scroll_to_options_msg').hide();
885 $('#format_specific_opts').find('div.format_specific_options')
894 Export.toggleQuickOrCustom();
895 Export.toggleStructureDataOpts();
896 Export.toggleSqlIncludeComments();
897 Export.checkTableSelectAll();
898 Export.handleAddProcCheckbox();
901 * Initially disables the "Dump some row(s)" sub-options
903 Export.disableDumpSomeRowsSubOptions();
906 * Disables the "Dump some row(s)" sub-options when it is not selected
908 $('input[type=\'radio\'][name=\'allrows\']').on('change', function () {
909 if ($('input[type=\'radio\'][name=\'allrows\']').prop('checked')) {
910 Export.enableDumpSomeRowsSubOptions();
912 Export.disableDumpSomeRowsSubOptions();
916 // Open Alias Modal Dialog on click
917 $('#btn_alias_config').on('click', Export.createAliasModal);
918 $('.alias_remove').on('click', function () {
919 $(this).parents('tr').remove();
921 $('#db_alias_select').on('change', function () {
922 Export.aliasToggleRow($(this));
923 var table = CommonParams.get('table');
925 var option = $('<option></option>');
927 option.attr('value', table);
928 $('#table_alias_select').append(option).val(table).trigger('change');
930 var database = $(this).val();
932 'ajax_request': true,
933 'server': CommonParams.get('server'),
936 var url = 'index.php?route=/ajax/list-tables';
937 $.post(url, params, function (response) {
938 if (response.success === true) {
939 $.each(response.tables, function (idx, value) {
940 var option = $('<option></option>');
942 option.attr('value', value);
943 $('#table_alias_select').append(option);
946 Functions.ajaxShowMessage(response.error, false);
951 $('#table_alias_select').on('change', function () {
952 Export.aliasToggleRow($(this));
953 var database = $('#db_alias_select').val();
954 var table = $(this).val();
956 'ajax_request': true,
957 'server': CommonParams.get('server'),
961 var url = 'index.php?route=/ajax/list-columns';
962 $.post(url, params, function (response) {
963 if (response.success === true) {
964 $.each(response.columns, function (idx, value) {
965 var option = $('<option></option>');
967 option.attr('value', value);
968 $('#column_alias_select').append(option);
971 Functions.ajaxShowMessage(response.error, false);
975 $('#column_alias_select').on('change', function () {
976 Export.aliasToggleRow($(this));
978 $('#db_alias_button').on('click', function (e) {
980 var db = $('#db_alias_select').val();
982 Messages.strAliasDatabase,
984 'aliases[' + db + '][alias]',
985 $('#db_alias_name').val()
987 $('#db_alias_name').val('');
989 $('#table_alias_button').on('click', function (e) {
991 var db = $('#db_alias_select').val();
992 var table = $('#table_alias_select').val();
994 Messages.strAliasTable,
996 'aliases[' + db + '][tables][' + table + '][alias]',
997 $('#table_alias_name').val()
999 $('#table_alias_name').val('');
1001 $('#column_alias_button').on('click', function (e) {
1003 var db = $('#db_alias_select').val();
1004 var table = $('#table_alias_select').val();
1005 var column = $('#column_alias_select').val();
1007 Messages.strAliasColumn,
1008 db + '.' + table + '.' + column,
1009 'aliases[' + db + '][tables][' + table + '][colums][' + column + ']',
1010 $('#column_alias_name').val()
1012 $('#column_alias_name').val('');