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").find("div.format_specific_options").each(function () {
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);
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) {
69 if (radioImport.is(":checked") && $("#input_import_file").val() === '') {
70 $("#input_import_file").focus();
71 PMA_ajaxShowMessage(fileMsg, false);
75 if (radioLocalImport.is(":checked")) {
76 if ($("#select_local_import_file").length === 0) {
77 PMA_ajaxShowMessage('<div class="error"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error" /> ' + PMA_messages.strNoImportFile + ' </div>', false);
81 if ($("#select_local_import_file").val() === '') {
82 $("#select_local_import_file").focus();
83 PMA_ajaxShowMessage(fileMsg, false);
89 if ($("#input_import_file").val() === '') {
90 $("#input_import_file").focus();
91 PMA_ajaxShowMessage(fileMsg, false);
97 $("#upload_form_status").css("display", "inline");
98 $("#upload_form_status_info").css("display", "inline");
101 // Initially display the options for the selected plugin
104 // Whenever the selected plugin changes, change the options displayed
105 $("#plugins").change(function () {
109 $("#input_import_file").change(function () {
110 matchFile($(this).val());
113 $("#select_local_import_file").change(function () {
114 matchFile($(this).val());
118 * When the "Browse the server" form is clicked or the "Select from the web server upload directory"
119 * form is clicked, the radio button beside it becomes selected and the other form becomes disabled.
121 $("#input_import_file").bind("focus change", function () {
122 $("#radio_import_file").prop('checked', true);
123 $("#radio_local_import_file").prop('checked', false);
125 $("#select_local_import_file").focus(function () {
126 $("#radio_local_import_file").prop('checked', true);
127 $("#radio_import_file").prop('checked', false);
131 * Set up the interface for Javascript-enabled browsers since the default is for
132 * Javascript-disabled browsers
134 $("#scroll_to_options_msg").hide();
135 $("#format_specific_opts").find("div.format_specific_options")
143 //$("form[name=import] *").unwrap();
146 * for input element text_csv_enclosed and text_csv_escaped allow just one character to enter.
147 * as mysql allows just one character for these fields,
148 * if first character is escape then allow two including escape character.
150 $("#text_csv_enclosed").add("#text_csv_escaped").bind('keyup', function() {
151 if($(this).val().length === 2 && $(this).val().charAt(0) !== "\\") {
152 $(this).val($(this).val().substring(0, 1));