export.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /* vim: set expandtab sw=4 ts=4 sts=4: */
  2. /**
  3. * Functions used in the export tab
  4. *
  5. */
  6. /**
  7. * Unbind all event handlers before tearing down a page
  8. */
  9. AJAX.registerTeardown('export.js', function() {
  10. $("#plugins").unbind('change');
  11. $("input[type='radio'][name='sql_structure_or_data']").unbind('change');
  12. $("input[type='radio'][name='latex_structure_or_data']").unbind('change');
  13. $("input[type='radio'][name='odt_structure_or_data']").unbind('change');
  14. $("input[type='radio'][name='texytext_structure_or_data']").unbind('change');
  15. $("input[type='radio'][name='htmlword_structure_or_data']").unbind('change');
  16. $("input[type='radio'][name='sql_structure_or_data']").unbind('change');
  17. $("input[type='radio'][name='output_format']").unbind('change');
  18. $("#checkbox_sql_include_comments").unbind('change');
  19. $("#plugins").unbind('change');
  20. $("input[type='radio'][name='quick_or_custom']").unbind('change');
  21. $("input[type='radio'][name='allrows']").unbind('change');
  22. });
  23. AJAX.registerOnload('export.js', function () {
  24. /**
  25. * Toggles the hiding and showing of each plugin's options
  26. * according to the currently selected plugin from the dropdown list
  27. */
  28. $("#plugins").change(function() {
  29. $("#format_specific_opts div.format_specific_options").hide();
  30. var selected_plugin_name = $("#plugins option:selected").val();
  31. $("#" + selected_plugin_name + "_options").show();
  32. });
  33. /**
  34. * Toggles the enabling and disabling of the SQL plugin's comment options that apply only when exporting structure
  35. */
  36. $("input[type='radio'][name='sql_structure_or_data']").change(function() {
  37. var comments_are_present = $("#checkbox_sql_include_comments").prop("checked");
  38. var show = $("input[type='radio'][name='sql_structure_or_data']:checked").val();
  39. if (show == 'data') {
  40. // disable the SQL comment options
  41. if (comments_are_present) {
  42. $("#checkbox_sql_dates").prop('disabled', true).parent().fadeTo('fast', 0.4);
  43. }
  44. $("#checkbox_sql_relation").prop('disabled', true).parent().fadeTo('fast', 0.4);
  45. $("#checkbox_sql_mime").prop('disabled', true).parent().fadeTo('fast', 0.4);
  46. } else {
  47. // enable the SQL comment options
  48. if (comments_are_present) {
  49. $("#checkbox_sql_dates").removeProp('disabled').parent().fadeTo('fast', 1);
  50. }
  51. $("#checkbox_sql_relation").removeProp('disabled').parent().fadeTo('fast', 1);
  52. $("#checkbox_sql_mime").removeProp('disabled').parent().fadeTo('fast', 1);
  53. }
  54. });
  55. });
  56. /**
  57. * Toggles the hiding and showing of plugin structure-specific and data-specific
  58. * options
  59. */
  60. function toggle_structure_data_opts(pluginName)
  61. {
  62. var radioFormName = pluginName + "_structure_or_data";
  63. var dataDiv = "#" + pluginName + "_data";
  64. var structureDiv = "#" + pluginName + "_structure";
  65. var show = $("input[type='radio'][name='" + radioFormName + "']:checked").val();
  66. if (show == 'data') {
  67. $(dataDiv).slideDown('slow');
  68. $(structureDiv).slideUp('slow');
  69. } else {
  70. $(structureDiv).slideDown('slow');
  71. if (show == 'structure') {
  72. $(dataDiv).slideUp('slow');
  73. } else {
  74. $(dataDiv).slideDown('slow');
  75. }
  76. }
  77. }
  78. AJAX.registerOnload('export.js', function () {
  79. $("input[type='radio'][name='latex_structure_or_data']").change(function() {
  80. toggle_structure_data_opts("latex");
  81. });
  82. $("input[type='radio'][name='odt_structure_or_data']").change(function() {
  83. toggle_structure_data_opts("odt");
  84. });
  85. $("input[type='radio'][name='texytext_structure_or_data']").change(function() {
  86. toggle_structure_data_opts("texytext");
  87. });
  88. $("input[type='radio'][name='htmlword_structure_or_data']").change(function() {
  89. toggle_structure_data_opts("htmlword");
  90. });
  91. $("input[type='radio'][name='sql_structure_or_data']").change(function() {
  92. toggle_structure_data_opts("sql");
  93. });
  94. });
  95. /**
  96. * Toggles the disabling of the "save to file" options
  97. */
  98. function toggle_save_to_file()
  99. {
  100. if (!$("#radio_dump_asfile").prop("checked")) {
  101. $("#ul_save_asfile > li").fadeTo('fast', 0.4);
  102. $("#ul_save_asfile > li > input").prop('disabled', true);
  103. $("#ul_save_asfile > li> select").prop('disabled', true);
  104. } else {
  105. $("#ul_save_asfile > li").fadeTo('fast', 1);
  106. $("#ul_save_asfile > li > input").removeProp('disabled');
  107. $("#ul_save_asfile > li> select").removeProp('disabled');
  108. }
  109. }
  110. AJAX.registerOnload('export.js', function () {
  111. toggle_save_to_file();
  112. $("input[type='radio'][name='output_format']").change(toggle_save_to_file);
  113. });
  114. /**
  115. * For SQL plugin, toggles the disabling of the "display comments" options
  116. */
  117. function toggle_sql_include_comments()
  118. {
  119. $("#checkbox_sql_include_comments").change(function() {
  120. if (!$("#checkbox_sql_include_comments").prop("checked")) {
  121. $("#ul_include_comments > li").fadeTo('fast', 0.4);
  122. $("#ul_include_comments > li > input").prop('disabled', true);
  123. } else {
  124. // If structure is not being exported, the comment options for structure should not be enabled
  125. if ($("#radio_sql_structure_or_data_data").prop("checked")) {
  126. $("#text_sql_header_comment").removeProp('disabled').parent("li").fadeTo('fast', 1);
  127. } else {
  128. $("#ul_include_comments > li").fadeTo('fast', 1);
  129. $("#ul_include_comments > li > input").removeProp('disabled');
  130. }
  131. }
  132. });
  133. }
  134. AJAX.registerOnload('export.js', function () {
  135. /**
  136. * For SQL plugin, if "CREATE TABLE options" is checked/unchecked, check/uncheck each of its sub-options
  137. */
  138. var $create = $("#checkbox_sql_create_table_statements");
  139. var $create_options = $("#ul_create_table_statements input");
  140. $create.change(function() {
  141. $create_options.prop('checked', $(this).prop("checked"));
  142. });
  143. $create_options.change(function() {
  144. if ($create_options.is(":checked")) {
  145. $create.prop('checked', true);
  146. }
  147. });
  148. /**
  149. * Disables the view output as text option if the output must be saved as a file
  150. */
  151. $("#plugins").change(function() {
  152. var active_plugin = $("#plugins option:selected").val();
  153. var force_file = $("#force_file_" + active_plugin).val();
  154. if (force_file == "true") {
  155. $("#radio_view_as_text").prop('disabled', true).parent().fadeTo('fast', 0.4);
  156. } else {
  157. $("#radio_view_as_text").removeProp('disabled').parent().fadeTo('fast', 1);
  158. }
  159. });
  160. });
  161. /**
  162. * Toggles display of options when quick and custom export are selected
  163. */
  164. function toggle_quick_or_custom()
  165. {
  166. if ($("#radio_custom_export").prop("checked")) {
  167. $("#databases_and_tables").show();
  168. $("#rows").show();
  169. $("#output").show();
  170. $("#format_specific_opts").show();
  171. $("#output_quick_export").hide();
  172. var selected_plugin_name = $("#plugins option:selected").val();
  173. $("#" + selected_plugin_name + "_options").show();
  174. } else {
  175. $("#databases_and_tables").hide();
  176. $("#rows").hide();
  177. $("#output").hide();
  178. $("#format_specific_opts").hide();
  179. $("#output_quick_export").show();
  180. }
  181. }
  182. AJAX.registerOnload('export.js', function () {
  183. $("input[type='radio'][name='quick_or_custom']").change(toggle_quick_or_custom);
  184. /**
  185. * Sets up the interface for Javascript-enabled browsers since the default is for
  186. * Javascript-disabled browsers
  187. * TODO: drop non-JS behaviour
  188. */
  189. if ($("input[type='hidden'][name='export_method']").val() != "custom-no-form") {
  190. $("#quick_or_custom").show();
  191. }
  192. $("#scroll_to_options_msg").hide();
  193. $("#format_specific_opts div.format_specific_options")
  194. .hide()
  195. .css({
  196. "border": 0,
  197. "margin": 0,
  198. "padding": 0
  199. })
  200. .find("h3")
  201. .remove();
  202. toggle_quick_or_custom();
  203. toggle_structure_data_opts($("select#plugins").val());
  204. toggle_sql_include_comments();
  205. /**
  206. * Initially disables the "Dump some row(s)" sub-options
  207. */
  208. disable_dump_some_rows_sub_options();
  209. /**
  210. * Disables the "Dump some row(s)" sub-options when it is not selected
  211. */
  212. $("input[type='radio'][name='allrows']").change(function() {
  213. if ($("input[type='radio'][name='allrows']").prop("checked")) {
  214. enable_dump_some_rows_sub_options();
  215. } else {
  216. disable_dump_some_rows_sub_options();
  217. }
  218. });
  219. });
  220. /**
  221. * Disables the "Dump some row(s)" sub-options
  222. */
  223. function disable_dump_some_rows_sub_options()
  224. {
  225. $("label[for='limit_to']").fadeTo('fast', 0.4);
  226. $("label[for='limit_from']").fadeTo('fast', 0.4);
  227. $("input[type='text'][name='limit_to']").prop('disabled', 'disabled');
  228. $("input[type='text'][name='limit_from']").prop('disabled', 'disabled');
  229. }
  230. /**
  231. * Enables the "Dump some row(s)" sub-options
  232. */
  233. function enable_dump_some_rows_sub_options()
  234. {
  235. $("label[for='limit_to']").fadeTo('fast', 1);
  236. $("label[for='limit_from']").fadeTo('fast', 1);
  237. $("input[type='text'][name='limit_to']").prop('disabled', '');
  238. $("input[type='text'][name='limit_from']").prop('disabled', '');
  239. }