export.js 10.0 KB

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