import.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* vim: set expandtab sw=4 ts=4 sts=4: */
  2. /**
  3. * Functions used in the import tab
  4. *
  5. */
  6. /**
  7. * Toggles the hiding and showing of each plugin's options
  8. * according to the currently selected plugin from the dropdown list
  9. */
  10. function changePluginOpts()
  11. {
  12. $("#format_specific_opts div.format_specific_options").each(function() {
  13. $(this).hide();
  14. });
  15. var selected_plugin_name = $("#plugins option:selected").val();
  16. $("#" + selected_plugin_name + "_options").fadeIn('slow');
  17. if (selected_plugin_name == "csv") {
  18. $("#import_notification").text(PMA_messages['strImportCSV']);
  19. } else {
  20. $("#import_notification").text("");
  21. }
  22. }
  23. /**
  24. * Toggles the hiding and showing of each plugin's options and sets the selected value
  25. * in the plugin dropdown list according to the format of the selected file
  26. */
  27. function matchFile(fname)
  28. {
  29. var fname_array = fname.toLowerCase().split(".");
  30. var len = fname_array.length;
  31. if (len != 0) {
  32. var extension = fname_array[len - 1];
  33. if (extension == "gz" || extension == "bz2" || extension == "zip") {
  34. len--;
  35. }
  36. // Only toggle if the format of the file can be imported
  37. if ($("select[name='format'] option").filterByValue(fname_array[len - 1]).length == 1) {
  38. $("select[name='format'] option").filterByValue(fname_array[len - 1]).prop('selected', true);
  39. changePluginOpts();
  40. }
  41. }
  42. }
  43. /**
  44. * Unbind all event handlers before tearing down a page
  45. */
  46. AJAX.registerTeardown('import.js', function() {
  47. $("#plugins").unbind('change');
  48. $("#input_import_file").unbind('change');
  49. $("#select_local_import_file").unbind('change');
  50. $("#input_import_file").unbind('change').unbind('focus');
  51. $("#select_local_import_file").unbind('focus');
  52. });
  53. AJAX.registerOnload('import.js', function() {
  54. // Initially display the options for the selected plugin
  55. changePluginOpts();
  56. // Whenever the selected plugin changes, change the options displayed
  57. $("#plugins").change(function() {
  58. changePluginOpts();
  59. });
  60. $("#input_import_file").change(function() {
  61. matchFile($(this).val());
  62. });
  63. $("#select_local_import_file").change(function() {
  64. matchFile($(this).val());
  65. });
  66. /*
  67. * When the "Browse the server" form is clicked or the "Select from the web server upload directory"
  68. * form is clicked, the radio button beside it becomes selected and the other form becomes disabled.
  69. */
  70. $("#input_import_file").bind("focus change", function() {
  71. $("#radio_import_file").prop('checked', true);
  72. $("#radio_local_import_file").prop('checked', false);
  73. });
  74. $("#select_local_import_file").focus(function() {
  75. $("#radio_local_import_file").prop('checked', true);
  76. $("#radio_import_file").prop('checked', false);
  77. });
  78. /**
  79. * Set up the interface for Javascript-enabled browsers since the default is for
  80. * Javascript-disabled browsers
  81. */
  82. $("#scroll_to_options_msg").hide();
  83. $("#format_specific_opts div.format_specific_options")
  84. .css({
  85. "border": 0,
  86. "margin": 0,
  87. "padding": 0
  88. })
  89. .find("h3")
  90. .remove();
  91. //$("form[name=import] *").unwrap();
  92. });