Translated using Weblate (Turkish)
[phpmyadmin.git] / js / import.js
blobd882d6e2b64e487058cdbfea78e65f6dde8ad8a6
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * Functions used in the import tab
4  *
5  */
8 /**
9  * Toggles the hiding and showing of each plugin's options
10  * according to the currently selected plugin from the dropdown list
11  */
12 function changePluginOpts () {
13     $('#format_specific_opts').find('div.format_specific_options').each(function () {
14         $(this).hide();
15     });
16     var selectedPluginName = $('#plugins').find('option:selected').val();
17     $('#' + selectedPluginName + '_options').fadeIn('slow');
18     if (selectedPluginName === 'csv') {
19         $('#import_notification').text(Messages.strImportCSV);
20     } else {
21         $('#import_notification').text('');
22     }
25 /**
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
28  */
29 function matchFile (fname) {
30     var fnameArray = fname.toLowerCase().split('.');
31     var len = fnameArray.length;
32     if (len !== 0) {
33         var extension = fnameArray[len - 1];
34         if (extension === 'gz' || extension === 'bz2' || extension === 'zip') {
35             len--;
36         }
37         // Only toggle if the format of the file can be imported
38         if ($('select[name=\'format\'] option').filterByValue(fnameArray[len - 1]).length === 1) {
39             $('select[name=\'format\'] option').filterByValue(fnameArray[len - 1]).prop('selected', true);
40             changePluginOpts();
41         }
42     }
45 /**
46  * Unbind all event handlers before tearing down a page
47  */
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');
55 });
57 AJAX.registerOnload('import.js', function () {
58     // import_file_form validation.
59     $(document).on('submit', '#import_file_form', function () {
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"> ' + Messages.strImportDialogMessage + '</div>';
63         var wrongTblNameMsg = '<div class="error"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error">' + Messages.strTableNameDialogMessage + '</div>';
64         var wrongDBNameMsg = '<div class="error"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error">' + Messages.strDBNameDialogMessage + '</div>';
66         if (radioLocalImport.length !== 0) {
67             // remote upload.
69             if (radioImport.is(':checked') && $('#input_import_file').val() === '') {
70                 $('#input_import_file').trigger('focus');
71                 Functions.ajaxShowMessage(fileMsg, false);
72                 return false;
73             }
75             if (radioLocalImport.is(':checked')) {
76                 if ($('#select_local_import_file').length === 0) {
77                     Functions.ajaxShowMessage('<div class="error"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error"> ' + Messages.strNoImportFile + ' </div>', false);
78                     return false;
79                 }
81                 if ($('#select_local_import_file').val() === '') {
82                     $('#select_local_import_file').trigger('focus');
83                     Functions.ajaxShowMessage(fileMsg, false);
84                     return false;
85                 }
86             }
87         } else {
88             // local upload.
89             if ($('#input_import_file').val() === '') {
90                 $('#input_import_file').trigger('focus');
91                 Functions.ajaxShowMessage(fileMsg, false);
92                 return false;
93             }
94             if ($('#text_csv_new_tbl_name').length > 0) {
95                 var newTblName = $('#text_csv_new_tbl_name').val();
96                 if (newTblName.length > 0 && $.trim(newTblName).length === 0) {
97                     Functions.ajaxShowMessage(wrongTblNameMsg, false);
98                     return false;
99                 }
100             }
101             if ($('#text_csv_new_db_name').length > 0) {
102                 var newDBName = $('#text_csv_new_db_name').val();
103                 if (newDBName.length > 0 && $.trim(newDBName).length === 0) {
104                     Functions.ajaxShowMessage(wrongDBNameMsg, false);
105                     return false;
106                 }
107             }
108         }
110         // show progress bar.
111         $('#upload_form_status').css('display', 'inline');
112         $('#upload_form_status_info').css('display', 'inline');
113     });
115     // Initially display the options for the selected plugin
116     changePluginOpts();
118     // Whenever the selected plugin changes, change the options displayed
119     $('#plugins').on('change', function () {
120         changePluginOpts();
121     });
123     $('#input_import_file').on('change', function () {
124         matchFile($(this).val());
125     });
127     $('#select_local_import_file').on('change', function () {
128         matchFile($(this).val());
129     });
131     /*
132      * When the "Browse the server" form is clicked or the "Select from the web server upload directory"
133      * form is clicked, the radio button beside it becomes selected and the other form becomes disabled.
134      */
135     $('#input_import_file').on('focus change', function () {
136         $('#radio_import_file').prop('checked', true);
137         $('#radio_local_import_file').prop('checked', false);
138     });
139     $('#select_local_import_file').on('focus', function () {
140         $('#radio_local_import_file').prop('checked', true);
141         $('#radio_import_file').prop('checked', false);
142     });
144     /**
145      * Set up the interface for Javascript-enabled browsers since the default is for
146      *  Javascript-disabled browsers
147      */
148     $('#scroll_to_options_msg').hide();
149     $('#format_specific_opts').find('div.format_specific_options')
150         .css({
151             'border': 0,
152             'margin': 0,
153             'padding': 0
154         })
155         .find('h3')
156         .remove();
157     // $("form[name=import] *").unwrap();
159     /**
160      * for input element text_csv_enclosed and text_csv_escaped allow just one character to enter.
161      * as mysql allows just one character for these fields,
162      * if first character is escape then allow two including escape character.
163      */
164     $('#text_csv_enclosed').add('#text_csv_escaped').on('keyup', function () {
165         if ($(this).val().length === 2 && $(this).val().charAt(0) !== '\\') {
166             $(this).val($(this).val().substring(0, 1));
167             return false;
168         }
169         return true;
170     });