Merge remote-tracking branch 'origin/master'
[phpmyadmin.git] / js / export.js
blob8d59c6e6d02c31b808658539e7bef7adfea03bea
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 AJAX.registerOnload('export.js', function () {
549     /**
550      * For SQL plugin, if "CREATE TABLE options" is checked/unchecked, check/uncheck each of its sub-options
551      */
552     var $create = $("#checkbox_sql_create_table_statements");
553     var $create_options = $("#ul_create_table_statements").find("input");
554     $create.change(function () {
555         $create_options.prop('checked', $(this).prop("checked"));
556     });
557     $create_options.change(function () {
558         if ($create_options.is(":checked")) {
559             $create.prop('checked', true);
560         }
561     });
563     /**
564      * Disables the view output as text option if the output must be saved as a file
565      */
566     $("#plugins").change(function () {
567         var active_plugin = $("#plugins").find("option:selected").val();
568         var force_file = $("#force_file_" + active_plugin).val();
569         if (force_file == "true") {
570             if ($("#radio_dump_asfile").prop('checked') !== true) {
571                 $("#radio_dump_asfile").prop('checked', true);
572                 toggle_save_to_file();
573             }
574             $("#radio_view_as_text").prop('disabled', true).parent().fadeTo('fast', 0.4);
575         } else {
576             $("#radio_view_as_text").prop('disabled', false).parent().fadeTo('fast', 1);
577         }
578     });
580     $("input[type='radio'][name$='_structure_or_data']").on('change', function () {
581         toggle_structure_data_opts();
582     });
584     $('input[name="table_select[]"]').on('change', function() {
585         toggle_table_select($(this).closest('tr'));
586         check_table_select_all();
587     });
589     $('input[name="table_structure[]"]').on('change', function() {
590         check_table_selected($(this).closest('tr'));
591         check_table_select_all();
592     });
594     $('input[name="table_data[]"]').on('change', function() {
595         check_table_selected($(this).closest('tr'));
596         check_table_select_all();
597     });
599     $('#table_structure_all').on('change', function() {
600         toggle_table_select_all_str();
601         check_selected_tables();
602     });
604     $('#table_data_all').on('change', function() {
605         toggle_table_select_all_data();
606         check_selected_tables();
607     });
609     if ($("input[name='export_type']").val() == 'database') {
610         // Hide structure or data radio buttons
611         $("input[type='radio'][name$='_structure_or_data']").each(function() {
612             var $this = $(this);
613             var name = $this.prop('name');
614             var val = $('input[name="' + name + '"]:checked').val();
615             var name_default = name + '_default';
616             if (!$('input[name="' + name_default + '"]').length) {
617                 $this
618                     .after(
619                         $('<input type="hidden" name="' + name_default + '" value="' + val + '" disabled>')
620                     )
621                     .after(
622                         $('<input type="hidden" name="' + name + '" value="structure_and_data">')
623                     );
624                 $this.parent().find('label').remove();
625             } else {
626                 $this.parent().remove();
627             }
628         });
629         $("input[type='radio'][name$='_structure_or_data']").remove();
631         // Disable CREATE table checkbox for sql
632         var createTableCheckbox = $('#checkbox_sql_create_table');
633         createTableCheckbox.prop('checked', true);
634         var dummyCreateTable = $('#checkbox_sql_create_table')
635             .clone()
636             .removeAttr('id')
637             .attr('type', 'hidden');
638         createTableCheckbox
639             .prop('disabled', true)
640             .after(dummyCreateTable)
641             .parent()
642             .fadeTo('fast', 0.4);
644         setup_table_structure_or_data();
645     }
647     /**
648      * Handle force structure_or_data
649      */
650     $("#plugins").change(setup_table_structure_or_data);
654  * Toggles display of options when quick and custom export are selected
655  */
656 function toggle_quick_or_custom()
658     if ($("input[name='quick_or_custom']").length === 0 // custom_no_form option
659         || $("#radio_custom_export").prop("checked") // custom
660     ) {
661         $("#databases_and_tables").show();
662         $("#rows").show();
663         $("#output").show();
664         $("#format_specific_opts").show();
665         $("#output_quick_export").hide();
666         var selected_plugin_name = $("#plugins").find("option:selected").val();
667         $("#" + selected_plugin_name + "_options").show();
668     } else { // quick
669         $("#databases_and_tables").hide();
670         $("#rows").hide();
671         $("#output").hide();
672         $("#format_specific_opts").hide();
673         $("#output_quick_export").show();
674     }
676 var time_out;
677 function check_time_out(time_limit)
679     if (typeof time_limit === 'undefined' || time_limit === 0) {
680         return true;
681     }
682     //margin of one second to avoid race condition to set/access session variable
683     time_limit = time_limit + 1;
684     var href = "export.php";
685     var params = {
686         'ajax_request' : true,
687         'token' : PMA_commonParams.get('token'),
688         'check_time_out' : true
689     };
690     clearTimeout(time_out);
691     time_out = setTimeout(function(){
692         $.get(href, params, function (data) {
693             if (data.message === 'timeout') {
694                 PMA_ajaxShowMessage(
695                     '<div class="error">' +
696                     PMA_messages.strTimeOutError +
697                     '</div>',
698                     false
699                 );
700             }
701         });
702     }, time_limit * 1000);
707  * Handler for Database/table alias select
709  * @param event object the event object
711  * @return void
712  */
713 function aliasSelectHandler(event) {
714     var sel = event.data.sel;
715     var type = event.data.type;
716     var inputId = $(this).val();
717     var $label = $(this).next('label');
718     $('input#' + $label.attr('for')).addClass('hide');
719     $('input#' + inputId).removeClass('hide');
720     $label.attr('for', inputId);
721     $('#alias_modal ' + sel + '[id$=' + type + ']:visible').addClass('hide');
722     var $inputWrapper = $('#alias_modal ' + sel + '#' + inputId + type);
723     $inputWrapper.removeClass('hide');
724     if (type === '_cols' && $inputWrapper.length > 0) {
725         var outer = $inputWrapper[0].outerHTML;
726         // Replace opening tags
727         var regex = /<dummy_inp/gi;
728         if (outer.match(regex)) {
729             var newTag = outer.replace(regex, '<input');
730             // Replace closing tags
731             regex = /<\/dummy_inp/gi;
732             newTag = newTag.replace(regex, '</input');
733             // Assign replacement
734             $inputWrapper.replaceWith(newTag);
735         }
736     } else if (type === '_tables') {
737         $('.table_alias_select:visible').change();
738     }
739     $("#alias_modal").dialog("option", "position", "center");
743  * Handler for Alias dialog box
745  * @param event object the event object
747  * @return void
748  */
749 function createAliasModal(event) {
750     event.preventDefault();
751     var dlgButtons = {};
752     dlgButtons[PMA_messages.strResetAll] = function() {
753         $(this).find('input[type="text"]').val('');
754     };
755     dlgButtons[PMA_messages.strReset] = function() {
756         $(this).find('input[type="text"]:visible').val('');
757     };
758     dlgButtons[PMA_messages.strSaveAndClose] = function() {
759         $(this).dialog("close");
760         // do not fillup form submission with empty values
761         $.each($(this).find('input[type="text"]'), function (i, e) {
762             if ($(e).val().trim().length == 0) {
763                 $(e).prop('disabled', true);
764             }
765         });
766         $('#alias_modal').parent().appendTo($('form[name="dump"]'));
767     };
768     $('#alias_modal').find('input[type="text"]').prop('disabled', false);
769     $('#alias_modal').dialog({
770         width: Math.min($(window).width() - 100, 700),
771         maxHeight: $(window).height(),
772         modal: true,
773         dialogClass: "alias-dialog",
774         buttons: dlgButtons,
775         create: function() {
776             $(this).css('maxHeight', $(window).height() - 150);
777             $('.alias-dialog .ui-dialog-titlebar-close').remove();
778         },
779         close: function() {
780             var isEmpty = true;
781             $(this).find('input[type="text"]').each(function() {
782                 // trim input fields on close
783                 $(this).val($(this).val().trim());
784                 // check if non empty field present
785                 if ($(this).val()) {
786                     isEmpty = false;
787                 }
788             });
789             $('input#btn_alias_config').prop('checked', !isEmpty);
790         },
791         position: { my: "center top", at: "center top", of: window }
792     });
793     // Call change event of .table_alias_select
794     $('.table_alias_select:visible').trigger('change');
797 AJAX.registerOnload('export.js', function () {
798     $("input[type='radio'][name='quick_or_custom']").change(toggle_quick_or_custom);
800     $("#scroll_to_options_msg").hide();
801     $("#format_specific_opts").find("div.format_specific_options")
802         .hide()
803         .css({
804             "border": 0,
805             "margin": 0,
806             "padding": 0
807         })
808         .find("h3")
809         .remove();
810     toggle_quick_or_custom();
811     toggle_structure_data_opts();
812     toggle_sql_include_comments();
814     /**
815      * Initially disables the "Dump some row(s)" sub-options
816      */
817     disable_dump_some_rows_sub_options();
819     /**
820      * Disables the "Dump some row(s)" sub-options when it is not selected
821      */
822     $("input[type='radio'][name='allrows']").change(function () {
823         if ($("input[type='radio'][name='allrows']").prop("checked")) {
824             enable_dump_some_rows_sub_options();
825         } else {
826             disable_dump_some_rows_sub_options();
827         }
828     });
830     // Open Alias Modal Dialog on click
831     $('#btn_alias_config').on('click', createAliasModal);
833     // Database alias select on change event
834     $('#db_alias_select').on(
835         'change',
836         {sel: 'span', type: '_tables'},
837         aliasSelectHandler
838     );
840     // Table alias select on change event
841     $('.table_alias_select').on(
842         'change',
843         {sel: 'table', type: '_cols'},
844         aliasSelectHandler
845     );