1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * Functions used in the import tab
9 * Toggles the hiding and showing of each plugin's options
10 * according to the currently selected plugin from the dropdown list
12 function changePluginOpts () {
13 $('#format_specific_opts').find('div.format_specific_options').each(function () {
16 var selected_plugin_name = $('#plugins').find('option:selected').val();
17 $('#' + selected_plugin_name + '_options').fadeIn('slow');
18 if (selected_plugin_name === 'csv') {
19 $('#import_notification').text(PMA_messages.strImportCSV);
21 $('#import_notification').text('');
26 * Toggles the hiding and showing of each plugin's options and sets the selected value
27 * in the plugin dropdown list according to the format of the selected file
29 function matchFile (fname) {
30 var fname_array = fname.toLowerCase().split('.');
31 var len = fname_array.length;
33 var extension = fname_array[len - 1];
34 if (extension === 'gz' || extension === 'bz2' || extension === 'zip') {
37 // Only toggle if the format of the file can be imported
38 if ($('select[name=\'format\'] option').filterByValue(fname_array[len - 1]).length === 1) {
39 $('select[name=\'format\'] option').filterByValue(fname_array[len - 1]).prop('selected', true);
46 * Unbind all event handlers before tearing down a page
48 AJAX.registerTeardown('import.js', function () {
49 $('#plugins').off('change');
50 $('#input_import_file').off('change');
51 $('#select_local_import_file').off('change');
52 $('#input_import_file').off('change').off('focus');
53 $('#select_local_import_file').off('focus');
54 $('#text_csv_enclosed').add('#text_csv_escaped').off('keyup');
57 AJAX.registerOnload('import.js', function () {
58 // import_file_form validation.
59 $(document).on('submit', '#import_file_form', function (event) {
60 var radioLocalImport = $('#radio_local_import_file');
61 var radioImport = $('#radio_import_file');
62 var fileMsg = '<div class="error"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error" /> ' + PMA_messages.strImportDialogMessage + '</div>';
64 if (radioLocalImport.length !== 0) {
67 if (radioImport.is(':checked') && $('#input_import_file').val() === '') {
68 $('#input_import_file').focus();
69 PMA_ajaxShowMessage(fileMsg, false);
73 if (radioLocalImport.is(':checked')) {
74 if ($('#select_local_import_file').length === 0) {
75 PMA_ajaxShowMessage('<div class="error"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error" /> ' + PMA_messages.strNoImportFile + ' </div>', false);
79 if ($('#select_local_import_file').val() === '') {
80 $('#select_local_import_file').focus();
81 PMA_ajaxShowMessage(fileMsg, false);
87 if ($('#input_import_file').val() === '') {
88 $('#input_import_file').focus();
89 PMA_ajaxShowMessage(fileMsg, false);
95 $('#upload_form_status').css('display', 'inline');
96 $('#upload_form_status_info').css('display', 'inline');
99 // Initially display the options for the selected plugin
102 // Whenever the selected plugin changes, change the options displayed
103 $('#plugins').change(function () {
107 $('#input_import_file').change(function () {
108 matchFile($(this).val());
111 $('#select_local_import_file').change(function () {
112 matchFile($(this).val());
116 * When the "Browse the server" form is clicked or the "Select from the web server upload directory"
117 * form is clicked, the radio button beside it becomes selected and the other form becomes disabled.
119 $('#input_import_file').on('focus change', function () {
120 $('#radio_import_file').prop('checked', true);
121 $('#radio_local_import_file').prop('checked', false);
123 $('#select_local_import_file').focus(function () {
124 $('#radio_local_import_file').prop('checked', true);
125 $('#radio_import_file').prop('checked', false);
129 * Set up the interface for Javascript-enabled browsers since the default is for
130 * Javascript-disabled browsers
132 $('#scroll_to_options_msg').hide();
133 $('#format_specific_opts').find('div.format_specific_options')
141 // $("form[name=import] *").unwrap();
144 * for input element text_csv_enclosed and text_csv_escaped allow just one character to enter.
145 * as mysql allows just one character for these fields,
146 * if first character is escape then allow two including escape character.
148 $('#text_csv_enclosed').add('#text_csv_escaped').on('keyup', function () {
149 if ($(this).val().length === 2 && $(this).val().charAt(0) !== '\\') {
150 $(this).val($(this).val().substring(0, 1));