Translated using Weblate (Turkish)
[phpmyadmin.git] / js / export.js
blobdb625e7ba6dcab62c339f14e32b7f5b8dec47ee6
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * Functions used in the export tab
4  *
5  */
7 var Export = {};
9 /**
10  * Disables the "Dump some row(s)" sub-options
11  */
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');
19 /**
20  * Enables the "Dump some row(s)" sub-options
21  */
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', '');
29 /**
30  * Return template data as a json object
31  *
32  * @returns template data
33  */
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'];
38     var obj = {};
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]];
45                 }
46                 obj[this.name].push(this.value || '');
47             } else {
48                 obj[this.name] = this.value || '';
49             }
50         }
51     });
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;
57         }
58     });
59     // include empty multiselects
60     $form.find('select').each(function () {
61         if ($(this).find('option:selected').length === 0) {
62             obj[this.name] = [];
63         }
64     });
65     return obj;
68 /**
69  * Create a template with selected options
70  *
71  * @param name name of the template
72  */
73 Export.createTemplate = function (name) {
74     var templateData = Export.getTemplateData();
76     var params = {
77         'ajax_request': true,
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',
83         'templateName': name,
84         'templateData': JSON.stringify(templateData)
85     };
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);
95                 }
96             });
97             Functions.ajaxShowMessage(Messages.strTemplateCreated);
98         } else {
99             Functions.ajaxShowMessage(response.error, false);
100         }
101     });
105  * Loads a template
107  * @param id ID of the template to load
108  */
109 Export.loadTemplate = function (id) {
110     var params = {
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',
117         'templateId': id,
118     };
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);
131                     } else {
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];
137                             }
138                         }
139                         $element.val(localValue);
140                     }
141                     $element.trigger('change');
142                 }
143             });
144             $('input[name="template_id"]').val(id);
145             Functions.ajaxShowMessage(Messages.strTemplateLoaded);
146         } else {
147             Functions.ajaxShowMessage(response.error, false);
148         }
149     });
153  * Updates an existing template with current options
155  * @param id ID of the template to update
156  */
157 Export.updateTemplate = function (id) {
158     var templateData = Export.getTemplateData();
160     var params = {
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',
167         'templateId': id,
168         'templateData': JSON.stringify(templateData)
169     };
171     Functions.ajaxShowMessage();
172     $.post('tbl_export.php', params, function (response) {
173         if (response.success === true) {
174             Functions.ajaxShowMessage(Messages.strTemplateUpdated);
175         } else {
176             Functions.ajaxShowMessage(response.error, false);
177         }
178     });
182  * Delete a template
184  * @param id ID of the template to delete
185  */
186 Export.deleteTemplate = function (id) {
187     var params = {
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',
194         'templateId': id,
195     };
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);
202         } else {
203             Functions.ajaxShowMessage(response.error, false);
204         }
205     });
209  * Unbind all event handlers before tearing down a page
210  */
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 () {
236     /**
237      * Export template handling code
238      */
239     // create a new template
240     $('input[name="createTemplate"]').on('click', function (e) {
241         e.preventDefault();
242         var name = $('input[name="templateName"]').val();
243         if (name.length) {
244             Export.createTemplate(name);
245         }
246     });
248     // load an existing template
249     $('select[name="template"]').on('change', function (e) {
250         e.preventDefault();
251         var id = $(this).val();
252         if (id.length) {
253             Export.loadTemplate(id);
254         }
255     });
257     // udpate an existing template with new criteria
258     $('input[name="updateTemplate"]').on('click', function (e) {
259         e.preventDefault();
260         var id = $('select[name="template"]').val();
261         if (id.length) {
262             Export.updateTemplate(id);
263         }
264     });
266     // delete an existing template
267     $('input[name="deleteTemplate"]').on('click', function (e) {
268         e.preventDefault();
269         var id = $('select[name="template"]').val();
270         if (id.length) {
271             Export.deleteTemplate(id);
272         }
273     });
275     /**
276      * Toggles the hiding and showing of each plugin's options
277      * according to the currently selected plugin from the dropdown list
278      */
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();
283     });
285     /**
286      * Toggles the enabling and disabling of the SQL plugin's comment options that apply only when exporting structure
287      */
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);
295             }
296             $('#checkbox_sql_relation').prop('disabled', true).parent().fadeTo('fast', 0.4);
297             $('#checkbox_sql_mime').prop('disabled', true).parent().fadeTo('fast', 0.4);
298         } else {
299             // enable the SQL comment options
300             if (commentsArePresent) {
301                 $('#checkbox_sql_dates').prop('disabled', false).parent().fadeTo('fast', 1);
302             }
303             $('#checkbox_sql_relation').prop('disabled', false).parent().fadeTo('fast', 1);
304             $('#checkbox_sql_mime').prop('disabled', false).parent().fadeTo('fast', 1);
305         }
307         if (show === 'structure') {
308             $('#checkbox_sql_auto_increment').prop('disabled', true).parent().fadeTo('fast', 0.4);
309         } else {
310             $('#checkbox_sql_auto_increment').prop('disabled', false).parent().fadeTo('fast', 1);
311         }
312     });
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');
319         } else {
320             $('#select_charset').val('utf-8');
321         }
322     });
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');
328         }
329     });
331     $('#compression').on('change', function () {
332         if ($('option:selected').val() !== 'zip') {
333             $('input[type="checkbox"][name="as_separate_files"]').prop('checked', false);
334         }
335     });
338 Export.setupTableStructureOrData = function () {
339     if ($('input[name=\'export_type\']').val() !== 'database') {
340         return;
341     }
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);
351     } else {
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);
365         }
366         if (structureOrData === 'structure' || structureOrData === 'structure_and_data') {
367             if (!$('.export_structure input[type="checkbox"]:checked').length) {
368                 $('input[name="table_select[]"]:checked')
369                     .closest('tr')
370                     .find('.export_structure input[type="checkbox"]')
371                     .prop('checked', true);
372             }
373         }
374         if (structureOrData === 'data' || structureOrData === 'structure_and_data') {
375             if (!$('.export_data input[type="checkbox"]:checked').length) {
376                 $('input[name="table_select[]"]:checked')
377                     .closest('tr')
378                     .find('.export_data input[type="checkbox"]')
379                     .prop('checked', true);
380             }
381         }
383         Export.checkSelectedTables();
384         Export.checkTableSelectAll();
385         Export.checkTableSelectStrutureOrData();
386     }
390  * Toggles the hiding and showing of plugin structure-specific and data-specific
391  * options
392  */
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');
404     } else {
405         $(structureDiv).slideDown('slow');
406         if (show === 'structure') {
407             $(dataDiv).slideUp('slow');
408         } else {
409             $(dataDiv).slideDown('slow');
410         }
411     }
415  * Toggles the disabling of the "save to file" options
416  */
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);
423     } else {
424         $ulSaveAsfile.find('> li').fadeTo('fast', 1);
425         $ulSaveAsfile.find('> li > input').prop('disabled', false);
426         $ulSaveAsfile.find('> li > select').prop('disabled', false);
427     }
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
437  */
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);
444         } else {
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);
448             } else {
449                 $ulIncludeComments.find('> li').fadeTo('fast', 1);
450                 $ulIncludeComments.find('> li > input').prop('disabled', false);
451             }
452         }
453     });
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) {
464         strAll
465             .prop('indeterminate', false)
466             .prop('checked', true);
467     } else if (strChecked === 0) {
468         strAll
469             .prop('indeterminate', false)
470             .prop('checked', false);
471     } else {
472         strAll
473             .prop('indeterminate', true)
474             .prop('checked', false);
475     }
477     if (dataChecked === total) {
478         dataAll
479             .prop('indeterminate', false)
480             .prop('checked', true);
481     } else if (dataChecked === 0) {
482         dataAll
483             .prop('indeterminate', false)
484             .prop('checked', false);
485     } else {
486         dataAll
487             .prop('indeterminate', true)
488             .prop('checked', false);
489     }
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');
503     } else {
504         $(structureDiv).slideDown('slow');
505     }
507     if (dataChecked === 0) {
508         $(dataDiv).slideUp('slow');
509         autoIncrement.prop('disabled', true).parent().fadeTo('fast', 0.4);
510     } else {
511         $(dataDiv).slideDown('slow');
512         autoIncrement.prop('disabled', false).parent().fadeTo('fast', 1);
513     }
516 Export.toggleTableSelectAllStr = function () {
517     var strAll = $('#table_structure_all').is(':checked');
518     if (strAll) {
519         $('input[name="table_structure[]"]').prop('checked', true);
520     } else {
521         $('input[name="table_structure[]"]').prop('checked', false);
522     }
525 Export.toggleTableSelectAllData = function () {
526     var dataAll = $('#table_data_all').is(':checked');
527     if (dataAll) {
528         $('input[name="table_data[]"]').prop('checked', true);
529     } else {
530         $('input[name="table_data[]"]').prop('checked', false);
531     }
534 Export.checkSelectedTables = function () {
535     $('.export_table_select tbody tr').each(function () {
536         Export.checkTableSelected(this);
537     });
540 Export.checkTableSelected = function (row) {
541     var $row = $(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');
555     } else {
556         tableSelect.prop({ checked: false, indeterminate: false });
557         $row.removeClass('marked');
558     }
561 Export.toggleTableSelect = function (row) {
562     var $row = $(row);
563     var tableSelected = $row.find('input[name="table_select[]"]').is(':checked');
565     if (tableSelected) {
566         $row.find('input[type="checkbox"]:not(:disabled)').prop('checked', true);
567         $row.addClass('marked');
568     } else {
569         $row.find('input[type="checkbox"]:not(:disabled)').prop('checked', false);
570         $row.removeClass('marked');
571     }
574 Export.handleAddProcCheckbox = function () {
575     if ($('#table_structure_all').is(':checked') === true
576         && $('#table_data_all').is(':checked') === true
577     ) {
578         $('#checkbox_sql_procedure_function').prop('checked', true);
579     } else {
580         $('#checkbox_sql_procedure_function').prop('checked', false);
581     }
584 AJAX.registerOnload('export.js', function () {
585     /**
586      * For SQL plugin, if "CREATE TABLE options" is checked/unchecked, check/uncheck each of its sub-options
587      */
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'));
592     });
593     $createOptions.on('change', function () {
594         if ($createOptions.is(':checked')) {
595             $create.prop('checked', true);
596         }
597     });
599     /**
600      * Disables the view output as text option if the output must be saved as a file
601      */
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();
609             }
610             $('#radio_view_as_text').prop('disabled', true).parent().fadeTo('fast', 0.4);
611         } else {
612             $('#radio_view_as_text').prop('disabled', false).parent().fadeTo('fast', 1);
613         }
614     });
616     $('input[type=\'radio\'][name$=\'_structure_or_data\']').on('change', function () {
617         Export.toggleStructureDataOpts();
618     });
620     $('input[name="table_select[]"]').on('change', function () {
621         Export.toggleTableSelect($(this).closest('tr'));
622         Export.checkTableSelectAll();
623         Export.handleAddProcCheckbox();
624         Export.checkTableSelectStrutureOrData();
625     });
627     $('input[name="table_structure[]"]').on('change', function () {
628         Export.checkTableSelected($(this).closest('tr'));
629         Export.checkTableSelectAll();
630         Export.handleAddProcCheckbox();
631         Export.checkTableSelectStrutureOrData();
632     });
634     $('input[name="table_data[]"]').on('change', function () {
635         Export.checkTableSelected($(this).closest('tr'));
636         Export.checkTableSelectAll();
637         Export.handleAddProcCheckbox();
638         Export.checkTableSelectStrutureOrData();
639     });
641     $('#table_structure_all').on('change', function () {
642         Export.toggleTableSelectAllStr();
643         Export.checkSelectedTables();
644         Export.handleAddProcCheckbox();
645         Export.checkTableSelectStrutureOrData();
646     });
648     $('#table_data_all').on('change', function () {
649         Export.toggleTableSelectAllData();
650         Export.checkSelectedTables();
651         Export.handleAddProcCheckbox();
652         Export.checkTableSelectStrutureOrData();
653     });
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 () {
658             var $this = $(this);
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) {
663                 $this
664                     .after(
665                         $('<input type="hidden" name="' + nameDefault + '" value="' + val + '" disabled>')
666                     )
667                     .after(
668                         $('<input type="hidden" name="' + name + '" value="structure_and_data">')
669                     );
670                 $this.parent().find('label').remove();
671             } else {
672                 $this.parent().remove();
673             }
674         });
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')
681             .clone()
682             .removeAttr('id')
683             .attr('type', 'hidden');
684         createTableCheckbox
685             .prop('disabled', true)
686             .after(dummyCreateTable)
687             .parent()
688             .fadeTo('fast', 0.4);
690         Export.setupTableStructureOrData();
691     }
693     /**
694      * Handle force structure_or_data
695      */
696     $('#plugins').on('change', Export.setupTableStructureOrData);
700  * Toggles display of options when quick and custom export are selected
701  */
702 Export.toggleQuickOrCustom = function () {
703     if ($('input[name=\'quick_or_custom\']').length === 0 // custom_no_form option
704         || $('#radio_custom_export').prop('checked') // custom
705     ) {
706         $('#databases_and_tables').show();
707         $('#rows').show();
708         $('#output').show();
709         $('#format_specific_opts').show();
710         $('#output_quick_export').hide();
711         var selectedPluginName = $('#plugins').find('option:selected').val();
712         $('#' + selectedPluginName + '_options').show();
713     } else { // quick
714         $('#databases_and_tables').hide();
715         $('#rows').hide();
716         $('#output').hide();
717         $('#format_specific_opts').hide();
718         $('#output_quick_export').show();
719     }
722 var timeOut;
724 Export.checkTimeOut = function (timeLimit) {
725     var limit = timeLimit;
726     if (typeof limit === 'undefined' || limit === 0) {
727         return true;
728     }
729     // margin of one second to avoid race condition to set/access session variable
730     limit = limit + 1;
731     var href = 'export.php';
732     var params = {
733         'ajax_request' : true,
734         'check_time_out' : true
735     };
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 +
743                     '</div>',
744                     false
745                 );
746             }
747         });
748     }, limit * 1000);
752  * Handler for Database/table alias select
754  * @param event object the event object
756  * @return void
757  */
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);
780         }
781     } else if (type === '_tables') {
782         $('.table_alias_select:visible').trigger('change');
783     }
784     $('#alias_modal').dialog('option', 'position', 'center');
788  * Handler for Alias dialog box
790  * @param event object the event object
792  * @return void
793  */
794 Export.createAliasModal = function (event) {
795     event.preventDefault();
796     var dlgButtons = {};
797     dlgButtons[Messages.strSaveAndClose] = function () {
798         $(this).dialog('close');
799         $('#alias_modal').parent().appendTo($('form[name="dump"]'));
800     };
801     $('#alias_modal').dialog({
802         width: Math.min($(window).width() - 100, 700),
803         maxHeight: $(window).height(),
804         modal: true,
805         dialogClass: 'alias-dialog',
806         buttons: dlgButtons,
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');
811             if (db) {
812                 var option = $('<option></option>');
813                 option.text(db);
814                 option.attr('value', db);
815                 $('#db_alias_select').append(option).val(db).trigger('change');
816             } else {
817                 var params = {
818                     'ajax_request': true,
819                     'server': CommonParams.get('server'),
820                     'type': 'list-databases'
821                 };
822                 $.post('ajax.php', params, function (response) {
823                     if (response.success === true) {
824                         $.each(response.databases, function (idx, value) {
825                             var option = $('<option></option>');
826                             option.text(value);
827                             option.attr('value', value);
828                             $('#db_alias_select').append(option);
829                         });
830                     } else {
831                         Functions.ajaxShowMessage(response.error, false);
832                     }
833                 });
834             }
835         },
836         close: function () {
837             var isEmpty = true;
838             $(this).find('input[type="text"]').each(function () {
839                 // trim empty input fields on close
840                 if ($(this).val()) {
841                     isEmpty = false;
842                 } else {
843                     $(this).parents('tr').remove();
844                 }
845             });
846             // Toggle checkbox based on aliases
847             $('input#btn_alias_config').prop('checked', !isEmpty);
848         },
849         position: { my: 'center top', at: 'center top', of: window }
850     });
853 Export.aliasToggleRow = function (elm) {
854     var inputs = elm.parents('tr').find('input,button');
855     if (elm.val()) {
856         inputs.attr('disabled', false);
857     } else {
858         inputs.attr('disabled', true);
859     }
862 Export.addAlias = function (type, name, field, value) {
863     if (value === '') {
864         return;
865     }
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();
874     });
876     var matching = $('#alias_data [name="' + $.escapeSelector(field) + '"]');
877     if (matching.length > 0) {
878         matching.parents('tr').remove();
879     }
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')
889         .hide()
890         .css({
891             'border': 0,
892             'margin': 0,
893             'padding': 0
894         })
895         .find('h3')
896         .remove();
897     Export.toggleQuickOrCustom();
898     Export.toggleStructureDataOpts();
899     Export.toggleSqlIncludeComments();
900     Export.checkTableSelectAll();
901     Export.handleAddProcCheckbox();
903     /**
904      * Initially disables the "Dump some row(s)" sub-options
905      */
906     Export.disableDumpSomeRowsSubOptions();
908     /**
909      * Disables the "Dump some row(s)" sub-options when it is not selected
910      */
911     $('input[type=\'radio\'][name=\'allrows\']').on('change', function () {
912         if ($('input[type=\'radio\'][name=\'allrows\']').prop('checked')) {
913             Export.enableDumpSomeRowsSubOptions();
914         } else {
915             Export.disableDumpSomeRowsSubOptions();
916         }
917     });
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();
923     });
924     $('#db_alias_select').on('change', function () {
925         Export.aliasToggleRow($(this));
926         var table = CommonParams.get('table');
927         if (table) {
928             var option = $('<option></option>');
929             option.text(table);
930             option.attr('value', table);
931             $('#table_alias_select').append(option).val(table).trigger('change');
932         } else {
933             var params = {
934                 'ajax_request': true,
935                 'server': CommonParams.get('server'),
936                 'db': $(this).val(),
937                 'type': 'list-tables'
938             };
939             $.post('ajax.php', params, function (response) {
940                 if (response.success === true) {
941                     $.each(response.tables, function (idx, value) {
942                         var option = $('<option></option>');
943                         option.text(value);
944                         option.attr('value', value);
945                         $('#table_alias_select').append(option);
946                     });
947                 } else {
948                     Functions.ajaxShowMessage(response.error, false);
949                 }
950             });
951         }
952     });
953     $('#table_alias_select').on('change', function () {
954         Export.aliasToggleRow($(this));
955         var params = {
956             'ajax_request': true,
957             'server': CommonParams.get('server'),
958             'db': $('#db_alias_select').val(),
959             'table': $(this).val(),
960             'type': 'list-columns'
961         };
962         $.post('ajax.php', params, function (response) {
963             if (response.success === true) {
964                 $.each(response.columns, function (idx, value) {
965                     var option = $('<option></option>');
966                     option.text(value);
967                     option.attr('value', value);
968                     $('#column_alias_select').append(option);
969                 });
970             } else {
971                 Functions.ajaxShowMessage(response.error, false);
972             }
973         });
974     });
975     $('#column_alias_select').on('change', function () {
976         Export.aliasToggleRow($(this));
977     });
978     $('#db_alias_button').on('click', function (e) {
979         e.preventDefault();
980         var db = $('#db_alias_select').val();
981         Export.addAlias(
982             Messages.strAliasDatabase,
983             db,
984             'aliases[' + db + '][alias]',
985             $('#db_alias_name').val()
986         );
987         $('#db_alias_name').val('');
988     });
989     $('#table_alias_button').on('click', function (e) {
990         e.preventDefault();
991         var db = $('#db_alias_select').val();
992         var table = $('#table_alias_select').val();
993         Export.addAlias(
994             Messages.strAliasTable,
995             db + '.' + table,
996             'aliases[' + db + '][tables][' + table + '][alias]',
997             $('#table_alias_name').val()
998         );
999         $('#table_alias_name').val('');
1000     });
1001     $('#column_alias_button').on('click', function (e) {
1002         e.preventDefault();
1003         var db = $('#db_alias_select').val();
1004         var table = $('#table_alias_select').val();
1005         var column = $('#column_alias_select').val();
1006         Export.addAlias(
1007             Messages.strAliasColumn,
1008             db + '.' + table + '.' + column,
1009             'aliases[' + db + '][tables][' + table + '][colums][' + column + ']',
1010             $('#column_alias_name').val()
1011         );
1012         $('#column_alias_name').val('');
1013     });