patch for Copy set of tables to new name pattern.
[phpmyadmin/dennischen.git] / js / import.js
blob0bcc3d0104a460a65db4035e362a09ad09559115
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_options").each(function() { 
14         $(this).hide();
15     }); 
16     var selected_plugin_name = $("#plugins option:selected").attr("value");
17     $("#" + selected_plugin_name + "_options").fadeIn('slow');
18     if(selected_plugin_name == "csv") {
19         $("#import_notification").text("Note: If the file contains multiple tables, they will be combined into one");
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 fname_array = fname.toLowerCase().split(".");
31     var len = fname_array.length;
32     if(len != 0) {
33         var extension = fname_array[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[value='" + fname_array[len - 1] + "']").length == 1) {
39             $("#plugins option:selected").removeAttr("selected");
40             $("select[name='format'] option[value='" + fname_array[len - 1] + "']").attr('selected', 'selected');
41             changePluginOpts();
42         }
43     }
45 $(document).ready(function() {
46     // Initially display the options for the selected plugin 
47     changePluginOpts();
49    // Whenever the selected plugin changes, change the options displayed
50    $("#plugins").change(function() {
51         changePluginOpts();
52     });
54     $("#input_import_file").change(function() {
55         matchFile($(this).attr("value"));
56     });
58     $("#select_local_import_file").change(function() {
59         matchFile($(this).attr("value"));
60     });
62     /*
63      * When the "Browse the server" form is clicked or the "Select from the web server upload directory"
64      * form is clicked, the radio button beside it becomes selected and the other form becomes disabled.
65      */
66     $("#input_import_file").focus(function() {
67          $("#radio_import_file").attr('checked', 'checked');
68          $("#radio_local_import_file").removeAttr('checked');
69     });
70     $("#select_local_import_file").focus(function() {
71          $("#radio_local_import_file").attr('checked', 'checked');
72          $("#radio_import_file").removeAttr('checked');
73     });
75     /**
76      * Set up the interface for Javascript-enabled browsers since the default is for
77      *  Javascript-disabled browsers
78      */
79     $("#scroll_to_options_msg").hide();
80     $(".format_specific_options").css({ "border": 0, "margin": 0, "padding": 0 });
81     $(".format_specific_options h3").remove();
82 });