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