Translated using Weblate (Korean)
[phpmyadmin.git] / js / import.js
blob61bd9dbac5f2c94336229eda91e678e8e4f0dea9
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()
14     $("#format_specific_opts").find("div.format_specific_options").each(function () {
15         $(this).hide();
16     });
17     var selected_plugin_name = $("#plugins").find("option:selected").val();
18     $("#" + selected_plugin_name + "_options").fadeIn('slow');
19     if (selected_plugin_name == "csv") {
20         $("#import_notification").text(PMA_messages.strImportCSV);
21     } else {
22         $("#import_notification").text("");
23     }
26 /**
27  * Toggles the hiding and showing of each plugin's options and sets the selected value
28  * in the plugin dropdown list according to the format of the selected file
29  */
30 function matchFile(fname)
32     var fname_array = fname.toLowerCase().split(".");
33     var len = fname_array.length;
34     if (len !== 0) {
35         var extension = fname_array[len - 1];
36         if (extension == "gz" || extension == "bz2" || extension == "zip") {
37             len--;
38         }
39         // Only toggle if the format of the file can be imported
40         if ($("select[name='format'] option").filterByValue(fname_array[len - 1]).length == 1) {
41             $("select[name='format'] option").filterByValue(fname_array[len - 1]).prop('selected', true);
42             changePluginOpts();
43         }
44     }
47 /**
48  * Unbind all event handlers before tearing down a page
49  */
50 AJAX.registerTeardown('import.js', function () {
51     $("#plugins").unbind('change');
52     $("#input_import_file").unbind('change');
53     $("#select_local_import_file").unbind('change');
54     $("#input_import_file").unbind('change').unbind('focus');
55     $("#select_local_import_file").unbind('focus');
56     $("#text_csv_enclosed").add("#text_csv_escaped").unbind('keyup');
57 });
59 AJAX.registerOnload('import.js', function () {
60     // import_file_form validation.
61     $(document).on('submit', '#import_file_form', function (event) {
62         var radioLocalImport = $("#radio_local_import_file");
63         var radioImport = $("#radio_import_file");
64         var fileMsg = '<div class="error"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error" /> ' + PMA_messages.strImportDialogMessage + '</div>';
66         if (radioLocalImport.length !== 0) {
67             // remote upload.
68             // TODO Remove this section when all browsers support HTML5 "required" property
69             if (! radioLocalImport.is(":checked") && ! radioImport.is(":checked")) {
70                 radioImport.focus();
71                 var msg = '<div class="error"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error" /> ';
72                 msg += PMA_messages.strRadioUnchecked;
73                 msg += '</div>';
74                 PMA_ajaxShowMessage(msg, false);
75                 return false;
76             }
78             if (radioImport.is(":checked") && $("#input_import_file").val() === '') {
79                 $("#input_import_file").focus();
80                 PMA_ajaxShowMessage(fileMsg, false);
81                 return false;
82             }
84             if (radioLocalImport.is(":checked")) {
85                 if ($("#select_local_import_file").length === 0) {
86                     PMA_ajaxShowMessage('<div class="error"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error" /> ' + PMA_messages.strNoImportFile + ' </div>', false);
87                     return false;
88                 }
90                 if ($("#select_local_import_file").val() === '') {
91                     $("#select_local_import_file").focus();
92                     PMA_ajaxShowMessage(fileMsg, false);
93                     return false;
94                 }
95             }
96         } else {
97             // local upload.
98             if ($("#input_import_file").val() === '') {
99                 $("#input_import_file").focus();
100                 PMA_ajaxShowMessage(fileMsg, false);
101                 return false;
102             }
103         }
105         // show progress bar.
106         $("#upload_form_status").css("display", "inline");
107         $("#upload_form_status_info").css("display", "inline");
108     });
110     // Initially display the options for the selected plugin
111     changePluginOpts();
113    // Whenever the selected plugin changes, change the options displayed
114     $("#plugins").change(function () {
115         changePluginOpts();
116     });
118     $("#input_import_file").change(function () {
119         matchFile($(this).val());
120     });
122     $("#select_local_import_file").change(function () {
123         matchFile($(this).val());
124     });
126     /*
127      * When the "Browse the server" form is clicked or the "Select from the web server upload directory"
128      * form is clicked, the radio button beside it becomes selected and the other form becomes disabled.
129      */
130     $("#input_import_file").bind("focus change", function () {
131         $("#radio_import_file").prop('checked', true);
132         $("#radio_local_import_file").prop('checked', false);
133     });
134     $("#select_local_import_file").focus(function () {
135         $("#radio_local_import_file").prop('checked', true);
136         $("#radio_import_file").prop('checked', false);
137     });
139     /**
140      * Set up the interface for Javascript-enabled browsers since the default is for
141      *  Javascript-disabled browsers
142      */
143     $("#scroll_to_options_msg").hide();
144     $("#format_specific_opts").find("div.format_specific_options")
145     .css({
146         "border": 0,
147         "margin": 0,
148         "padding": 0
149     })
150     .find("h3")
151     .remove();
152     //$("form[name=import] *").unwrap();
154     /**
155      * for input element text_csv_enclosed and text_csv_escaped allow just one character to enter.
156      * as mysql allows just one character for these fields,
157      * if first character is escape then allow two including escape character.
158      */
159     $("#text_csv_enclosed").add("#text_csv_escaped").bind('keyup', function() {
160         if($(this).val().length === 2 && $(this).val().charAt(0) !== "\\") {
161             $(this).val($(this).val().substring(0, 1));
162             return false;
163         }
164         return true;
165     });