1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functions used in the export tab
*
*/
/**
* Disables the "Dump some row(s)" sub-options
*/
function disable_dump_some_rows_sub_options()
{
$("label[for='limit_to']").fadeTo('fast', 0.4);
$("label[for='limit_from']").fadeTo('fast', 0.4);
$("input[type='text'][name='limit_to']").prop('disabled', 'disabled');
$("input[type='text'][name='limit_from']").prop('disabled', 'disabled');
}
/**
* Enables the "Dump some row(s)" sub-options
*/
function enable_dump_some_rows_sub_options()
{
$("label[for='limit_to']").fadeTo('fast', 1);
$("label[for='limit_from']").fadeTo('fast', 1);
$("input[type='text'][name='limit_to']").prop('disabled', '');
$("input[type='text'][name='limit_from']").prop('disabled', '');
}
/**
* Unbind all event handlers before tearing down a page
*/
AJAX.registerTeardown('export.js', function () {
$("#plugins").unbind('change');
$("input[type='radio'][name='sql_structure_or_data']").unbind('change');
$("input[type='radio'][name='latex_structure_or_data']").unbind('change');
$("input[type='radio'][name='odt_structure_or_data']").unbind('change');
$("input[type='radio'][name='texytext_structure_or_data']").unbind('change');
$("input[type='radio'][name='htmlword_structure_or_data']").unbind('change');
$("input[type='radio'][name='sql_structure_or_data']").unbind('change');
$("input[type='radio'][name='output_format']").unbind('change');
$("#checkbox_sql_include_comments").unbind('change');
$("#plugins").unbind('change');
$("input[type='radio'][name='quick_or_custom']").unbind('change');
$("input[type='radio'][name='allrows']").unbind('change');
$('#btn_alias_config').off('click');
$('#db_alias_select').off('change');
$('.table_alias_select').off('change');
});
AJAX.registerOnload('export.js', function () {
/**
* Toggles the hiding and showing of each plugin's options
* according to the currently selected plugin from the dropdown list
*/
$("#plugins").change(function () {
$("#format_specific_opts div.format_specific_options").hide();
var selected_plugin_name = $("#plugins option:selected").val();
$("#" + selected_plugin_name + "_options").show();
});
/**
* Toggles the enabling and disabling of the SQL plugin's comment options that apply only when exporting structure
*/
$("input[type='radio'][name='sql_structure_or_data']").change(function () {
var comments_are_present = $("#checkbox_sql_include_comments").prop("checked");
var show = $("input[type='radio'][name='sql_structure_or_data']:checked").val();
if (show == 'data') {
// disable the SQL comment options
if (comments_are_present) {
$("#checkbox_sql_dates").prop('disabled', true).parent().fadeTo('fast', 0.4);
}
$("#checkbox_sql_relation").prop('disabled', true).parent().fadeTo('fast', 0.4);
$("#checkbox_sql_mime").prop('disabled', true).parent().fadeTo('fast', 0.4);
} else {
// enable the SQL comment options
if (comments_are_present) {
$("#checkbox_sql_dates").removeProp('disabled').parent().fadeTo('fast', 1);
}
$("#checkbox_sql_relation").removeProp('disabled').parent().fadeTo('fast', 1);
$("#checkbox_sql_mime").removeProp('disabled').parent().fadeTo('fast', 1);
}
});
});
/**
* Toggles the hiding and showing of plugin structure-specific and data-specific
* options
*/
function toggle_structure_data_opts(pluginName)
{
var radioFormName = pluginName + "_structure_or_data";
var dataDiv = "#" + pluginName + "_data";
var structureDiv = "#" + pluginName + "_structure";
var show = $("input[type='radio'][name='" + radioFormName + "']:checked").val();
if (show == 'data') {
$(dataDiv).slideDown('slow');
$(structureDiv).slideUp('slow');
} else {
$(structureDiv).slideDown('slow');
if (show == 'structure') {
$(dataDiv).slideUp('slow');
} else {
$(dataDiv).slideDown('slow');
}
}
}
AJAX.registerOnload('export.js', function () {
$("input[type='radio'][name='latex_structure_or_data']").change(function () {
toggle_structure_data_opts("latex");
});
$("input[type='radio'][name='odt_structure_or_data']").change(function () {
toggle_structure_data_opts("odt");
});
$("input[type='radio'][name='texytext_structure_or_data']").change(function () {
toggle_structure_data_opts("texytext");
});
$("input[type='radio'][name='htmlword_structure_or_data']").change(function () {
toggle_structure_data_opts("htmlword");
});
$("input[type='radio'][name='sql_structure_or_data']").change(function () {
toggle_structure_data_opts("sql");
});
});
/**
* Toggles the disabling of the "save to file" options
*/
function toggle_save_to_file()
{
if (!$("#radio_dump_asfile").prop("checked")) {
$("#ul_save_asfile > li").fadeTo('fast', 0.4);
$("#ul_save_asfile > li > input").prop('disabled', true);
$("#ul_save_asfile > li> select").prop('disabled', true);
} else {
$("#ul_save_asfile > li").fadeTo('fast', 1);
$("#ul_save_asfile > li > input").prop('disabled', false);
$("#ul_save_asfile > li> select").prop('disabled', false);
}
}
AJAX.registerOnload('export.js', function () {
toggle_save_to_file();
$("input[type='radio'][name='output_format']").change(toggle_save_to_file);
});
/**
* For SQL plugin, toggles the disabling of the "display comments" options
*/
function toggle_sql_include_comments()
{
$("#checkbox_sql_include_comments").change(function () {
if (!$("#checkbox_sql_include_comments").prop("checked")) {
$("#ul_include_comments > li").fadeTo('fast', 0.4);
$("#ul_include_comments > li > input").prop('disabled', true);
} else {
// If structure is not being exported, the comment options for structure should not be enabled
if ($("#radio_sql_structure_or_data_data").prop("checked")) {
$("#text_sql_header_comment").removeProp('disabled').parent("li").fadeTo('fast', 1);
} else {
$("#ul_include_comments > li").fadeTo('fast', 1);
$("#ul_include_comments > li > input").removeProp('disabled');
}
}
});
}
AJAX.registerOnload('export.js', function () {
/**
* For SQL plugin, if "CREATE TABLE options" is checked/unchecked, check/uncheck each of its sub-options
*/
var $create = $("#checkbox_sql_create_table_statements");
var $create_options = $("#ul_create_table_statements input");
$create.change(function () {
$create_options.prop('checked', $(this).prop("checked"));
});
$create_options.change(function () {
if ($create_options.is(":checked")) {
$create.prop('checked', true);
}
});
/**
* Disables the view output as text option if the output must be saved as a file
*/
$("#plugins").change(function () {
var active_plugin = $("#plugins option:selected").val();
var force_file = $("#force_file_" + active_plugin).val();
if (force_file == "true") {
if ($("#radio_dump_asfile").prop('checked') !== true) {
$("#radio_dump_asfile").prop('checked', true);
toggle_save_to_file();
}
$("#radio_view_as_text").prop('disabled', true).parent().fadeTo('fast', 0.4);
} else {
$("#radio_view_as_text").prop('disabled', false).parent().fadeTo('fast', 1);
}
});
});
/**
* Toggles display of options when quick and custom export are selected
*/
function toggle_quick_or_custom()
{
if ($("#radio_custom_export").prop("checked")) {
$("#databases_and_tables").show();
$("#rows").show();
$("#output").show();
$("#format_specific_opts").show();
$("#output_quick_export").hide();
var selected_plugin_name = $("#plugins option:selected").val();
$("#" + selected_plugin_name + "_options").show();
} else {
$("#databases_and_tables").hide();
$("#rows").hide();
$("#output").hide();
$("#format_specific_opts").hide();
$("#output_quick_export").show();
}
}
var time_out;
function check_time_out(time_limit)
{
if (typeof time_limit === 'undefined' || time_limit === 0) {
return true;
}
//margin of one second to avoid race condition to set/access session variable
time_limit = time_limit + 1;
var href = "export.php";
var params = {
'ajax_request' : true,
'token' : PMA_commonParams.get('token'),
'check_time_out' : true
};
clearTimeout(time_out);
time_out = setTimeout(function(){
$.get(href, params, function (data) {
if (data.message === 'timeout') {
PMA_ajaxShowMessage(
'<div class="error">' +
PMA_messages.strTimeOutError +
'</div>',
false
);
}
});
}, time_limit * 1000);
}
/**
* Handler for Database/table alias select
*
* @param object event the event object
*
* @return void
*/
function aliasSelectHandler(event) {
var sel = event.data.sel;
var type = event.data.type;
var inputId = $(this).val();
var $label = $(this).next('label');
$('input#' + $label.attr('for')).addClass('hide');
$('input#' + inputId).removeClass('hide');
$label.attr('for', inputId);
$('#alias_modal ' + sel + '[id$=' + type + ']:visible').addClass('hide');
var $inputWrapper = $('#alias_modal ' + sel + '#' + inputId + type);
$inputWrapper.removeClass('hide');
if (type === '_cols' && $inputWrapper.length > 0) {
var outer = $inputWrapper[0].outerHTML;
// Replace opening tags
var regex = /<dummy_inp/gi;
var newTag = outer.replace(regex, '<input');
// Replace closing tags
regex = /<\/dummy_inp/gi;
newTag = newTag.replace(regex, '</input');
// Assign replacement
$inputWrapper.replaceWith(newTag);
} else if (type === '_tables') {
$('.table_alias_select:visible').change();
}
$("#alias_modal").dialog("option", "position", "center");
}
/**
* Handler for Alias dialog box
*
* @param object event the event object
*
* @return void
*/
function createAliasModal(event) {
event.preventDefault();
var dlgButtons = {};
dlgButtons[PMA_messages.strResetAll] = function() {
$(this).find('input[type="text"]').val('');
};
dlgButtons[PMA_messages.strReset] = function() {
$(this).find('input[type="text"]:visible').val('');
};
dlgButtons[PMA_messages.strSaveAndClose] = function() {
$(this).dialog("close");
$('#alias_modal').parent().appendTo($('form[name="dump"]'));
};
$('#alias_modal').dialog({
width: Math.min($(window).width() - 100, 700),
modal: true,
dialogClass: "alias-dialog",
buttons: dlgButtons,
create: function() {
$(this).css('maxHeight', $(window).height() - 150);
$('.alias-dialog .ui-dialog-titlebar-close').remove();
},
close: function() {
var isEmpty = true;
$(this).find('input[type="text"]').each(function() {
// trim input fields on close
$(this).val($(this).val().trim());
// check if non empty field present
if ($(this).val()) {
isEmpty = false;
}
});
$('input#btn_alias_config').attr('checked', !isEmpty);
},
position: 'center'
});
// Call change event of .table_alias_select
$('.table_alias_select:visible').trigger('change');
}
AJAX.registerOnload('export.js', function () {
$("input[type='radio'][name='quick_or_custom']").change(toggle_quick_or_custom);
$("#scroll_to_options_msg").hide();
$("#format_specific_opts div.format_specific_options")
.hide()
.css({
"border": 0,
"margin": 0,
"padding": 0
})
.find("h3")
.remove();
toggle_quick_or_custom();
toggle_structure_data_opts($("select#plugins").val());
toggle_sql_include_comments();
/**
* Initially disables the "Dump some row(s)" sub-options
*/
disable_dump_some_rows_sub_options();
/**
* Disables the "Dump some row(s)" sub-options when it is not selected
*/
$("input[type='radio'][name='allrows']").change(function () {
if ($("input[type='radio'][name='allrows']").prop("checked")) {
enable_dump_some_rows_sub_options();
} else {
disable_dump_some_rows_sub_options();
}
});
// Open Alias Modal Dialog on click
$('#btn_alias_config').on('click', createAliasModal);
// Database alias select on change event
$('#db_alias_select').on(
'change',
{sel: 'span', type: '_tables'},
aliasSelectHandler
);
// Table alias select on change event
$('.table_alias_select').on(
'change',
{sel: 'table', type: '_cols'},
aliasSelectHandler
);
});
|