2 * Functions used in the import tab
8 * Toggles the hiding and showing of each plugin's options
9 * according to the currently selected plugin from the dropdown list
11 function changePluginOpts () {
12 $('#format_specific_opts').find('div.format_specific_options').each(function () {
15 var selectedPluginName = $('#plugins').find('option:selected').val();
16 $('#' + selectedPluginName + '_options').fadeIn('slow');
17 if (selectedPluginName === 'csv') {
18 $('#import_notification').text(Messages.strImportCSV);
20 $('#import_notification').text('');
25 * Toggles the hiding and showing of each plugin's options and sets the selected value
26 * in the plugin dropdown list according to the format of the selected file
28 function matchFile (fname) {
29 var fnameArray = fname.toLowerCase().split('.');
30 var len = fnameArray.length;
32 var extension = fnameArray[len - 1];
33 if (extension === 'gz' || extension === 'bz2' || extension === 'zip') {
36 // Only toggle if the format of the file can be imported
37 if ($('select[name=\'format\'] option').filterByValue(fnameArray[len - 1]).length === 1) {
38 $('select[name=\'format\'] option').filterByValue(fnameArray[len - 1]).prop('selected', true);
45 * Unbind all event handlers before tearing down a page
47 AJAX.registerTeardown('import.js', function () {
48 $('#plugins').off('change');
49 $('#input_import_file').off('change');
50 $('#select_local_import_file').off('change');
51 $('#input_import_file').off('change').off('focus');
52 $('#select_local_import_file').off('focus');
53 $('#text_csv_enclosed').add('#text_csv_escaped').off('keyup');
56 AJAX.registerOnload('import.js', function () {
57 // import_file_form validation.
58 $(document).on('submit', '#import_file_form', function () {
59 var radioLocalImport = $('#radio_local_import_file');
60 var radioImport = $('#radio_import_file');
61 var fileMsg = '<div class="alert alert-danger" role="alert"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error"> ' + Messages.strImportDialogMessage + '</div>';
62 var wrongTblNameMsg = '<div class="alert alert-danger" role="alert"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error">' + Messages.strTableNameDialogMessage + '</div>';
63 var wrongDBNameMsg = '<div class="alert alert-danger" role="alert"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error">' + Messages.strDBNameDialogMessage + '</div>';
65 if (radioLocalImport.length !== 0) {
68 if (radioImport.is(':checked') && $('#input_import_file').val() === '') {
69 $('#input_import_file').trigger('focus');
70 Functions.ajaxShowMessage(fileMsg, false);
74 if (radioLocalImport.is(':checked')) {
75 if ($('#select_local_import_file').length === 0) {
76 Functions.ajaxShowMessage('<div class="alert alert-danger" role="alert"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error"> ' + Messages.strNoImportFile + ' </div>', false);
80 if ($('#select_local_import_file').val() === '') {
81 $('#select_local_import_file').trigger('focus');
82 Functions.ajaxShowMessage(fileMsg, false);
88 if ($('#input_import_file').val() === '') {
89 $('#input_import_file').trigger('focus');
90 Functions.ajaxShowMessage(fileMsg, false);
93 if ($('#text_csv_new_tbl_name').length > 0) {
94 var newTblName = $('#text_csv_new_tbl_name').val();
95 if (newTblName.length > 0 && $.trim(newTblName).length === 0) {
96 Functions.ajaxShowMessage(wrongTblNameMsg, false);
100 if ($('#text_csv_new_db_name').length > 0) {
101 var newDBName = $('#text_csv_new_db_name').val();
102 if (newDBName.length > 0 && $.trim(newDBName).length === 0) {
103 Functions.ajaxShowMessage(wrongDBNameMsg, false);
109 // show progress bar.
110 $('#upload_form_status').css('display', 'inline');
111 $('#upload_form_status_info').css('display', 'inline');
114 // Initially display the options for the selected plugin
117 // Whenever the selected plugin changes, change the options displayed
118 $('#plugins').on('change', function () {
122 $('#input_import_file').on('change', function () {
123 matchFile($(this).val());
126 $('#select_local_import_file').on('change', function () {
127 matchFile($(this).val());
131 * When the "Browse the server" form is clicked or the "Select from the web server upload directory"
132 * form is clicked, the radio button beside it becomes selected and the other form becomes disabled.
134 $('#input_import_file').on('focus change', function () {
135 $('#radio_import_file').prop('checked', true);
136 $('#radio_local_import_file').prop('checked', false);
138 $('#select_local_import_file').on('focus', function () {
139 $('#radio_local_import_file').prop('checked', true);
140 $('#radio_import_file').prop('checked', false);
144 * Set up the interface for Javascript-enabled browsers since the default is for
145 * Javascript-disabled browsers
147 $('#scroll_to_options_msg').hide();
148 $('#format_specific_opts').find('div.format_specific_options')
156 // $("form[name=import] *").unwrap();
159 * for input element text_csv_enclosed and text_csv_escaped allow just one character to enter.
160 * as mysql allows just one character for these fields,
161 * if first character is escape then allow two including escape character.
163 $('#text_csv_enclosed').add('#text_csv_escaped').on('keyup', function () {
164 if ($(this).val().length === 2 && $(this).val().charAt(0) !== '\\') {
165 $(this).val($(this).val().substring(0, 1));