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()
14 $("#format_specific_opts div.format_specific_options").each(function () {
17 var selected_plugin_name = $("#plugins option:selected").val();
18 $("#" + selected_plugin_name + "_options").fadeIn('slow');
19 if (selected_plugin_name == "csv") {
20 $("#import_notification").text(PMA_messages.strImportCSV);
22 $("#import_notification").text("");
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
30 function matchFile(fname)
32 var fname_array = fname.toLowerCase().split(".");
33 var len = fname_array.length;
35 var extension = fname_array[len - 1];
36 if (extension == "gz" || extension == "bz2" || extension == "zip") {
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);
48 * Unbind all event handlers before tearing down a page
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');
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) {
68 // TODO Remove this section when all browsers support HTML5 "required" property
69 if (! radioLocalImport.is(":checked") && ! radioImport.is(":checked")) {
71 var msg = '<div class="error"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error" /> ';
72 msg += PMA_messages.strRadioUnchecked;
74 PMA_ajaxShowMessage(msg, false);
78 if (radioImport.is(":checked") && $("#input_import_file").val() === '') {
79 $("#input_import_file").focus();
80 PMA_ajaxShowMessage(fileMsg, false);
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);
90 if ($("#select_local_import_file").val() === '') {
91 $("#select_local_import_file").focus();
92 PMA_ajaxShowMessage(fileMsg, false);
98 if ($("#input_import_file").val() === '') {
99 $("#input_import_file").focus();
100 PMA_ajaxShowMessage(fileMsg, false);
105 // show progress bar.
106 $("#upload_form_status").css("display", "inline");
107 $("#upload_form_status_info").css("display", "inline");
110 // Initially display the options for the selected plugin
113 // Whenever the selected plugin changes, change the options displayed
114 $("#plugins").change(function () {
118 $("#input_import_file").change(function () {
119 matchFile($(this).val());
122 $("#select_local_import_file").change(function () {
123 matchFile($(this).val());
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.
130 $("#input_import_file").bind("focus change", function () {
131 $("#radio_import_file").prop('checked', true);
132 $("#radio_local_import_file").prop('checked', false);
134 $("#select_local_import_file").focus(function () {
135 $("#radio_local_import_file").prop('checked', true);
136 $("#radio_import_file").prop('checked', false);
140 * Set up the interface for Javascript-enabled browsers since the default is for
141 * Javascript-disabled browsers
143 $("#scroll_to_options_msg").hide();
144 $("#format_specific_opts div.format_specific_options")
152 //$("form[name=import] *").unwrap();
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.
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));