1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * Functions used in the export tab
10 * Disables the "Dump some row(s)" sub-options
12 Export.disableDumpSomeRowsSubOptions = function () {
13 $('label[for=\'limit_to\']').fadeTo('fast', 0.4);
14 $('label[for=\'limit_from\']').fadeTo('fast', 0.4);
15 $('input[type=\'text\'][name=\'limit_to\']').prop('disabled', 'disabled');
16 $('input[type=\'text\'][name=\'limit_from\']').prop('disabled', 'disabled');
20 * Enables the "Dump some row(s)" sub-options
22 Export.enableDumpSomeRowsSubOptions = function () {
23 $('label[for=\'limit_to\']').fadeTo('fast', 1);
24 $('label[for=\'limit_from\']').fadeTo('fast', 1);
25 $('input[type=\'text\'][name=\'limit_to\']').prop('disabled', '');
26 $('input[type=\'text\'][name=\'limit_from\']').prop('disabled', '');
30 * Return template data as a json object
32 * @returns template data
34 Export.getTemplateData = function () {
35 var $form = $('form[name="dump"]');
36 var blacklist = ['token', 'server', 'db', 'table', 'single_table',
37 'export_type', 'export_method', 'sql_query', 'template_id'];
39 var arr = $form.serializeArray();
40 $.each(arr, function () {
41 if ($.inArray(this.name, blacklist) < 0) {
42 if (obj[this.name] !== undefined) {
43 if (! obj[this.name].push) {
44 obj[this.name] = [obj[this.name]];
46 obj[this.name].push(this.value || '');
48 obj[this.name] = this.value || '';
52 // include unchecked checboxes (which are ignored by serializeArray()) with null
53 // to uncheck them when loading the template
54 $form.find('input[type="checkbox"]:not(:checked)').each(function () {
55 if (obj[this.name] === undefined) {
56 obj[this.name] = null;
59 // include empty multiselects
60 $form.find('select').each(function () {
61 if ($(this).find('option:selected').length === 0) {
69 * Create a template with selected options
71 * @param name name of the template
73 Export.createTemplate = function (name) {
74 var templateData = Export.getTemplateData();
78 'server': CommonParams.get('server'),
79 'db': CommonParams.get('db'),
80 'table': CommonParams.get('table'),
81 'exportType': $('input[name="export_type"]').val(),
82 'templateAction': 'create',
84 'templateData': JSON.stringify(templateData)
87 Functions.ajaxShowMessage();
88 $.post('tbl_export.php', params, function (response) {
89 if (response.success === true) {
90 $('#templateName').val('');
91 $('#template').html(response.data);
92 $('#template').find('option').each(function () {
93 if ($(this).text() === name) {
94 $(this).prop('selected', true);
97 Functions.ajaxShowMessage(Messages.strTemplateCreated);
99 Functions.ajaxShowMessage(response.error, false);
107 * @param id ID of the template to load
109 Export.loadTemplate = function (id) {
111 'ajax_request': true,
112 'server': CommonParams.get('server'),
113 'db': CommonParams.get('db'),
114 'table': CommonParams.get('table'),
115 'exportType': $('input[name="export_type"]').val(),
116 'templateAction': 'load',
120 Functions.ajaxShowMessage();
121 $.post('tbl_export.php', params, function (response) {
122 if (response.success === true) {
123 var $form = $('form[name="dump"]');
124 var options = JSON.parse(response.data);
125 $.each(options, function (key, value) {
126 var localValue = value;
127 var $element = $form.find('[name="' + key + '"]');
128 if ($element.length) {
129 if (($element.is('input') && $element.attr('type') === 'checkbox') && localValue === null) {
130 $element.prop('checked', false);
132 if (($element.is('input') && $element.attr('type') === 'checkbox') ||
133 ($element.is('input') && $element.attr('type') === 'radio') ||
134 ($element.is('select') && $element.attr('multiple') === 'multiple')) {
135 if (! localValue.push) {
136 localValue = [localValue];
139 $element.val(localValue);
141 $element.trigger('change');
144 $('input[name="template_id"]').val(id);
145 Functions.ajaxShowMessage(Messages.strTemplateLoaded);
147 Functions.ajaxShowMessage(response.error, false);
153 * Updates an existing template with current options
155 * @param id ID of the template to update
157 Export.updateTemplate = function (id) {
158 var templateData = Export.getTemplateData();
161 'ajax_request': true,
162 'server': CommonParams.get('server'),
163 'db': CommonParams.get('db'),
164 'table': CommonParams.get('table'),
165 'exportType': $('input[name="export_type"]').val(),
166 'templateAction': 'update',
168 'templateData': JSON.stringify(templateData)
171 Functions.ajaxShowMessage();
172 $.post('tbl_export.php', params, function (response) {
173 if (response.success === true) {
174 Functions.ajaxShowMessage(Messages.strTemplateUpdated);
176 Functions.ajaxShowMessage(response.error, false);
184 * @param id ID of the template to delete
186 Export.deleteTemplate = function (id) {
188 'ajax_request': true,
189 'server': CommonParams.get('server'),
190 'db': CommonParams.get('db'),
191 'table': CommonParams.get('table'),
192 'exportType': $('input[name="export_type"]').val(),
193 'templateAction': 'delete',
197 Functions.ajaxShowMessage();
198 $.post('tbl_export.php', params, function (response) {
199 if (response.success === true) {
200 $('#template').find('option[value="' + id + '"]').remove();
201 Functions.ajaxShowMessage(Messages.strTemplateDeleted);
203 Functions.ajaxShowMessage(response.error, false);
209 * Unbind all event handlers before tearing down a page
211 AJAX.registerTeardown('export.js', function () {
212 $('#plugins').off('change');
213 $('input[type=\'radio\'][name=\'sql_structure_or_data\']').off('change');
214 $('input[type=\'radio\'][name$=\'_structure_or_data\']').off('change');
215 $('input[type=\'radio\'][name=\'output_format\']').off('change');
216 $('#checkbox_sql_include_comments').off('change');
217 $('input[type=\'radio\'][name=\'quick_or_custom\']').off('change');
218 $('input[type=\'radio\'][name=\'allrows\']').off('change');
219 $('#btn_alias_config').off('click');
220 $('.alias_remove').off('click');
221 $('#db_alias_button').off('click');
222 $('#table_alias_button').off('click');
223 $('#column_alias_button').off('click');
224 $('input[name="table_select[]"]').off('change');
225 $('input[name="table_structure[]"]').off('change');
226 $('input[name="table_data[]"]').off('change');
227 $('#table_structure_all').off('change');
228 $('#table_data_all').off('change');
229 $('input[name="createTemplate"]').off('click');
230 $('select[name="template"]').off('change');
231 $('input[name="updateTemplate"]').off('click');
232 $('input[name="deleteTemplate"]').off('click');
235 AJAX.registerOnload('export.js', function () {
237 * Export template handling code
239 // create a new template
240 $('input[name="createTemplate"]').on('click', function (e) {
242 var name = $('input[name="templateName"]').val();
244 Export.createTemplate(name);
248 // load an existing template
249 $('select[name="template"]').on('change', function (e) {
251 var id = $(this).val();
253 Export.loadTemplate(id);
257 // udpate an existing template with new criteria
258 $('input[name="updateTemplate"]').on('click', function (e) {
260 var id = $('select[name="template"]').val();
262 Export.updateTemplate(id);
266 // delete an existing template
267 $('input[name="deleteTemplate"]').on('click', function (e) {
269 var id = $('select[name="template"]').val();
271 Export.deleteTemplate(id);
276 * Toggles the hiding and showing of each plugin's options
277 * according to the currently selected plugin from the dropdown list
279 $('#plugins').on('change', function () {
280 $('#format_specific_opts').find('div.format_specific_options').hide();
281 var selectedPluginName = $('#plugins').find('option:selected').val();
282 $('#' + selectedPluginName + '_options').show();
286 * Toggles the enabling and disabling of the SQL plugin's comment options that apply only when exporting structure
288 $('input[type=\'radio\'][name=\'sql_structure_or_data\']').on('change', function () {
289 var commentsArePresent = $('#checkbox_sql_include_comments').prop('checked');
290 var show = $('input[type=\'radio\'][name=\'sql_structure_or_data\']:checked').val();
291 if (show === 'data') {
292 // disable the SQL comment options
293 if (commentsArePresent) {
294 $('#checkbox_sql_dates').prop('disabled', true).parent().fadeTo('fast', 0.4);
296 $('#checkbox_sql_relation').prop('disabled', true).parent().fadeTo('fast', 0.4);
297 $('#checkbox_sql_mime').prop('disabled', true).parent().fadeTo('fast', 0.4);
299 // enable the SQL comment options
300 if (commentsArePresent) {
301 $('#checkbox_sql_dates').prop('disabled', false).parent().fadeTo('fast', 1);
303 $('#checkbox_sql_relation').prop('disabled', false).parent().fadeTo('fast', 1);
304 $('#checkbox_sql_mime').prop('disabled', false).parent().fadeTo('fast', 1);
307 if (show === 'structure') {
308 $('#checkbox_sql_auto_increment').prop('disabled', true).parent().fadeTo('fast', 0.4);
310 $('#checkbox_sql_auto_increment').prop('disabled', false).parent().fadeTo('fast', 1);
314 // When MS Excel is selected as the Format automatically Switch to Character Set as windows-1252
315 $('#plugins').change(function () {
316 var selectedPluginName = $('#plugins').find('option:selected').val();
317 if (selectedPluginName === 'excel') {
318 $('#select_charset').val('windows-1252');
320 $('#select_charset').val('utf-8');
324 // For separate-file exports only ZIP compression is allowed
325 $('input[type="checkbox"][name="as_separate_files"]').on('change', function () {
326 if ($(this).is(':checked')) {
327 $('#compression').val('zip');
331 $('#compression').on('change', function () {
332 if ($('option:selected').val() !== 'zip') {
333 $('input[type="checkbox"][name="as_separate_files"]').prop('checked', false);
338 Export.setupTableStructureOrData = function () {
339 if ($('input[name=\'export_type\']').val() !== 'database') {
342 var pluginName = $('#plugins').find('option:selected').val();
343 var formElemName = pluginName + '_structure_or_data';
344 var forceStructureOrData = !($('input[name=\'' + formElemName + '_default\']').length);
346 if (forceStructureOrData === true) {
347 $('input[name="structure_or_data_forced"]').val(1);
348 $('.export_structure input[type="checkbox"], .export_data input[type="checkbox"]')
349 .prop('disabled', true);
350 $('.export_structure, .export_data').fadeTo('fast', 0.4);
352 $('input[name="structure_or_data_forced"]').val(0);
353 $('.export_structure input[type="checkbox"], .export_data input[type="checkbox"]')
354 .prop('disabled', false);
355 $('.export_structure, .export_data').fadeTo('fast', 1);
357 var structureOrData = $('input[name="' + formElemName + '_default"]').val();
359 if (structureOrData === 'structure') {
360 $('.export_data input[type="checkbox"]')
361 .prop('checked', false);
362 } else if (structureOrData === 'data') {
363 $('.export_structure input[type="checkbox"]')
364 .prop('checked', false);
366 if (structureOrData === 'structure' || structureOrData === 'structure_and_data') {
367 if (!$('.export_structure input[type="checkbox"]:checked').length) {
368 $('input[name="table_select[]"]:checked')
370 .find('.export_structure input[type="checkbox"]')
371 .prop('checked', true);
374 if (structureOrData === 'data' || structureOrData === 'structure_and_data') {
375 if (!$('.export_data input[type="checkbox"]:checked').length) {
376 $('input[name="table_select[]"]:checked')
378 .find('.export_data input[type="checkbox"]')
379 .prop('checked', true);
383 Export.checkSelectedTables();
384 Export.checkTableSelectAll();
385 Export.checkTableSelectStrutureOrData();
390 * Toggles the hiding and showing of plugin structure-specific and data-specific
393 Export.toggleStructureDataOpts = function () {
394 var pluginName = $('select#plugins').val();
395 var radioFormName = pluginName + '_structure_or_data';
396 var dataDiv = '#' + pluginName + '_data';
397 var structureDiv = '#' + pluginName + '_structure';
398 var show = $('input[type=\'radio\'][name=\'' + radioFormName + '\']:checked').val();
399 // Show the #rows if 'show' is not structure
400 $('#rows').toggle(show !== 'structure');
401 if (show === 'data') {
402 $(dataDiv).slideDown('slow');
403 $(structureDiv).slideUp('slow');
405 $(structureDiv).slideDown('slow');
406 if (show === 'structure') {
407 $(dataDiv).slideUp('slow');
409 $(dataDiv).slideDown('slow');
415 * Toggles the disabling of the "save to file" options
417 Export.toggleSaveToFile = function () {
418 var $ulSaveAsfile = $('#ul_save_asfile');
419 if (!$('#radio_dump_asfile').prop('checked')) {
420 $ulSaveAsfile.find('> li').fadeTo('fast', 0.4);
421 $ulSaveAsfile.find('> li > input').prop('disabled', true);
422 $ulSaveAsfile.find('> li > select').prop('disabled', true);
424 $ulSaveAsfile.find('> li').fadeTo('fast', 1);
425 $ulSaveAsfile.find('> li > input').prop('disabled', false);
426 $ulSaveAsfile.find('> li > select').prop('disabled', false);
430 AJAX.registerOnload('export.js', function () {
431 Export.toggleSaveToFile();
432 $('input[type=\'radio\'][name=\'output_format\']').on('change', Export.toggleSaveToFile);
436 * For SQL plugin, toggles the disabling of the "display comments" options
438 Export.toggleSqlIncludeComments = function () {
439 $('#checkbox_sql_include_comments').on('change', function () {
440 var $ulIncludeComments = $('#ul_include_comments');
441 if (!$('#checkbox_sql_include_comments').prop('checked')) {
442 $ulIncludeComments.find('> li').fadeTo('fast', 0.4);
443 $ulIncludeComments.find('> li > input').prop('disabled', true);
445 // If structure is not being exported, the comment options for structure should not be enabled
446 if ($('#radio_sql_structure_or_data_data').prop('checked')) {
447 $('#text_sql_header_comment').prop('disabled', false).parent('li').fadeTo('fast', 1);
449 $ulIncludeComments.find('> li').fadeTo('fast', 1);
450 $ulIncludeComments.find('> li > input').prop('disabled', false);
456 Export.checkTableSelectAll = function () {
457 var total = $('input[name="table_select[]"]').length;
458 var strChecked = $('input[name="table_structure[]"]:checked').length;
459 var dataChecked = $('input[name="table_data[]"]:checked').length;
460 var strAll = $('#table_structure_all');
461 var dataAll = $('#table_data_all');
463 if (strChecked === total) {
465 .prop('indeterminate', false)
466 .prop('checked', true);
467 } else if (strChecked === 0) {
469 .prop('indeterminate', false)
470 .prop('checked', false);
473 .prop('indeterminate', true)
474 .prop('checked', false);
477 if (dataChecked === total) {
479 .prop('indeterminate', false)
480 .prop('checked', true);
481 } else if (dataChecked === 0) {
483 .prop('indeterminate', false)
484 .prop('checked', false);
487 .prop('indeterminate', true)
488 .prop('checked', false);
492 Export.checkTableSelectStrutureOrData = function () {
493 var strChecked = $('input[name="table_structure[]"]:checked').length;
494 var dataChecked = $('input[name="table_data[]"]:checked').length;
495 var autoIncrement = $('#checkbox_sql_auto_increment');
497 var pluginName = $('select#plugins').val();
498 var dataDiv = '#' + pluginName + '_data';
499 var structureDiv = '#' + pluginName + '_structure';
501 if (strChecked === 0) {
502 $(structureDiv).slideUp('slow');
504 $(structureDiv).slideDown('slow');
507 if (dataChecked === 0) {
508 $(dataDiv).slideUp('slow');
509 autoIncrement.prop('disabled', true).parent().fadeTo('fast', 0.4);
511 $(dataDiv).slideDown('slow');
512 autoIncrement.prop('disabled', false).parent().fadeTo('fast', 1);
516 Export.toggleTableSelectAllStr = function () {
517 var strAll = $('#table_structure_all').is(':checked');
519 $('input[name="table_structure[]"]').prop('checked', true);
521 $('input[name="table_structure[]"]').prop('checked', false);
525 Export.toggleTableSelectAllData = function () {
526 var dataAll = $('#table_data_all').is(':checked');
528 $('input[name="table_data[]"]').prop('checked', true);
530 $('input[name="table_data[]"]').prop('checked', false);
534 Export.checkSelectedTables = function () {
535 $('.export_table_select tbody tr').each(function () {
536 Export.checkTableSelected(this);
540 Export.checkTableSelected = function (row) {
542 var tableSelect = $row.find('input[name="table_select[]"]');
543 var strCheck = $row.find('input[name="table_structure[]"]');
544 var dataCheck = $row.find('input[name="table_data[]"]');
546 var data = dataCheck.is(':checked:not(:disabled)');
547 var structure = strCheck.is(':checked:not(:disabled)');
549 if (data && structure) {
550 tableSelect.prop({ checked: true, indeterminate: false });
551 $row.addClass('marked');
552 } else if (data || structure) {
553 tableSelect.prop({ checked: true, indeterminate: true });
554 $row.removeClass('marked');
556 tableSelect.prop({ checked: false, indeterminate: false });
557 $row.removeClass('marked');
561 Export.toggleTableSelect = function (row) {
563 var tableSelected = $row.find('input[name="table_select[]"]').is(':checked');
566 $row.find('input[type="checkbox"]:not(:disabled)').prop('checked', true);
567 $row.addClass('marked');
569 $row.find('input[type="checkbox"]:not(:disabled)').prop('checked', false);
570 $row.removeClass('marked');
574 Export.handleAddProcCheckbox = function () {
575 if ($('#table_structure_all').is(':checked') === true
576 && $('#table_data_all').is(':checked') === true
578 $('#checkbox_sql_procedure_function').prop('checked', true);
580 $('#checkbox_sql_procedure_function').prop('checked', false);
584 AJAX.registerOnload('export.js', function () {
586 * For SQL plugin, if "CREATE TABLE options" is checked/unchecked, check/uncheck each of its sub-options
588 var $create = $('#checkbox_sql_create_table_statements');
589 var $createOptions = $('#ul_create_table_statements').find('input');
590 $create.on('change', function () {
591 $createOptions.prop('checked', $(this).prop('checked'));
593 $createOptions.on('change', function () {
594 if ($createOptions.is(':checked')) {
595 $create.prop('checked', true);
600 * Disables the view output as text option if the output must be saved as a file
602 $('#plugins').on('change', function () {
603 var activePlugin = $('#plugins').find('option:selected').val();
604 var forceFile = $('#force_file_' + activePlugin).val();
605 if (forceFile === 'true') {
606 if ($('#radio_dump_asfile').prop('checked') !== true) {
607 $('#radio_dump_asfile').prop('checked', true);
608 Export.toggleSaveToFile();
610 $('#radio_view_as_text').prop('disabled', true).parent().fadeTo('fast', 0.4);
612 $('#radio_view_as_text').prop('disabled', false).parent().fadeTo('fast', 1);
616 $('input[type=\'radio\'][name$=\'_structure_or_data\']').on('change', function () {
617 Export.toggleStructureDataOpts();
620 $('input[name="table_select[]"]').on('change', function () {
621 Export.toggleTableSelect($(this).closest('tr'));
622 Export.checkTableSelectAll();
623 Export.handleAddProcCheckbox();
624 Export.checkTableSelectStrutureOrData();
627 $('input[name="table_structure[]"]').on('change', function () {
628 Export.checkTableSelected($(this).closest('tr'));
629 Export.checkTableSelectAll();
630 Export.handleAddProcCheckbox();
631 Export.checkTableSelectStrutureOrData();
634 $('input[name="table_data[]"]').on('change', function () {
635 Export.checkTableSelected($(this).closest('tr'));
636 Export.checkTableSelectAll();
637 Export.handleAddProcCheckbox();
638 Export.checkTableSelectStrutureOrData();
641 $('#table_structure_all').on('change', function () {
642 Export.toggleTableSelectAllStr();
643 Export.checkSelectedTables();
644 Export.handleAddProcCheckbox();
645 Export.checkTableSelectStrutureOrData();
648 $('#table_data_all').on('change', function () {
649 Export.toggleTableSelectAllData();
650 Export.checkSelectedTables();
651 Export.handleAddProcCheckbox();
652 Export.checkTableSelectStrutureOrData();
655 if ($('input[name=\'export_type\']').val() === 'database') {
656 // Hide structure or data radio buttons
657 $('input[type=\'radio\'][name$=\'_structure_or_data\']').each(function () {
659 var name = $this.prop('name');
660 var val = $('input[name="' + name + '"]:checked').val();
661 var nameDefault = name + '_default';
662 if (!$('input[name="' + nameDefault + '"]').length) {
665 $('<input type="hidden" name="' + nameDefault + '" value="' + val + '" disabled>')
668 $('<input type="hidden" name="' + name + '" value="structure_and_data">')
670 $this.parent().find('label').remove();
672 $this.parent().remove();
675 $('input[type=\'radio\'][name$=\'_structure_or_data\']').remove();
677 // Disable CREATE table checkbox for sql
678 var createTableCheckbox = $('#checkbox_sql_create_table');
679 createTableCheckbox.prop('checked', true);
680 var dummyCreateTable = $('#checkbox_sql_create_table')
683 .attr('type', 'hidden');
685 .prop('disabled', true)
686 .after(dummyCreateTable)
688 .fadeTo('fast', 0.4);
690 Export.setupTableStructureOrData();
694 * Handle force structure_or_data
696 $('#plugins').on('change', Export.setupTableStructureOrData);
700 * Toggles display of options when quick and custom export are selected
702 Export.toggleQuickOrCustom = function () {
703 if ($('input[name=\'quick_or_custom\']').length === 0 // custom_no_form option
704 || $('#radio_custom_export').prop('checked') // custom
706 $('#databases_and_tables').show();
709 $('#format_specific_opts').show();
710 $('#output_quick_export').hide();
711 var selectedPluginName = $('#plugins').find('option:selected').val();
712 $('#' + selectedPluginName + '_options').show();
714 $('#databases_and_tables').hide();
717 $('#format_specific_opts').hide();
718 $('#output_quick_export').show();
724 Export.checkTimeOut = function (timeLimit) {
725 var limit = timeLimit;
726 if (typeof limit === 'undefined' || limit === 0) {
729 // margin of one second to avoid race condition to set/access session variable
731 var href = 'export.php';
733 'ajax_request' : true,
734 'check_time_out' : true
736 clearTimeout(timeOut);
737 timeOut = setTimeout(function () {
738 $.get(href, params, function (data) {
739 if (data.message === 'timeout') {
740 Functions.ajaxShowMessage(
741 '<div class="error">' +
742 Messages.strTimeOutError +
752 * Handler for Database/table alias select
754 * @param event object the event object
758 Export.aliasSelectHandler = function (event) {
759 var sel = event.data.sel;
760 var type = event.data.type;
761 var inputId = $(this).val();
762 var $label = $(this).next('label');
763 $('input#' + $label.attr('for')).addClass('hide');
764 $('input#' + inputId).removeClass('hide');
765 $label.attr('for', inputId);
766 $('#alias_modal ' + sel + '[id$=' + type + ']:visible').addClass('hide');
767 var $inputWrapper = $('#alias_modal ' + sel + '#' + inputId + type);
768 $inputWrapper.removeClass('hide');
769 if (type === '_cols' && $inputWrapper.length > 0) {
770 var outer = $inputWrapper[0].outerHTML;
771 // Replace opening tags
772 var regex = /<dummy_inp/gi;
773 if (outer.match(regex)) {
774 var newTag = outer.replace(regex, '<input');
775 // Replace closing tags
776 regex = /<\/dummy_inp/gi;
777 newTag = newTag.replace(regex, '</input');
778 // Assign replacement
779 $inputWrapper.replaceWith(newTag);
781 } else if (type === '_tables') {
782 $('.table_alias_select:visible').trigger('change');
784 $('#alias_modal').dialog('option', 'position', 'center');
788 * Handler for Alias dialog box
790 * @param event object the event object
794 Export.createAliasModal = function (event) {
795 event.preventDefault();
797 dlgButtons[Messages.strSaveAndClose] = function () {
798 $(this).dialog('close');
799 $('#alias_modal').parent().appendTo($('form[name="dump"]'));
801 $('#alias_modal').dialog({
802 width: Math.min($(window).width() - 100, 700),
803 maxHeight: $(window).height(),
805 dialogClass: 'alias-dialog',
807 create: function () {
808 $(this).closest('.ui-dialog').find('.ui-button').addClass('btn btn-secondary');
809 $(this).css('maxHeight', $(window).height() - 150);
810 var db = CommonParams.get('db');
812 var option = $('<option></option>');
814 option.attr('value', db);
815 $('#db_alias_select').append(option).val(db).trigger('change');
818 'ajax_request': true,
819 'server': CommonParams.get('server'),
820 'type': 'list-databases'
822 $.post('ajax.php', params, function (response) {
823 if (response.success === true) {
824 $.each(response.databases, function (idx, value) {
825 var option = $('<option></option>');
827 option.attr('value', value);
828 $('#db_alias_select').append(option);
831 Functions.ajaxShowMessage(response.error, false);
838 $(this).find('input[type="text"]').each(function () {
839 // trim empty input fields on close
843 $(this).parents('tr').remove();
846 // Toggle checkbox based on aliases
847 $('input#btn_alias_config').prop('checked', !isEmpty);
849 position: { my: 'center top', at: 'center top', of: window }
853 Export.aliasToggleRow = function (elm) {
854 var inputs = elm.parents('tr').find('input,button');
856 inputs.attr('disabled', false);
858 inputs.attr('disabled', true);
862 Export.addAlias = function (type, name, field, value) {
867 var row = $('#alias_data tfoot tr').clone();
868 row.find('th').text(type);
869 row.find('td:first').text(name);
870 row.find('input').attr('name', field);
871 row.find('input').val(value);
872 row.find('.alias_remove').on('click', function () {
873 $(this).parents('tr').remove();
876 var matching = $('#alias_data [name="' + $.escapeSelector(field) + '"]');
877 if (matching.length > 0) {
878 matching.parents('tr').remove();
881 $('#alias_data tbody').append(row);
884 AJAX.registerOnload('export.js', function () {
885 $('input[type=\'radio\'][name=\'quick_or_custom\']').on('change', Export.toggleQuickOrCustom);
887 $('#scroll_to_options_msg').hide();
888 $('#format_specific_opts').find('div.format_specific_options')
897 Export.toggleQuickOrCustom();
898 Export.toggleStructureDataOpts();
899 Export.toggleSqlIncludeComments();
900 Export.checkTableSelectAll();
901 Export.handleAddProcCheckbox();
904 * Initially disables the "Dump some row(s)" sub-options
906 Export.disableDumpSomeRowsSubOptions();
909 * Disables the "Dump some row(s)" sub-options when it is not selected
911 $('input[type=\'radio\'][name=\'allrows\']').on('change', function () {
912 if ($('input[type=\'radio\'][name=\'allrows\']').prop('checked')) {
913 Export.enableDumpSomeRowsSubOptions();
915 Export.disableDumpSomeRowsSubOptions();
919 // Open Alias Modal Dialog on click
920 $('#btn_alias_config').on('click', Export.createAliasModal);
921 $('.alias_remove').on('click', function () {
922 $(this).parents('tr').remove();
924 $('#db_alias_select').on('change', function () {
925 Export.aliasToggleRow($(this));
926 var table = CommonParams.get('table');
928 var option = $('<option></option>');
930 option.attr('value', table);
931 $('#table_alias_select').append(option).val(table).trigger('change');
934 'ajax_request': true,
935 'server': CommonParams.get('server'),
937 'type': 'list-tables'
939 $.post('ajax.php', params, function (response) {
940 if (response.success === true) {
941 $.each(response.tables, function (idx, value) {
942 var option = $('<option></option>');
944 option.attr('value', value);
945 $('#table_alias_select').append(option);
948 Functions.ajaxShowMessage(response.error, false);
953 $('#table_alias_select').on('change', function () {
954 Export.aliasToggleRow($(this));
956 'ajax_request': true,
957 'server': CommonParams.get('server'),
958 'db': $('#db_alias_select').val(),
959 'table': $(this).val(),
960 'type': 'list-columns'
962 $.post('ajax.php', 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('');