Translated using Weblate (Interlingua)
[phpmyadmin.git] / js / export.js
bloba0da0f251e64ea9b5b1b7b4fd723ea8d919f8bee
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * Functions used in the export tab
4  *
5  */
7 /**
8  * Disables the "Dump some row(s)" sub-options
9  */
10 function disable_dump_some_rows_sub_options()
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');
18 /**
19  * Enables the "Dump some row(s)" sub-options
20  */
21 function enable_dump_some_rows_sub_options()
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 function getTemplateData()
36     var $form = $('form[name="dump"]');
37     var blacklist = ['token', 'server', 'db', 'table', 'single_table',
38         'export_type', 'export_method', 'sql_query', 'template_id'];
39     var obj = {};
40     var arr = $form.serializeArray();
41     $.each(arr, function () {
42         if ($.inArray(this.name, blacklist) < 0) {
43             if (obj[this.name] !== undefined) {
44                 if (! obj[this.name].push) {
45                     obj[this.name] = [obj[this.name]];
46                 }
47                 obj[this.name].push(this.value || '');
48             } else {
49                 obj[this.name] = this.value || '';
50             }
51         }
52     });
53     // include unchecked checboxes (which are ignored by serializeArray()) with null
54     // to uncheck them when loading the template
55     $form.find('input[type="checkbox"]:not(:checked)').each(function () {
56         if (obj[this.name] === undefined) {
57             obj[this.name] = null;
58         }
59     });
60     // include empty multiselects
61     $form.find('select').each(function () {
62         if ($(this).find('option:selected').length == 0) {
63             obj[this.name] = [];
64         }
65     });
66     return obj;
69 /**
70  * Create a template with selected options
71  *
72  * @param name name of the template
73  */
74 function createTemplate(name)
76     var templateData = getTemplateData();
78     var params = {
79         ajax_request : true,
80         token : PMA_commonParams.get('token'),
81         server : PMA_commonParams.get('server'),
82         db : PMA_commonParams.get('db'),
83         table : PMA_commonParams.get('table'),
84         exportType : $('input[name="export_type"]').val(),
85         templateAction : 'create',
86         templateName : name,
87         templateData : JSON.stringify(templateData)
88     };
90     PMA_ajaxShowMessage();
91     $.post('tbl_export.php', params, function (response) {
92         if (response.success === true) {
93             $('#templateName').val('');
94             $('#template').html(response.data);
95             $("#template").find("option").each(function() {
96                 if ($(this).text() == name) {
97                     $(this).prop('selected', true);
98                 }
99             });
100             PMA_ajaxShowMessage(PMA_messages.strTemplateCreated);
101         } else {
102             PMA_ajaxShowMessage(response.error, false);
103         }
104     });
108  * Loads a template
110  * @param id ID of the template to load
111  */
112 function loadTemplate(id)
114     var params = {
115         ajax_request : true,
116         token : PMA_commonParams.get('token'),
117         server : PMA_commonParams.get('server'),
118         db : PMA_commonParams.get('db'),
119         table : PMA_commonParams.get('table'),
120         exportType : $('input[name="export_type"]').val(),
121         templateAction : 'load',
122         templateId : id,
123     };
125     PMA_ajaxShowMessage();
126     $.post('tbl_export.php', params, function (response) {
127         if (response.success === true) {
128             var $form = $('form[name="dump"]');
129             var options = $.parseJSON(response.data);
130             $.each(options, function (key, value) {
131                 var $element = $form.find('[name="' + key + '"]');
132                 if ($element.length) {
133                     if (($element.is('input') && $element.attr('type') == 'checkbox') && value === null) {
134                         $element.prop('checked', false);
135                     } else {
136                         if (($element.is('input') && $element.attr('type') == 'checkbox') ||
137                             ($element.is('input') && $element.attr('type') == 'radio') ||
138                             ($element.is('select') && $element.attr('multiple') == 'multiple')) {
139                             if (! value.push) {
140                                 value = [value];
141                             }
142                         }
143                         $element.val(value);
144                     }
145                     $element.trigger('change');
146                 }
147             });
148             $('input[name="template_id"]').val(id);
149             PMA_ajaxShowMessage(PMA_messages.strTemplateLoaded);
150         } else {
151             PMA_ajaxShowMessage(response.error, false);
152         }
153     });
157  * Updates an existing template with current options
159  * @param id ID of the template to update
160  */
161 function updateTemplate(id)
163     var templateData = getTemplateData();
165     var params = {
166         ajax_request : true,
167         token : PMA_commonParams.get('token'),
168         server : PMA_commonParams.get('server'),
169         db : PMA_commonParams.get('db'),
170         table : PMA_commonParams.get('table'),
171         exportType : $('input[name="export_type"]').val(),
172         templateAction : 'update',
173         templateId : id,
174         templateData : JSON.stringify(templateData)
175     };
177     PMA_ajaxShowMessage();
178     $.post('tbl_export.php', params, function (response) {
179         if (response.success === true) {
180             PMA_ajaxShowMessage(PMA_messages.strTemplateUpdated);
181         } else {
182             PMA_ajaxShowMessage(response.error, false);
183         }
184     });
188  * Delete a template
190  * @param id ID of the template to delete
191  */
192 function deleteTemplate(id)
194     var params = {
195         ajax_request : true,
196         token : PMA_commonParams.get('token'),
197         server : PMA_commonParams.get('server'),
198         db : PMA_commonParams.get('db'),
199         table : PMA_commonParams.get('table'),
200         exportType : $('input[name="export_type"]').val(),
201         templateAction : 'delete',
202         templateId : id,
203     };
205     PMA_ajaxShowMessage();
206     $.post('tbl_export.php', params, function (response) {
207         if (response.success === true) {
208             $('#template').find('option[value="' + id + '"]').remove();
209             PMA_ajaxShowMessage(PMA_messages.strTemplateDeleted);
210         } else {
211             PMA_ajaxShowMessage(response.error, false);
212         }
213     });
217  * Unbind all event handlers before tearing down a page
218  */
219 AJAX.registerTeardown('export.js', function () {
220     $("#plugins").unbind('change');
221     $("input[type='radio'][name='sql_structure_or_data']").unbind('change');
222     $("input[type='radio'][name$='_structure_or_data']").off('change');
223     $("input[type='radio'][name='output_format']").unbind('change');
224     $("#checkbox_sql_include_comments").unbind('change');
225     $("input[type='radio'][name='quick_or_custom']").unbind('change');
226     $("input[type='radio'][name='allrows']").unbind('change');
227     $('#btn_alias_config').off('click');
228     $('#db_alias_select').off('change');
229     $('.table_alias_select').off('change');
230     $('input[name="table_select[]"]').off('change');
231     $('input[name="table_structure[]"]').off('change');
232     $('input[name="table_data[]"]').off('change');
233     $('#table_structure_all').off('change');
234     $('#table_data_all').off('change');
235     $('input[name="createTemplate"]').off('click');
236     $('select[name="template"]').off('change');
237     $('input[name="updateTemplate"]').off('click');
238     $('input[name="deleteTemplate"]').off('click');
241 AJAX.registerOnload('export.js', function () {
243     /**
244      * Export template handling code
245      */
246     // create a new template
247     $('input[name="createTemplate"]').on('click', function (e) {
248         e.preventDefault();
249         var name = $('input[name="templateName"]').val();
250         if (name.length) {
251             createTemplate(name);
252         }
253     });
255     // load an existing template
256     $('select[name="template"]').on('change', function (e) {
257         e.preventDefault();
258         var id = $(this).val();
259         if (id.length) {
260             loadTemplate(id);
261         }
262     });
264     // udpate an existing template with new criteria
265     $('input[name="updateTemplate"]').on('click', function (e) {
266         e.preventDefault();
267         var id = $('select[name="template"]').val();
268         if (id.length) {
269             updateTemplate(id);
270         }
271     });
273     // delete an existing template
274     $('input[name="deleteTemplate"]').on('click', function (e) {
275         e.preventDefault();
276         var id = $('select[name="template"]').val();
277         if (id.length) {
278             deleteTemplate(id);
279         }
280     });
282     /**
283      * Toggles the hiding and showing of each plugin's options
284      * according to the currently selected plugin from the dropdown list
285      */
286     $("#plugins").change(function () {
287         $("#format_specific_opts").find("div.format_specific_options").hide();
288         var selected_plugin_name = $("#plugins").find("option:selected").val();
289         $("#" + selected_plugin_name + "_options").show();
290     });
292     /**
293      * Toggles the enabling and disabling of the SQL plugin's comment options that apply only when exporting structure
294      */
295     $("input[type='radio'][name='sql_structure_or_data']").change(function () {
296         var comments_are_present = $("#checkbox_sql_include_comments").prop("checked");
297         var show = $("input[type='radio'][name='sql_structure_or_data']:checked").val();
298         if (show == 'data') {
299             // disable the SQL comment options
300             if (comments_are_present) {
301                 $("#checkbox_sql_dates").prop('disabled', true).parent().fadeTo('fast', 0.4);
302             }
303             $("#checkbox_sql_relation").prop('disabled', true).parent().fadeTo('fast', 0.4);
304             $("#checkbox_sql_mime").prop('disabled', true).parent().fadeTo('fast', 0.4);
305         } else {
306             // enable the SQL comment options
307             if (comments_are_present) {
308                 $("#checkbox_sql_dates").prop('disabled', false).parent().fadeTo('fast', 1);
309             }
310             $("#checkbox_sql_relation").prop('disabled', false).parent().fadeTo('fast', 1);
311             $("#checkbox_sql_mime").prop('disabled', false).parent().fadeTo('fast', 1);
312         }
314         if (show == 'structure') {
315             $('#checkbox_sql_auto_increment').prop('disabled', true).parent().fadeTo('fast', 0.4);
316         } else {
317             $("#checkbox_sql_auto_increment").prop('disabled', false).parent().fadeTo('fast', 1);
318         }
319     });
321     // For separate-file exports only ZIP compression is allowed
322     $('input[type="checkbox"][name="as_separate_files"]').change(function(){
323         if ($(this).is(':checked')) {
324             $('#compression').val('zip');
325         }
326     });
328     $('#compression').change(function(){
329         if ($('option:selected').val() !== 'zip') {
330             $('input[type="checkbox"][name="as_separate_files"]').prop('checked', false);
331         }
332     });
336 function setup_table_structure_or_data() {
337     if ($("input[name='export_type']").val() != 'database') {
338         return;
339     }
340     var pluginName = $("#plugins").find("option:selected").val();
341     var formElemName = pluginName + "_structure_or_data";
342     var force_structure_or_data = !($("input[name='" + formElemName + "_default']").length);
344     if (force_structure_or_data === true) {
345         $('input[name="structure_or_data_forced"]').val(1);
346         $('.export_structure input[type="checkbox"], .export_data input[type="checkbox"]')
347             .prop('disabled', true);
348         $('.export_structure, .export_data').fadeTo('fast', 0.4);
349     } else {
350         $('input[name="structure_or_data_forced"]').val(0);
351         $('.export_structure input[type="checkbox"], .export_data input[type="checkbox"]')
352             .prop('disabled', false);
353         $('.export_structure, .export_data').fadeTo('fast', 1);
355         var structure_or_data = $('input[name="' + formElemName + '_default"]').val();
357         if (structure_or_data == 'structure') {
358             $('.export_data input[type="checkbox"]')
359                 .prop('checked', false);
360         } else if (structure_or_data == 'data') {
361             $('.export_structure input[type="checkbox"]')
362                 .prop('checked', false);
363         }
364         if (structure_or_data == 'structure' || structure_or_data == 'structure_and_data') {
365             if (!$('.export_structure input[type="checkbox"]:checked').length) {
366                 $('input[name="table_select[]"]:checked')
367                     .closest('tr')
368                     .find('.export_structure input[type="checkbox"]')
369                     .prop('checked', true);
370             }
371         }
372         if (structure_or_data == 'data' || structure_or_data == 'structure_and_data') {
373             if (!$('.export_data input[type="checkbox"]:checked').length) {
374                 $('input[name="table_select[]"]:checked')
375                     .closest('tr')
376                     .find('.export_data input[type="checkbox"]')
377                     .prop('checked', true);
378             }
379         }
381         check_selected_tables();
382         check_table_select_all();
383     }
387  * Toggles the hiding and showing of plugin structure-specific and data-specific
388  * options
389  */
390 function toggle_structure_data_opts()
392     var pluginName = $("select#plugins").val();
393     var radioFormName = pluginName + "_structure_or_data";
394     var dataDiv = "#" + pluginName + "_data";
395     var structureDiv = "#" + pluginName + "_structure";
396     var show = $("input[type='radio'][name='" + radioFormName + "']:checked").val();
397     if (show == 'data') {
398         $(dataDiv).slideDown('slow');
399         $(structureDiv).slideUp('slow');
400     } else {
401         $(structureDiv).slideDown('slow');
402         if (show == 'structure') {
403             $(dataDiv).slideUp('slow');
404         } else {
405             $(dataDiv).slideDown('slow');
406         }
407     }
411  * Toggles the disabling of the "save to file" options
412  */
413 function toggle_save_to_file()
415     var $ulSaveAsfile = $("#ul_save_asfile");
416     if (!$("#radio_dump_asfile").prop("checked")) {
417         $ulSaveAsfile.find("> li").fadeTo('fast', 0.4);
418         $ulSaveAsfile.find("> li > input").prop('disabled', true);
419         $ulSaveAsfile.find("> li > select").prop('disabled', true);
420     } else {
421         $ulSaveAsfile.find("> li").fadeTo('fast', 1);
422         $ulSaveAsfile.find("> li > input").prop('disabled', false);
423         $ulSaveAsfile.find("> li > select").prop('disabled', false);
424     }
427 AJAX.registerOnload('export.js', function () {
428     toggle_save_to_file();
429     $("input[type='radio'][name='output_format']").change(toggle_save_to_file);
433  * For SQL plugin, toggles the disabling of the "display comments" options
434  */
435 function toggle_sql_include_comments()
437     $("#checkbox_sql_include_comments").change(function () {
438         var $ulIncludeComments = $("#ul_include_comments");
439         if (!$("#checkbox_sql_include_comments").prop("checked")) {
440             $ulIncludeComments.find("> li").fadeTo('fast', 0.4);
441             $ulIncludeComments.find("> li > input").prop('disabled', true);
442         } else {
443             // If structure is not being exported, the comment options for structure should not be enabled
444             if ($("#radio_sql_structure_or_data_data").prop("checked")) {
445                 $("#text_sql_header_comment").prop('disabled', false).parent("li").fadeTo('fast', 1);
446             } else {
447                 $ulIncludeComments.find("> li").fadeTo('fast', 1);
448                 $ulIncludeComments.find("> li > input").prop('disabled', false);
449             }
450         }
451     });
454 function check_table_select_all() {
455     var total = $('input[name="table_select[]"]').length;
456     var str_checked = $('input[name="table_structure[]"]:checked').length;
457     var data_checked = $('input[name="table_data[]"]:checked').length;
458     var str_all = $('#table_structure_all');
459     var data_all = $('#table_data_all');
461     if (str_checked == total) {
462         str_all
463             .prop("indeterminate", false)
464             .prop('checked', true);
465     } else if (str_checked === 0) {
466         str_all
467             .prop("indeterminate", false)
468             .prop('checked', false);
469     } else {
470         str_all
471             .prop("indeterminate", true)
472             .prop('checked', false);
473     }
475     if (data_checked == total) {
476         data_all
477             .prop("indeterminate", false)
478             .prop('checked', true);
479     } else if (data_checked === 0) {
480         data_all
481             .prop("indeterminate", false)
482             .prop('checked', false);
483     } else {
484         data_all
485             .prop("indeterminate", true)
486             .prop('checked', false);
487     }
490 function toggle_table_select_all_str() {
491     var str_all = $('#table_structure_all').is(':checked');
492     if (str_all) {
493         $('input[name="table_structure[]"]').prop('checked', true);
494     } else {
495         $('input[name="table_structure[]"]').prop('checked', false);
496     }
499 function toggle_table_select_all_data() {
500     var data_all = $('#table_data_all').is(':checked');
501     if (data_all) {
502         $('input[name="table_data[]"]').prop('checked', true);
503     } else {
504         $('input[name="table_data[]"]').prop('checked', false);
505     }
508 function check_selected_tables(argument) {
509     $('.export_table_select tbody tr').each(function() {
510         check_table_selected(this);
511     });
514 function check_table_selected(row) {
515     var $row = $(row);
516     var table_select = $row.find('input[name="table_select[]"]');
517     var str_check = $row.find('input[name="table_structure[]"]');
518     var data_check = $row.find('input[name="table_data[]"]');
520     var data = data_check.is(':checked:not(:disabled)');
521     var structure = str_check.is(':checked:not(:disabled)');
523     if (data && structure) {
524         table_select.prop({checked: true, indeterminate: false});
525         $row.addClass('marked');
526     } else if (data || structure) {
527         table_select.prop({checked: true, indeterminate: true});
528         $row.removeClass('marked');
529     } else {
530         table_select.prop({checked: false, indeterminate: false});
531         $row.removeClass('marked');
532     }
535 function toggle_table_select(row) {
536     var $row = $(row);
537     var table_selected = $row.find('input[name="table_select[]"]').is(':checked');
539     if (table_selected) {
540         $row.find('input[type="checkbox"]:not(:disabled)').prop('checked', true);
541         $row.addClass('marked');
542     } else {
543         $row.find('input[type="checkbox"]:not(:disabled)').prop('checked', false);
544         $row.removeClass('marked');
545     }
548 function handleAddProcCheckbox() {
549     if ($('#table_structure_all').is(':checked') === true
550         && $('#table_data_all').is(':checked') === true
551     ) {
552         $('#checkbox_sql_procedure_function').prop('checked', true);
553     } else {
554         $('#checkbox_sql_procedure_function').prop('checked', false);
555     }
558 AJAX.registerOnload('export.js', function () {
559     /**
560      * For SQL plugin, if "CREATE TABLE options" is checked/unchecked, check/uncheck each of its sub-options
561      */
562     var $create = $("#checkbox_sql_create_table_statements");
563     var $create_options = $("#ul_create_table_statements").find("input");
564     $create.change(function () {
565         $create_options.prop('checked', $(this).prop("checked"));
566     });
567     $create_options.change(function () {
568         if ($create_options.is(":checked")) {
569             $create.prop('checked', true);
570         }
571     });
573     /**
574      * Disables the view output as text option if the output must be saved as a file
575      */
576     $("#plugins").change(function () {
577         var active_plugin = $("#plugins").find("option:selected").val();
578         var force_file = $("#force_file_" + active_plugin).val();
579         if (force_file == "true") {
580             if ($("#radio_dump_asfile").prop('checked') !== true) {
581                 $("#radio_dump_asfile").prop('checked', true);
582                 toggle_save_to_file();
583             }
584             $("#radio_view_as_text").prop('disabled', true).parent().fadeTo('fast', 0.4);
585         } else {
586             $("#radio_view_as_text").prop('disabled', false).parent().fadeTo('fast', 1);
587         }
588     });
590     $("input[type='radio'][name$='_structure_or_data']").on('change', function () {
591         toggle_structure_data_opts();
592     });
594     $('input[name="table_select[]"]').on('change', function() {
595         toggle_table_select($(this).closest('tr'));
596         check_table_select_all();
597         handleAddProcCheckbox();
598     });
600     $('input[name="table_structure[]"]').on('change', function() {
601         check_table_selected($(this).closest('tr'));
602         check_table_select_all();
603         handleAddProcCheckbox();
604     });
606     $('input[name="table_data[]"]').on('change', function() {
607         check_table_selected($(this).closest('tr'));
608         check_table_select_all();
609         handleAddProcCheckbox();
610     });
612     $('#table_structure_all').on('change', function() {
613         toggle_table_select_all_str();
614         check_selected_tables();
615         handleAddProcCheckbox();
616     });
618     $('#table_data_all').on('change', function() {
619         toggle_table_select_all_data();
620         check_selected_tables();
621         handleAddProcCheckbox();
622     });
624     if ($("input[name='export_type']").val() == 'database') {
625         // Hide structure or data radio buttons
626         $("input[type='radio'][name$='_structure_or_data']").each(function() {
627             var $this = $(this);
628             var name = $this.prop('name');
629             var val = $('input[name="' + name + '"]:checked').val();
630             var name_default = name + '_default';
631             if (!$('input[name="' + name_default + '"]').length) {
632                 $this
633                     .after(
634                         $('<input type="hidden" name="' + name_default + '" value="' + val + '" disabled>')
635                     )
636                     .after(
637                         $('<input type="hidden" name="' + name + '" value="structure_and_data">')
638                     );
639                 $this.parent().find('label').remove();
640             } else {
641                 $this.parent().remove();
642             }
643         });
644         $("input[type='radio'][name$='_structure_or_data']").remove();
646         // Disable CREATE table checkbox for sql
647         var createTableCheckbox = $('#checkbox_sql_create_table');
648         createTableCheckbox.prop('checked', true);
649         var dummyCreateTable = $('#checkbox_sql_create_table')
650             .clone()
651             .removeAttr('id')
652             .attr('type', 'hidden');
653         createTableCheckbox
654             .prop('disabled', true)
655             .after(dummyCreateTable)
656             .parent()
657             .fadeTo('fast', 0.4);
659         setup_table_structure_or_data();
660     }
662     /**
663      * Handle force structure_or_data
664      */
665     $("#plugins").change(setup_table_structure_or_data);
669  * Toggles display of options when quick and custom export are selected
670  */
671 function toggle_quick_or_custom()
673     if ($("input[name='quick_or_custom']").length === 0 // custom_no_form option
674         || $("#radio_custom_export").prop("checked") // custom
675     ) {
676         $("#databases_and_tables").show();
677         $("#rows").show();
678         $("#output").show();
679         $("#format_specific_opts").show();
680         $("#output_quick_export").hide();
681         var selected_plugin_name = $("#plugins").find("option:selected").val();
682         $("#" + selected_plugin_name + "_options").show();
683     } else { // quick
684         $("#databases_and_tables").hide();
685         $("#rows").hide();
686         $("#output").hide();
687         $("#format_specific_opts").hide();
688         $("#output_quick_export").show();
689     }
691 var time_out;
692 function check_time_out(time_limit)
694     if (typeof time_limit === 'undefined' || time_limit === 0) {
695         return true;
696     }
697     //margin of one second to avoid race condition to set/access session variable
698     time_limit = time_limit + 1;
699     var href = "export.php";
700     var params = {
701         'ajax_request' : true,
702         'token' : PMA_commonParams.get('token'),
703         'check_time_out' : true
704     };
705     clearTimeout(time_out);
706     time_out = setTimeout(function(){
707         $.get(href, params, function (data) {
708             if (data.message === 'timeout') {
709                 PMA_ajaxShowMessage(
710                     '<div class="error">' +
711                     PMA_messages.strTimeOutError +
712                     '</div>',
713                     false
714                 );
715             }
716         });
717     }, time_limit * 1000);
722  * Handler for Database/table alias select
724  * @param event object the event object
726  * @return void
727  */
728 function aliasSelectHandler(event) {
729     var sel = event.data.sel;
730     var type = event.data.type;
731     var inputId = $(this).val();
732     var $label = $(this).next('label');
733     $('input#' + $label.attr('for')).addClass('hide');
734     $('input#' + inputId).removeClass('hide');
735     $label.attr('for', inputId);
736     $('#alias_modal ' + sel + '[id$=' + type + ']:visible').addClass('hide');
737     var $inputWrapper = $('#alias_modal ' + sel + '#' + inputId + type);
738     $inputWrapper.removeClass('hide');
739     if (type === '_cols' && $inputWrapper.length > 0) {
740         var outer = $inputWrapper[0].outerHTML;
741         // Replace opening tags
742         var regex = /<dummy_inp/gi;
743         if (outer.match(regex)) {
744             var newTag = outer.replace(regex, '<input');
745             // Replace closing tags
746             regex = /<\/dummy_inp/gi;
747             newTag = newTag.replace(regex, '</input');
748             // Assign replacement
749             $inputWrapper.replaceWith(newTag);
750         }
751     } else if (type === '_tables') {
752         $('.table_alias_select:visible').change();
753     }
754     $("#alias_modal").dialog("option", "position", "center");
758  * Handler for Alias dialog box
760  * @param event object the event object
762  * @return void
763  */
764 function createAliasModal(event) {
765     event.preventDefault();
766     var dlgButtons = {};
767     dlgButtons[PMA_messages.strResetAll] = function() {
768         $(this).find('input[type="text"]').val('');
769     };
770     dlgButtons[PMA_messages.strReset] = function() {
771         $(this).find('input[type="text"]:visible').val('');
772     };
773     dlgButtons[PMA_messages.strSaveAndClose] = function() {
774         $(this).dialog("close");
775         // do not fillup form submission with empty values
776         $.each($(this).find('input[type="text"]'), function (i, e) {
777             if ($(e).val().trim().length == 0) {
778                 $(e).prop('disabled', true);
779             }
780         });
781         $('#alias_modal').parent().appendTo($('form[name="dump"]'));
782     };
783     $('#alias_modal').find('input[type="text"]').prop('disabled', false);
784     $('#alias_modal').dialog({
785         width: Math.min($(window).width() - 100, 700),
786         maxHeight: $(window).height(),
787         modal: true,
788         dialogClass: "alias-dialog",
789         buttons: dlgButtons,
790         create: function() {
791             $(this).css('maxHeight', $(window).height() - 150);
792             $('.alias-dialog .ui-dialog-titlebar-close').remove();
793         },
794         close: function() {
795             var isEmpty = true;
796             $(this).find('input[type="text"]').each(function() {
797                 // trim input fields on close
798                 $(this).val($(this).val().trim());
799                 // check if non empty field present
800                 if ($(this).val()) {
801                     isEmpty = false;
802                 }
803             });
804             $('input#btn_alias_config').prop('checked', !isEmpty);
805         },
806         position: { my: "center top", at: "center top", of: window }
807     });
808     // Call change event of .table_alias_select
809     $('.table_alias_select:visible').trigger('change');
812 AJAX.registerOnload('export.js', function () {
813     $("input[type='radio'][name='quick_or_custom']").change(toggle_quick_or_custom);
815     $("#scroll_to_options_msg").hide();
816     $("#format_specific_opts").find("div.format_specific_options")
817         .hide()
818         .css({
819             "border": 0,
820             "margin": 0,
821             "padding": 0
822         })
823         .find("h3")
824         .remove();
825     toggle_quick_or_custom();
826     toggle_structure_data_opts();
827     toggle_sql_include_comments();
828     check_table_select_all();
829     handleAddProcCheckbox();
831     /**
832      * Initially disables the "Dump some row(s)" sub-options
833      */
834     disable_dump_some_rows_sub_options();
836     /**
837      * Disables the "Dump some row(s)" sub-options when it is not selected
838      */
839     $("input[type='radio'][name='allrows']").change(function () {
840         if ($("input[type='radio'][name='allrows']").prop("checked")) {
841             enable_dump_some_rows_sub_options();
842         } else {
843             disable_dump_some_rows_sub_options();
844         }
845     });
847     // Open Alias Modal Dialog on click
848     $('#btn_alias_config').on('click', createAliasModal);
850     // Database alias select on change event
851     $('#db_alias_select').on(
852         'change',
853         {sel: 'span', type: '_tables'},
854         aliasSelectHandler
855     );
857     // Table alias select on change event
858     $('.table_alias_select').on(
859         'change',
860         {sel: 'table', type: '_cols'},
861         aliasSelectHandler
862     );