Some common files removed for code cleanup.
Signed-Off-By: Piyush Vijay <piyushvijay.1997@gmail.com>
This commit is contained in:
parent
2bd0206f22
commit
2950e2b269
1495
js/console.js
1495
js/console.js
File diff suppressed because it is too large
Load Diff
996
js/export.js
996
js/export.js
@ -1,996 +0,0 @@
|
||||
/* 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', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return template data as a json object
|
||||
*
|
||||
* @returns template data
|
||||
*/
|
||||
function getTemplateData () {
|
||||
var $form = $('form[name="dump"]');
|
||||
var blacklist = ['token', 'server', 'db', 'table', 'single_table',
|
||||
'export_type', 'export_method', 'sql_query', 'template_id'];
|
||||
var obj = {};
|
||||
var arr = $form.serializeArray();
|
||||
$.each(arr, function () {
|
||||
if ($.inArray(this.name, blacklist) < 0) {
|
||||
if (obj[this.name] !== undefined) {
|
||||
if (! obj[this.name].push) {
|
||||
obj[this.name] = [obj[this.name]];
|
||||
}
|
||||
obj[this.name].push(this.value || '');
|
||||
} else {
|
||||
obj[this.name] = this.value || '';
|
||||
}
|
||||
}
|
||||
});
|
||||
// include unchecked checboxes (which are ignored by serializeArray()) with null
|
||||
// to uncheck them when loading the template
|
||||
$form.find('input[type="checkbox"]:not(:checked)').each(function () {
|
||||
if (obj[this.name] === undefined) {
|
||||
obj[this.name] = null;
|
||||
}
|
||||
});
|
||||
// include empty multiselects
|
||||
$form.find('select').each(function () {
|
||||
if ($(this).find('option:selected').length === 0) {
|
||||
obj[this.name] = [];
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a template with selected options
|
||||
*
|
||||
* @param name name of the template
|
||||
*/
|
||||
function createTemplate (name) {
|
||||
var templateData = getTemplateData();
|
||||
|
||||
var params = {
|
||||
ajax_request : true,
|
||||
server : PMA_commonParams.get('server'),
|
||||
db : PMA_commonParams.get('db'),
|
||||
table : PMA_commonParams.get('table'),
|
||||
exportType : $('input[name="export_type"]').val(),
|
||||
templateAction : 'create',
|
||||
templateName : name,
|
||||
templateData : JSON.stringify(templateData)
|
||||
};
|
||||
|
||||
PMA_ajaxShowMessage();
|
||||
$.post('tbl_export.php', params, function (response) {
|
||||
if (response.success === true) {
|
||||
$('#templateName').val('');
|
||||
$('#template').html(response.data);
|
||||
$('#template').find('option').each(function () {
|
||||
if ($(this).text() === name) {
|
||||
$(this).prop('selected', true);
|
||||
}
|
||||
});
|
||||
PMA_ajaxShowMessage(PMA_messages.strTemplateCreated);
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.error, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a template
|
||||
*
|
||||
* @param id ID of the template to load
|
||||
*/
|
||||
function loadTemplate (id) {
|
||||
var params = {
|
||||
ajax_request : true,
|
||||
server : PMA_commonParams.get('server'),
|
||||
db : PMA_commonParams.get('db'),
|
||||
table : PMA_commonParams.get('table'),
|
||||
exportType : $('input[name="export_type"]').val(),
|
||||
templateAction : 'load',
|
||||
templateId : id,
|
||||
};
|
||||
|
||||
PMA_ajaxShowMessage();
|
||||
$.post('tbl_export.php', params, function (response) {
|
||||
if (response.success === true) {
|
||||
var $form = $('form[name="dump"]');
|
||||
var options = JSON.parse(response.data);
|
||||
$.each(options, function (key, value) {
|
||||
var $element = $form.find('[name="' + key + '"]');
|
||||
if ($element.length) {
|
||||
if (($element.is('input') && $element.attr('type') === 'checkbox') && value === null) {
|
||||
$element.prop('checked', false);
|
||||
} else {
|
||||
if (($element.is('input') && $element.attr('type') === 'checkbox') ||
|
||||
($element.is('input') && $element.attr('type') === 'radio') ||
|
||||
($element.is('select') && $element.attr('multiple') === 'multiple')) {
|
||||
if (! value.push) {
|
||||
value = [value];
|
||||
}
|
||||
}
|
||||
$element.val(value);
|
||||
}
|
||||
$element.trigger('change');
|
||||
}
|
||||
});
|
||||
$('input[name="template_id"]').val(id);
|
||||
PMA_ajaxShowMessage(PMA_messages.strTemplateLoaded);
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.error, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing template with current options
|
||||
*
|
||||
* @param id ID of the template to update
|
||||
*/
|
||||
function updateTemplate (id) {
|
||||
var templateData = getTemplateData();
|
||||
|
||||
var params = {
|
||||
ajax_request : true,
|
||||
server : PMA_commonParams.get('server'),
|
||||
db : PMA_commonParams.get('db'),
|
||||
table : PMA_commonParams.get('table'),
|
||||
exportType : $('input[name="export_type"]').val(),
|
||||
templateAction : 'update',
|
||||
templateId : id,
|
||||
templateData : JSON.stringify(templateData)
|
||||
};
|
||||
|
||||
PMA_ajaxShowMessage();
|
||||
$.post('tbl_export.php', params, function (response) {
|
||||
if (response.success === true) {
|
||||
PMA_ajaxShowMessage(PMA_messages.strTemplateUpdated);
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.error, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a template
|
||||
*
|
||||
* @param id ID of the template to delete
|
||||
*/
|
||||
function deleteTemplate (id) {
|
||||
var params = {
|
||||
ajax_request : true,
|
||||
server : PMA_commonParams.get('server'),
|
||||
db : PMA_commonParams.get('db'),
|
||||
table : PMA_commonParams.get('table'),
|
||||
exportType : $('input[name="export_type"]').val(),
|
||||
templateAction : 'delete',
|
||||
templateId : id,
|
||||
};
|
||||
|
||||
PMA_ajaxShowMessage();
|
||||
$.post('tbl_export.php', params, function (response) {
|
||||
if (response.success === true) {
|
||||
$('#template').find('option[value="' + id + '"]').remove();
|
||||
PMA_ajaxShowMessage(PMA_messages.strTemplateDeleted);
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.error, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbind all event handlers before tearing down a page
|
||||
*/
|
||||
AJAX.registerTeardown('export.js', function () {
|
||||
$('#plugins').off('change');
|
||||
$('input[type=\'radio\'][name=\'sql_structure_or_data\']').off('change');
|
||||
$('input[type=\'radio\'][name$=\'_structure_or_data\']').off('change');
|
||||
$('input[type=\'radio\'][name=\'output_format\']').off('change');
|
||||
$('#checkbox_sql_include_comments').off('change');
|
||||
$('input[type=\'radio\'][name=\'quick_or_custom\']').off('change');
|
||||
$('input[type=\'radio\'][name=\'allrows\']').off('change');
|
||||
$('#btn_alias_config').off('click');
|
||||
$('.alias_remove').off('click');
|
||||
$('#db_alias_button').off('click');
|
||||
$('#table_alias_button').off('click');
|
||||
$('#column_alias_button').off('click');
|
||||
$('input[name="table_select[]"]').off('change');
|
||||
$('input[name="table_structure[]"]').off('change');
|
||||
$('input[name="table_data[]"]').off('change');
|
||||
$('#table_structure_all').off('change');
|
||||
$('#table_data_all').off('change');
|
||||
$('input[name="createTemplate"]').off('click');
|
||||
$('select[name="template"]').off('change');
|
||||
$('input[name="updateTemplate"]').off('click');
|
||||
$('input[name="deleteTemplate"]').off('click');
|
||||
});
|
||||
|
||||
AJAX.registerOnload('export.js', function () {
|
||||
/**
|
||||
* Export template handling code
|
||||
*/
|
||||
// create a new template
|
||||
$('input[name="createTemplate"]').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var name = $('input[name="templateName"]').val();
|
||||
if (name.length) {
|
||||
createTemplate(name);
|
||||
}
|
||||
});
|
||||
|
||||
// load an existing template
|
||||
$('select[name="template"]').on('change', function (e) {
|
||||
e.preventDefault();
|
||||
var id = $(this).val();
|
||||
if (id.length) {
|
||||
loadTemplate(id);
|
||||
}
|
||||
});
|
||||
|
||||
// udpate an existing template with new criteria
|
||||
$('input[name="updateTemplate"]').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var id = $('select[name="template"]').val();
|
||||
if (id.length) {
|
||||
updateTemplate(id);
|
||||
}
|
||||
});
|
||||
|
||||
// delete an existing template
|
||||
$('input[name="deleteTemplate"]').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var id = $('select[name="template"]').val();
|
||||
if (id.length) {
|
||||
deleteTemplate(id);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Toggles the hiding and showing of each plugin's options
|
||||
* according to the currently selected plugin from the dropdown list
|
||||
*/
|
||||
$('#plugins').on('change', function () {
|
||||
$('#format_specific_opts').find('div.format_specific_options').hide();
|
||||
var selected_plugin_name = $('#plugins').find('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\']').on('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').prop('disabled', false).parent().fadeTo('fast', 1);
|
||||
}
|
||||
$('#checkbox_sql_relation').prop('disabled', false).parent().fadeTo('fast', 1);
|
||||
$('#checkbox_sql_mime').prop('disabled', false).parent().fadeTo('fast', 1);
|
||||
}
|
||||
|
||||
if (show === 'structure') {
|
||||
$('#checkbox_sql_auto_increment').prop('disabled', true).parent().fadeTo('fast', 0.4);
|
||||
} else {
|
||||
$('#checkbox_sql_auto_increment').prop('disabled', false).parent().fadeTo('fast', 1);
|
||||
}
|
||||
});
|
||||
|
||||
// For separate-file exports only ZIP compression is allowed
|
||||
$('input[type="checkbox"][name="as_separate_files"]').on('change', function () {
|
||||
if ($(this).is(':checked')) {
|
||||
$('#compression').val('zip');
|
||||
}
|
||||
});
|
||||
|
||||
$('#compression').on('change', function () {
|
||||
if ($('option:selected').val() !== 'zip') {
|
||||
$('input[type="checkbox"][name="as_separate_files"]').prop('checked', false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function setup_table_structure_or_data () {
|
||||
if ($('input[name=\'export_type\']').val() !== 'database') {
|
||||
return;
|
||||
}
|
||||
var pluginName = $('#plugins').find('option:selected').val();
|
||||
var formElemName = pluginName + '_structure_or_data';
|
||||
var force_structure_or_data = !($('input[name=\'' + formElemName + '_default\']').length);
|
||||
|
||||
if (force_structure_or_data === true) {
|
||||
$('input[name="structure_or_data_forced"]').val(1);
|
||||
$('.export_structure input[type="checkbox"], .export_data input[type="checkbox"]')
|
||||
.prop('disabled', true);
|
||||
$('.export_structure, .export_data').fadeTo('fast', 0.4);
|
||||
} else {
|
||||
$('input[name="structure_or_data_forced"]').val(0);
|
||||
$('.export_structure input[type="checkbox"], .export_data input[type="checkbox"]')
|
||||
.prop('disabled', false);
|
||||
$('.export_structure, .export_data').fadeTo('fast', 1);
|
||||
|
||||
var structure_or_data = $('input[name="' + formElemName + '_default"]').val();
|
||||
|
||||
if (structure_or_data === 'structure') {
|
||||
$('.export_data input[type="checkbox"]')
|
||||
.prop('checked', false);
|
||||
} else if (structure_or_data === 'data') {
|
||||
$('.export_structure input[type="checkbox"]')
|
||||
.prop('checked', false);
|
||||
}
|
||||
if (structure_or_data === 'structure' || structure_or_data === 'structure_and_data') {
|
||||
if (!$('.export_structure input[type="checkbox"]:checked').length) {
|
||||
$('input[name="table_select[]"]:checked')
|
||||
.closest('tr')
|
||||
.find('.export_structure input[type="checkbox"]')
|
||||
.prop('checked', true);
|
||||
}
|
||||
}
|
||||
if (structure_or_data === 'data' || structure_or_data === 'structure_and_data') {
|
||||
if (!$('.export_data input[type="checkbox"]:checked').length) {
|
||||
$('input[name="table_select[]"]:checked')
|
||||
.closest('tr')
|
||||
.find('.export_data input[type="checkbox"]')
|
||||
.prop('checked', true);
|
||||
}
|
||||
}
|
||||
|
||||
check_selected_tables();
|
||||
check_table_select_all();
|
||||
check_table_select_struture_or_data();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the hiding and showing of plugin structure-specific and data-specific
|
||||
* options
|
||||
*/
|
||||
function toggle_structure_data_opts () {
|
||||
var pluginName = $('select#plugins').val();
|
||||
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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the disabling of the "save to file" options
|
||||
*/
|
||||
function toggle_save_to_file () {
|
||||
var $ulSaveAsfile = $('#ul_save_asfile');
|
||||
if (!$('#radio_dump_asfile').prop('checked')) {
|
||||
$ulSaveAsfile.find('> li').fadeTo('fast', 0.4);
|
||||
$ulSaveAsfile.find('> li > input').prop('disabled', true);
|
||||
$ulSaveAsfile.find('> li > select').prop('disabled', true);
|
||||
} else {
|
||||
$ulSaveAsfile.find('> li').fadeTo('fast', 1);
|
||||
$ulSaveAsfile.find('> li > input').prop('disabled', false);
|
||||
$ulSaveAsfile.find('> li > select').prop('disabled', false);
|
||||
}
|
||||
}
|
||||
|
||||
AJAX.registerOnload('export.js', function () {
|
||||
toggle_save_to_file();
|
||||
$('input[type=\'radio\'][name=\'output_format\']').on('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').on('change', function () {
|
||||
var $ulIncludeComments = $('#ul_include_comments');
|
||||
if (!$('#checkbox_sql_include_comments').prop('checked')) {
|
||||
$ulIncludeComments.find('> li').fadeTo('fast', 0.4);
|
||||
$ulIncludeComments.find('> 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').prop('disabled', false).parent('li').fadeTo('fast', 1);
|
||||
} else {
|
||||
$ulIncludeComments.find('> li').fadeTo('fast', 1);
|
||||
$ulIncludeComments.find('> li > input').prop('disabled', false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function check_table_select_all () {
|
||||
var total = $('input[name="table_select[]"]').length;
|
||||
var str_checked = $('input[name="table_structure[]"]:checked').length;
|
||||
var data_checked = $('input[name="table_data[]"]:checked').length;
|
||||
var str_all = $('#table_structure_all');
|
||||
var data_all = $('#table_data_all');
|
||||
|
||||
if (str_checked === total) {
|
||||
str_all
|
||||
.prop('indeterminate', false)
|
||||
.prop('checked', true);
|
||||
} else if (str_checked === 0) {
|
||||
str_all
|
||||
.prop('indeterminate', false)
|
||||
.prop('checked', false);
|
||||
} else {
|
||||
str_all
|
||||
.prop('indeterminate', true)
|
||||
.prop('checked', false);
|
||||
}
|
||||
|
||||
if (data_checked === total) {
|
||||
data_all
|
||||
.prop('indeterminate', false)
|
||||
.prop('checked', true);
|
||||
} else if (data_checked === 0) {
|
||||
data_all
|
||||
.prop('indeterminate', false)
|
||||
.prop('checked', false);
|
||||
} else {
|
||||
data_all
|
||||
.prop('indeterminate', true)
|
||||
.prop('checked', false);
|
||||
}
|
||||
}
|
||||
|
||||
function check_table_select_struture_or_data () {
|
||||
var str_checked = $('input[name="table_structure[]"]:checked').length;
|
||||
var data_checked = $('input[name="table_data[]"]:checked').length;
|
||||
var auto_increment = $('#checkbox_sql_auto_increment');
|
||||
|
||||
var pluginName = $('select#plugins').val();
|
||||
var dataDiv = '#' + pluginName + '_data';
|
||||
var structureDiv = '#' + pluginName + '_structure';
|
||||
|
||||
if (str_checked === 0) {
|
||||
$(structureDiv).slideUp('slow');
|
||||
} else {
|
||||
$(structureDiv).slideDown('slow');
|
||||
}
|
||||
|
||||
if (data_checked === 0) {
|
||||
$(dataDiv).slideUp('slow');
|
||||
auto_increment.prop('disabled', true).parent().fadeTo('fast', 0.4);
|
||||
} else {
|
||||
$(dataDiv).slideDown('slow');
|
||||
auto_increment.prop('disabled', false).parent().fadeTo('fast', 1);
|
||||
}
|
||||
}
|
||||
|
||||
function toggle_table_select_all_str () {
|
||||
var str_all = $('#table_structure_all').is(':checked');
|
||||
if (str_all) {
|
||||
$('input[name="table_structure[]"]').prop('checked', true);
|
||||
} else {
|
||||
$('input[name="table_structure[]"]').prop('checked', false);
|
||||
}
|
||||
}
|
||||
|
||||
function toggle_table_select_all_data () {
|
||||
var data_all = $('#table_data_all').is(':checked');
|
||||
if (data_all) {
|
||||
$('input[name="table_data[]"]').prop('checked', true);
|
||||
} else {
|
||||
$('input[name="table_data[]"]').prop('checked', false);
|
||||
}
|
||||
}
|
||||
|
||||
function check_selected_tables (argument) {
|
||||
$('.export_table_select tbody tr').each(function () {
|
||||
check_table_selected(this);
|
||||
});
|
||||
}
|
||||
|
||||
function check_table_selected (row) {
|
||||
var $row = $(row);
|
||||
var table_select = $row.find('input[name="table_select[]"]');
|
||||
var str_check = $row.find('input[name="table_structure[]"]');
|
||||
var data_check = $row.find('input[name="table_data[]"]');
|
||||
|
||||
var data = data_check.is(':checked:not(:disabled)');
|
||||
var structure = str_check.is(':checked:not(:disabled)');
|
||||
|
||||
if (data && structure) {
|
||||
table_select.prop({ checked: true, indeterminate: false });
|
||||
$row.addClass('marked');
|
||||
} else if (data || structure) {
|
||||
table_select.prop({ checked: true, indeterminate: true });
|
||||
$row.removeClass('marked');
|
||||
} else {
|
||||
table_select.prop({ checked: false, indeterminate: false });
|
||||
$row.removeClass('marked');
|
||||
}
|
||||
}
|
||||
|
||||
function toggle_table_select (row) {
|
||||
var $row = $(row);
|
||||
var table_selected = $row.find('input[name="table_select[]"]').is(':checked');
|
||||
|
||||
if (table_selected) {
|
||||
$row.find('input[type="checkbox"]:not(:disabled)').prop('checked', true);
|
||||
$row.addClass('marked');
|
||||
} else {
|
||||
$row.find('input[type="checkbox"]:not(:disabled)').prop('checked', false);
|
||||
$row.removeClass('marked');
|
||||
}
|
||||
}
|
||||
|
||||
function handleAddProcCheckbox () {
|
||||
if ($('#table_structure_all').is(':checked') === true
|
||||
&& $('#table_data_all').is(':checked') === true
|
||||
) {
|
||||
$('#checkbox_sql_procedure_function').prop('checked', true);
|
||||
} else {
|
||||
$('#checkbox_sql_procedure_function').prop('checked', false);
|
||||
}
|
||||
}
|
||||
|
||||
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').find('input');
|
||||
$create.on('change', function () {
|
||||
$create_options.prop('checked', $(this).prop('checked'));
|
||||
});
|
||||
$create_options.on('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').on('change', function () {
|
||||
var active_plugin = $('#plugins').find('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);
|
||||
}
|
||||
});
|
||||
|
||||
$('input[type=\'radio\'][name$=\'_structure_or_data\']').on('change', function () {
|
||||
toggle_structure_data_opts();
|
||||
});
|
||||
|
||||
$('input[name="table_select[]"]').on('change', function () {
|
||||
toggle_table_select($(this).closest('tr'));
|
||||
check_table_select_all();
|
||||
handleAddProcCheckbox();
|
||||
check_table_select_struture_or_data();
|
||||
});
|
||||
|
||||
$('input[name="table_structure[]"]').on('change', function () {
|
||||
check_table_selected($(this).closest('tr'));
|
||||
check_table_select_all();
|
||||
handleAddProcCheckbox();
|
||||
check_table_select_struture_or_data();
|
||||
});
|
||||
|
||||
$('input[name="table_data[]"]').on('change', function () {
|
||||
check_table_selected($(this).closest('tr'));
|
||||
check_table_select_all();
|
||||
handleAddProcCheckbox();
|
||||
check_table_select_struture_or_data();
|
||||
});
|
||||
|
||||
$('#table_structure_all').on('change', function () {
|
||||
toggle_table_select_all_str();
|
||||
check_selected_tables();
|
||||
handleAddProcCheckbox();
|
||||
check_table_select_struture_or_data();
|
||||
});
|
||||
|
||||
$('#table_data_all').on('change', function () {
|
||||
toggle_table_select_all_data();
|
||||
check_selected_tables();
|
||||
handleAddProcCheckbox();
|
||||
check_table_select_struture_or_data();
|
||||
});
|
||||
|
||||
if ($('input[name=\'export_type\']').val() === 'database') {
|
||||
// Hide structure or data radio buttons
|
||||
$('input[type=\'radio\'][name$=\'_structure_or_data\']').each(function () {
|
||||
var $this = $(this);
|
||||
var name = $this.prop('name');
|
||||
var val = $('input[name="' + name + '"]:checked').val();
|
||||
var name_default = name + '_default';
|
||||
if (!$('input[name="' + name_default + '"]').length) {
|
||||
$this
|
||||
.after(
|
||||
$('<input type="hidden" name="' + name_default + '" value="' + val + '" disabled>')
|
||||
)
|
||||
.after(
|
||||
$('<input type="hidden" name="' + name + '" value="structure_and_data">')
|
||||
);
|
||||
$this.parent().find('label').remove();
|
||||
} else {
|
||||
$this.parent().remove();
|
||||
}
|
||||
});
|
||||
$('input[type=\'radio\'][name$=\'_structure_or_data\']').remove();
|
||||
|
||||
// Disable CREATE table checkbox for sql
|
||||
var createTableCheckbox = $('#checkbox_sql_create_table');
|
||||
createTableCheckbox.prop('checked', true);
|
||||
var dummyCreateTable = $('#checkbox_sql_create_table')
|
||||
.clone()
|
||||
.removeAttr('id')
|
||||
.attr('type', 'hidden');
|
||||
createTableCheckbox
|
||||
.prop('disabled', true)
|
||||
.after(dummyCreateTable)
|
||||
.parent()
|
||||
.fadeTo('fast', 0.4);
|
||||
|
||||
setup_table_structure_or_data();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle force structure_or_data
|
||||
*/
|
||||
$('#plugins').on('change', setup_table_structure_or_data);
|
||||
});
|
||||
|
||||
/**
|
||||
* Toggles display of options when quick and custom export are selected
|
||||
*/
|
||||
function toggle_quick_or_custom () {
|
||||
if ($('input[name=\'quick_or_custom\']').length === 0 // custom_no_form option
|
||||
|| $('#radio_custom_export').prop('checked') // custom
|
||||
) {
|
||||
$('#databases_and_tables').show();
|
||||
$('#rows').show();
|
||||
$('#output').show();
|
||||
$('#format_specific_opts').show();
|
||||
$('#output_quick_export').hide();
|
||||
var selected_plugin_name = $('#plugins').find('option:selected').val();
|
||||
$('#' + selected_plugin_name + '_options').show();
|
||||
} else { // quick
|
||||
$('#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,
|
||||
'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 event object 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;
|
||||
if (outer.match(regex)) {
|
||||
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').trigger('change');
|
||||
}
|
||||
$('#alias_modal').dialog('option', 'position', 'center');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for Alias dialog box
|
||||
*
|
||||
* @param event object the event object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function createAliasModal (event) {
|
||||
event.preventDefault();
|
||||
var dlgButtons = {};
|
||||
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),
|
||||
maxHeight: $(window).height(),
|
||||
modal: true,
|
||||
dialogClass: 'alias-dialog',
|
||||
buttons: dlgButtons,
|
||||
create: function () {
|
||||
$(this).css('maxHeight', $(window).height() - 150);
|
||||
var db = PMA_commonParams.get('db');
|
||||
if (db) {
|
||||
var option = $('<option></option>');
|
||||
option.text(db);
|
||||
option.attr('value', db);
|
||||
$('#db_alias_select').append(option).val(db).trigger('change');
|
||||
} else {
|
||||
var params = {
|
||||
ajax_request : true,
|
||||
server : PMA_commonParams.get('server'),
|
||||
type: 'list-databases'
|
||||
};
|
||||
$.post('ajax.php', params, function (response) {
|
||||
if (response.success === true) {
|
||||
$.each(response.databases, function (idx, value) {
|
||||
var option = $('<option></option>');
|
||||
option.text(value);
|
||||
option.attr('value', value);
|
||||
$('#db_alias_select').append(option);
|
||||
});
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.error, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
close: function () {
|
||||
var isEmpty = true;
|
||||
$(this).find('input[type="text"]').each(function () {
|
||||
// trim empty input fields on close
|
||||
if ($(this).val()) {
|
||||
isEmpty = false;
|
||||
} else {
|
||||
$(this).parents('tr').remove();
|
||||
}
|
||||
});
|
||||
// Toggle checkbox based on aliases
|
||||
$('input#btn_alias_config').prop('checked', !isEmpty);
|
||||
},
|
||||
position: { my: 'center top', at: 'center top', of: window }
|
||||
});
|
||||
}
|
||||
|
||||
function aliasToggleRow (elm) {
|
||||
var inputs = elm.parents('tr').find('input,button');
|
||||
if (elm.val()) {
|
||||
inputs.attr('disabled', false);
|
||||
} else {
|
||||
inputs.attr('disabled', true);
|
||||
}
|
||||
}
|
||||
|
||||
function addAlias (type, name, field, value) {
|
||||
if (value === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
var row = $('#alias_data tfoot tr').clone();
|
||||
row.find('th').text(type);
|
||||
row.find('td:first').text(name);
|
||||
row.find('input').attr('name', field);
|
||||
row.find('input').val(value);
|
||||
row.find('.alias_remove').on('click', function () {
|
||||
$(this).parents('tr').remove();
|
||||
});
|
||||
|
||||
var matching = $('#alias_data [name="' + $.escapeSelector(field) + '"]');
|
||||
if (matching.length > 0) {
|
||||
matching.parents('tr').remove();
|
||||
}
|
||||
|
||||
$('#alias_data tbody').append(row);
|
||||
}
|
||||
|
||||
AJAX.registerOnload('export.js', function () {
|
||||
$('input[type=\'radio\'][name=\'quick_or_custom\']').on('change', toggle_quick_or_custom);
|
||||
|
||||
$('#scroll_to_options_msg').hide();
|
||||
$('#format_specific_opts').find('div.format_specific_options')
|
||||
.hide()
|
||||
.css({
|
||||
'border': 0,
|
||||
'margin': 0,
|
||||
'padding': 0
|
||||
})
|
||||
.find('h3')
|
||||
.remove();
|
||||
toggle_quick_or_custom();
|
||||
toggle_structure_data_opts();
|
||||
toggle_sql_include_comments();
|
||||
check_table_select_all();
|
||||
handleAddProcCheckbox();
|
||||
|
||||
/**
|
||||
* 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\']').on('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);
|
||||
$('.alias_remove').on('click', function () {
|
||||
$(this).parents('tr').remove();
|
||||
});
|
||||
$('#db_alias_select').on('change', function () {
|
||||
aliasToggleRow($(this));
|
||||
var db = $(this).val();
|
||||
var table = PMA_commonParams.get('table');
|
||||
if (table) {
|
||||
var option = $('<option></option>');
|
||||
option.text(table);
|
||||
option.attr('value', table);
|
||||
$('#table_alias_select').append(option).val(table).trigger('change');
|
||||
} else {
|
||||
var params = {
|
||||
ajax_request : true,
|
||||
server : PMA_commonParams.get('server'),
|
||||
db : $(this).val(),
|
||||
type: 'list-tables'
|
||||
};
|
||||
$.post('ajax.php', params, function (response) {
|
||||
if (response.success === true) {
|
||||
$.each(response.tables, function (idx, value) {
|
||||
var option = $('<option></option>');
|
||||
option.text(value);
|
||||
option.attr('value', value);
|
||||
$('#table_alias_select').append(option);
|
||||
});
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.error, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
$('#table_alias_select').on('change', function () {
|
||||
aliasToggleRow($(this));
|
||||
var params = {
|
||||
ajax_request : true,
|
||||
server : PMA_commonParams.get('server'),
|
||||
db : $('#db_alias_select').val(),
|
||||
table: $(this).val(),
|
||||
type: 'list-columns'
|
||||
};
|
||||
$.post('ajax.php', params, function (response) {
|
||||
if (response.success === true) {
|
||||
$.each(response.columns, function (idx, value) {
|
||||
var option = $('<option></option>');
|
||||
option.text(value);
|
||||
option.attr('value', value);
|
||||
$('#column_alias_select').append(option);
|
||||
});
|
||||
} else {
|
||||
PMA_ajaxShowMessage(response.error, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
$('#column_alias_select').on('change', function () {
|
||||
aliasToggleRow($(this));
|
||||
});
|
||||
$('#db_alias_button').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var db = $('#db_alias_select').val();
|
||||
addAlias(
|
||||
PMA_messages.strAliasDatabase,
|
||||
db,
|
||||
'aliases[' + db + '][alias]',
|
||||
$('#db_alias_name').val()
|
||||
);
|
||||
$('#db_alias_name').val('');
|
||||
});
|
||||
$('#table_alias_button').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var db = $('#db_alias_select').val();
|
||||
var table = $('#table_alias_select').val();
|
||||
addAlias(
|
||||
PMA_messages.strAliasTable,
|
||||
db + '.' + table,
|
||||
'aliases[' + db + '][tables][' + table + '][alias]',
|
||||
$('#table_alias_name').val()
|
||||
);
|
||||
$('#table_alias_name').val('');
|
||||
});
|
||||
$('#column_alias_button').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var db = $('#db_alias_select').val();
|
||||
var table = $('#table_alias_select').val();
|
||||
var column = $('#column_alias_select').val();
|
||||
addAlias(
|
||||
PMA_messages.strAliasColumn,
|
||||
db + '.' + table + '.' + column,
|
||||
'aliases[' + db + '][tables][' + table + '][colums][' + column + ']',
|
||||
$('#column_alias_name').val()
|
||||
);
|
||||
$('#column_alias_name').val('');
|
||||
});
|
||||
});
|
||||
155
js/import.js
155
js/import.js
@ -1,155 +0,0 @@
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Functions used in the import tab
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Toggles the hiding and showing of each plugin's options
|
||||
* according to the currently selected plugin from the dropdown list
|
||||
*/
|
||||
function changePluginOpts () {
|
||||
$('#format_specific_opts').find('div.format_specific_options').each(function () {
|
||||
$(this).hide();
|
||||
});
|
||||
var selected_plugin_name = $('#plugins').find('option:selected').val();
|
||||
$('#' + selected_plugin_name + '_options').fadeIn('slow');
|
||||
if (selected_plugin_name === 'csv') {
|
||||
$('#import_notification').text(PMA_messages.strImportCSV);
|
||||
} else {
|
||||
$('#import_notification').text('');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the hiding and showing of each plugin's options and sets the selected value
|
||||
* in the plugin dropdown list according to the format of the selected file
|
||||
*/
|
||||
function matchFile (fname) {
|
||||
var fname_array = fname.toLowerCase().split('.');
|
||||
var len = fname_array.length;
|
||||
if (len !== 0) {
|
||||
var extension = fname_array[len - 1];
|
||||
if (extension === 'gz' || extension === 'bz2' || extension === 'zip') {
|
||||
len--;
|
||||
}
|
||||
// Only toggle if the format of the file can be imported
|
||||
if ($('select[name=\'format\'] option').filterByValue(fname_array[len - 1]).length === 1) {
|
||||
$('select[name=\'format\'] option').filterByValue(fname_array[len - 1]).prop('selected', true);
|
||||
changePluginOpts();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbind all event handlers before tearing down a page
|
||||
*/
|
||||
AJAX.registerTeardown('import.js', function () {
|
||||
$('#plugins').off('change');
|
||||
$('#input_import_file').off('change');
|
||||
$('#select_local_import_file').off('change');
|
||||
$('#input_import_file').off('change').off('focus');
|
||||
$('#select_local_import_file').off('focus');
|
||||
$('#text_csv_enclosed').add('#text_csv_escaped').off('keyup');
|
||||
});
|
||||
|
||||
AJAX.registerOnload('import.js', function () {
|
||||
// import_file_form validation.
|
||||
$(document).on('submit', '#import_file_form', function (event) {
|
||||
var radioLocalImport = $('#radio_local_import_file');
|
||||
var radioImport = $('#radio_import_file');
|
||||
var fileMsg = '<div class="error"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error" /> ' + PMA_messages.strImportDialogMessage + '</div>';
|
||||
|
||||
if (radioLocalImport.length !== 0) {
|
||||
// remote upload.
|
||||
|
||||
if (radioImport.is(':checked') && $('#input_import_file').val() === '') {
|
||||
$('#input_import_file').trigger('focus');
|
||||
PMA_ajaxShowMessage(fileMsg, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (radioLocalImport.is(':checked')) {
|
||||
if ($('#select_local_import_file').length === 0) {
|
||||
PMA_ajaxShowMessage('<div class="error"><img src="themes/dot.gif" title="" alt="" class="icon ic_s_error" /> ' + PMA_messages.strNoImportFile + ' </div>', false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($('#select_local_import_file').val() === '') {
|
||||
$('#select_local_import_file').trigger('focus');
|
||||
PMA_ajaxShowMessage(fileMsg, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// local upload.
|
||||
if ($('#input_import_file').val() === '') {
|
||||
$('#input_import_file').trigger('focus');
|
||||
PMA_ajaxShowMessage(fileMsg, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// show progress bar.
|
||||
$('#upload_form_status').css('display', 'inline');
|
||||
$('#upload_form_status_info').css('display', 'inline');
|
||||
});
|
||||
|
||||
// Initially display the options for the selected plugin
|
||||
changePluginOpts();
|
||||
|
||||
// Whenever the selected plugin changes, change the options displayed
|
||||
$('#plugins').on('change', function () {
|
||||
changePluginOpts();
|
||||
});
|
||||
|
||||
$('#input_import_file').on('change', function () {
|
||||
matchFile($(this).val());
|
||||
});
|
||||
|
||||
$('#select_local_import_file').on('change', function () {
|
||||
matchFile($(this).val());
|
||||
});
|
||||
|
||||
/*
|
||||
* When the "Browse the server" form is clicked or the "Select from the web server upload directory"
|
||||
* form is clicked, the radio button beside it becomes selected and the other form becomes disabled.
|
||||
*/
|
||||
$('#input_import_file').on('focus change', function () {
|
||||
$('#radio_import_file').prop('checked', true);
|
||||
$('#radio_local_import_file').prop('checked', false);
|
||||
});
|
||||
$('#select_local_import_file').on('focus', function () {
|
||||
$('#radio_local_import_file').prop('checked', true);
|
||||
$('#radio_import_file').prop('checked', false);
|
||||
});
|
||||
|
||||
/**
|
||||
* Set up the interface for Javascript-enabled browsers since the default is for
|
||||
* Javascript-disabled browsers
|
||||
*/
|
||||
$('#scroll_to_options_msg').hide();
|
||||
$('#format_specific_opts').find('div.format_specific_options')
|
||||
.css({
|
||||
'border': 0,
|
||||
'margin': 0,
|
||||
'padding': 0
|
||||
})
|
||||
.find('h3')
|
||||
.remove();
|
||||
// $("form[name=import] *").unwrap();
|
||||
|
||||
/**
|
||||
* for input element text_csv_enclosed and text_csv_escaped allow just one character to enter.
|
||||
* as mysql allows just one character for these fields,
|
||||
* if first character is escape then allow two including escape character.
|
||||
*/
|
||||
$('#text_csv_enclosed').add('#text_csv_escaped').on('keyup', function () {
|
||||
if ($(this).val().length === 2 && $(this).val().charAt(0) !== '\\') {
|
||||
$(this).val($(this).val().substring(0, 1));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
755
js/indexes.js
755
js/indexes.js
@ -1,755 +0,0 @@
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* @fileoverview function used for index manipulation pages
|
||||
* @name Table Structure
|
||||
*
|
||||
* @requires jQuery
|
||||
* @requires jQueryUI
|
||||
* @required js/functions.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the array of indexes based on the index choice
|
||||
*
|
||||
* @param index_choice index choice
|
||||
*/
|
||||
function PMA_getIndexArray (index_choice) {
|
||||
var source_array = null;
|
||||
|
||||
switch (index_choice.toLowerCase()) {
|
||||
case 'primary':
|
||||
source_array = primary_indexes;
|
||||
break;
|
||||
case 'unique':
|
||||
source_array = unique_indexes;
|
||||
break;
|
||||
case 'index':
|
||||
source_array = indexes;
|
||||
break;
|
||||
case 'fulltext':
|
||||
source_array = fulltext_indexes;
|
||||
break;
|
||||
case 'spatial':
|
||||
source_array = spatial_indexes;
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return source_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hides/shows the inputs and submits appropriately depending
|
||||
* on whether the index type chosen is 'SPATIAL' or not.
|
||||
*/
|
||||
function checkIndexType () {
|
||||
/**
|
||||
* @var Object Dropdown to select the index choice.
|
||||
*/
|
||||
var $select_index_choice = $('#select_index_choice');
|
||||
/**
|
||||
* @var Object Dropdown to select the index type.
|
||||
*/
|
||||
var $select_index_type = $('#select_index_type');
|
||||
/**
|
||||
* @var Object Table header for the size column.
|
||||
*/
|
||||
var $size_header = $('#index_columns').find('thead tr th:nth-child(2)');
|
||||
/**
|
||||
* @var Object Inputs to specify the columns for the index.
|
||||
*/
|
||||
var $column_inputs = $('select[name="index[columns][names][]"]');
|
||||
/**
|
||||
* @var Object Inputs to specify sizes for columns of the index.
|
||||
*/
|
||||
var $size_inputs = $('input[name="index[columns][sub_parts][]"]');
|
||||
/**
|
||||
* @var Object Footer containg the controllers to add more columns
|
||||
*/
|
||||
var $add_more = $('#index_frm').find('.add_more');
|
||||
|
||||
if ($select_index_choice.val() === 'SPATIAL') {
|
||||
// Disable and hide the size column
|
||||
$size_header.hide();
|
||||
$size_inputs.each(function () {
|
||||
$(this)
|
||||
.prop('disabled', true)
|
||||
.parent('td').hide();
|
||||
});
|
||||
|
||||
// Disable and hide the columns of the index other than the first one
|
||||
var initial = true;
|
||||
$column_inputs.each(function () {
|
||||
$column_input = $(this);
|
||||
if (! initial) {
|
||||
$column_input
|
||||
.prop('disabled', true)
|
||||
.parent('td').hide();
|
||||
} else {
|
||||
initial = false;
|
||||
}
|
||||
});
|
||||
|
||||
// Hide controllers to add more columns
|
||||
$add_more.hide();
|
||||
} else {
|
||||
// Enable and show the size column
|
||||
$size_header.show();
|
||||
$size_inputs.each(function () {
|
||||
$(this)
|
||||
.prop('disabled', false)
|
||||
.parent('td').show();
|
||||
});
|
||||
|
||||
// Enable and show the columns of the index
|
||||
$column_inputs.each(function () {
|
||||
$(this)
|
||||
.prop('disabled', false)
|
||||
.parent('td').show();
|
||||
});
|
||||
|
||||
// Show controllers to add more columns
|
||||
$add_more.show();
|
||||
}
|
||||
|
||||
if ($select_index_choice.val() === 'SPATIAL' ||
|
||||
$select_index_choice.val() === 'FULLTEXT') {
|
||||
$select_index_type.val('').prop('disabled', true);
|
||||
} else {
|
||||
$select_index_type.prop('disabled', false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current index information into form parameters.
|
||||
*
|
||||
* @param array source_array Array containing index columns
|
||||
* @param string index_choice Choice of index
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_setIndexFormParameters (source_array, index_choice) {
|
||||
if (index_choice === 'index') {
|
||||
$('input[name="indexes"]').val(JSON.stringify(source_array));
|
||||
} else {
|
||||
$('input[name="' + index_choice + '_indexes"]').val(JSON.stringify(source_array));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a column from an Index.
|
||||
*
|
||||
* @param string col_index Index of column in form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_removeColumnFromIndex (col_index) {
|
||||
// Get previous index details.
|
||||
var previous_index = $('select[name="field_key[' + col_index + ']"]')
|
||||
.attr('data-index');
|
||||
if (previous_index.length) {
|
||||
previous_index = previous_index.split(',');
|
||||
var source_array = PMA_getIndexArray(previous_index[0]);
|
||||
if (source_array === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove column from index array.
|
||||
var source_length = source_array[previous_index[1]].columns.length;
|
||||
for (var i = 0; i < source_length; i++) {
|
||||
if (source_array[previous_index[1]].columns[i].col_index === col_index) {
|
||||
source_array[previous_index[1]].columns.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove index completely if no columns left.
|
||||
if (source_array[previous_index[1]].columns.length === 0) {
|
||||
source_array.splice(previous_index[1], 1);
|
||||
}
|
||||
|
||||
// Update current index details.
|
||||
$('select[name="field_key[' + col_index + ']"]').attr('data-index', '');
|
||||
// Update form index parameters.
|
||||
PMA_setIndexFormParameters(source_array, previous_index[0].toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a column to an Index.
|
||||
*
|
||||
* @param array source_array Array holding corresponding indexes
|
||||
* @param string array_index Index of an INDEX in array
|
||||
* @param string index_choice Choice of Index
|
||||
* @param string col_index Index of column on form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_addColumnToIndex (source_array, array_index, index_choice, col_index) {
|
||||
if (col_index >= 0) {
|
||||
// Remove column from other indexes (if any).
|
||||
PMA_removeColumnFromIndex(col_index);
|
||||
}
|
||||
var index_name = $('input[name="index[Key_name]"]').val();
|
||||
var index_comment = $('input[name="index[Index_comment]"]').val();
|
||||
var key_block_size = $('input[name="index[Key_block_size]"]').val();
|
||||
var parser = $('input[name="index[Parser]"]').val();
|
||||
var index_type = $('select[name="index[Index_type]"]').val();
|
||||
var columns = [];
|
||||
$('#index_columns').find('tbody').find('tr').each(function () {
|
||||
// Get columns in particular order.
|
||||
var col_index = $(this).find('select[name="index[columns][names][]"]').val();
|
||||
var size = $(this).find('input[name="index[columns][sub_parts][]"]').val();
|
||||
columns.push({
|
||||
'col_index': col_index,
|
||||
'size': size
|
||||
});
|
||||
});
|
||||
|
||||
// Update or create an index.
|
||||
source_array[array_index] = {
|
||||
'Key_name': index_name,
|
||||
'Index_comment': index_comment,
|
||||
'Index_choice': index_choice.toUpperCase(),
|
||||
'Key_block_size': key_block_size,
|
||||
'Parser': parser,
|
||||
'Index_type': index_type,
|
||||
'columns': columns
|
||||
};
|
||||
|
||||
// Display index name (or column list)
|
||||
var displayName = index_name;
|
||||
if (displayName === '') {
|
||||
var columnNames = [];
|
||||
$.each(columns, function () {
|
||||
columnNames.push($('input[name="field_name[' + this.col_index + ']"]').val());
|
||||
});
|
||||
displayName = '[' + columnNames.join(', ') + ']';
|
||||
}
|
||||
$.each(columns, function () {
|
||||
var id = 'index_name_' + this.col_index + '_8';
|
||||
var $name = $('#' + id);
|
||||
if ($name.length === 0) {
|
||||
$name = $('<a id="' + id + '" href="#" class="ajax show_index_dialog"></a>');
|
||||
$name.insertAfter($('select[name="field_key[' + this.col_index + ']"]'));
|
||||
}
|
||||
var $text = $('<small>').text(displayName);
|
||||
$name.html($text);
|
||||
});
|
||||
|
||||
if (col_index >= 0) {
|
||||
// Update index details on form.
|
||||
$('select[name="field_key[' + col_index + ']"]')
|
||||
.attr('data-index', index_choice + ',' + array_index);
|
||||
}
|
||||
PMA_setIndexFormParameters(source_array, index_choice.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get choices list for a column to create a composite index with.
|
||||
*
|
||||
* @param string index_choice Choice of index
|
||||
* @param array source_array Array hodling columns for particular index
|
||||
*
|
||||
* @return jQuery Object
|
||||
*/
|
||||
function PMA_getCompositeIndexList (source_array, col_index) {
|
||||
// Remove any previous list.
|
||||
if ($('#composite_index_list').length) {
|
||||
$('#composite_index_list').remove();
|
||||
}
|
||||
|
||||
// Html list.
|
||||
var $composite_index_list = $(
|
||||
'<ul id="composite_index_list">' +
|
||||
'<div>' + PMA_messages.strCompositeWith + '</div>' +
|
||||
'</ul>'
|
||||
);
|
||||
|
||||
// Add each column to list available for composite index.
|
||||
var source_length = source_array.length;
|
||||
var already_present = false;
|
||||
for (var i = 0; i < source_length; i++) {
|
||||
var sub_array_len = source_array[i].columns.length;
|
||||
var column_names = [];
|
||||
for (var j = 0; j < sub_array_len; j++) {
|
||||
column_names.push(
|
||||
$('input[name="field_name[' + source_array[i].columns[j].col_index + ']"]').val()
|
||||
);
|
||||
|
||||
if (col_index === source_array[i].columns[j].col_index) {
|
||||
already_present = true;
|
||||
}
|
||||
}
|
||||
|
||||
$composite_index_list.append(
|
||||
'<li>' +
|
||||
'<input type="radio" name="composite_with" ' +
|
||||
(already_present ? 'checked="checked"' : '') +
|
||||
' id="composite_index_' + i + '" value="' + i + '">' +
|
||||
'<label for="composite_index_' + i + '">' + column_names.join(', ') +
|
||||
'</lablel>' +
|
||||
'</li>'
|
||||
);
|
||||
}
|
||||
|
||||
return $composite_index_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows 'Add Index' dialog.
|
||||
*
|
||||
* @param array source_array Array holding particluar index
|
||||
* @param string array_index Index of an INDEX in array
|
||||
* @param array target_columns Columns for an INDEX
|
||||
* @param string col_index Index of column on form
|
||||
* @param object index Index detail object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_showAddIndexDialog (source_array, array_index, target_columns, col_index, index) {
|
||||
// Prepare post-data.
|
||||
var $table = $('input[name="table"]');
|
||||
var table = $table.length > 0 ? $table.val() : '';
|
||||
var post_data = {
|
||||
server: PMA_commonParams.get('server'),
|
||||
db: $('input[name="db"]').val(),
|
||||
table: table,
|
||||
ajax_request: 1,
|
||||
create_edit_table: 1,
|
||||
index: index
|
||||
};
|
||||
|
||||
var columns = {};
|
||||
for (var i = 0; i < target_columns.length; i++) {
|
||||
var column_name = $('input[name="field_name[' + target_columns[i] + ']"]').val();
|
||||
var column_type = $('select[name="field_type[' + target_columns[i] + ']"]').val().toLowerCase();
|
||||
columns[column_name] = [column_type, target_columns[i]];
|
||||
}
|
||||
post_data.columns = JSON.stringify(columns);
|
||||
|
||||
var button_options = {};
|
||||
button_options[PMA_messages.strGo] = function () {
|
||||
var is_missing_value = false;
|
||||
$('select[name="index[columns][names][]"]').each(function () {
|
||||
if ($(this).val() === '') {
|
||||
is_missing_value = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (! is_missing_value) {
|
||||
PMA_addColumnToIndex(
|
||||
source_array,
|
||||
array_index,
|
||||
index.Index_choice,
|
||||
col_index
|
||||
);
|
||||
} else {
|
||||
PMA_ajaxShowMessage(
|
||||
'<div class="error"><img src="themes/dot.gif" title="" alt=""' +
|
||||
' class="icon ic_s_error" /> ' + PMA_messages.strMissingColumn +
|
||||
' </div>', false
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$(this).dialog('close');
|
||||
};
|
||||
button_options[PMA_messages.strCancel] = function () {
|
||||
if (col_index >= 0) {
|
||||
// Handle state on 'Cancel'.
|
||||
var $select_list = $('select[name="field_key[' + col_index + ']"]');
|
||||
if (! $select_list.attr('data-index').length) {
|
||||
$select_list.find('option[value*="none"]').attr('selected', 'selected');
|
||||
} else {
|
||||
var previous_index = $select_list.attr('data-index').split(',');
|
||||
$select_list.find('option[value*="' + previous_index[0].toLowerCase() + '"]')
|
||||
.attr('selected', 'selected');
|
||||
}
|
||||
}
|
||||
$(this).dialog('close');
|
||||
};
|
||||
var $msgbox = PMA_ajaxShowMessage();
|
||||
$.post('tbl_indexes.php', post_data, function (data) {
|
||||
if (data.success === false) {
|
||||
// in the case of an error, show the error message returned.
|
||||
PMA_ajaxShowMessage(data.error, false);
|
||||
} else {
|
||||
PMA_ajaxRemoveMessage($msgbox);
|
||||
// Show dialog if the request was successful
|
||||
var $div = $('<div/>');
|
||||
$div
|
||||
.append(data.message)
|
||||
.dialog({
|
||||
title: PMA_messages.strAddIndex,
|
||||
width: 450,
|
||||
minHeight: 250,
|
||||
open: function () {
|
||||
checkIndexName('index_frm');
|
||||
PMA_showHints($div);
|
||||
PMA_init_slider();
|
||||
$('#index_columns').find('td').each(function () {
|
||||
$(this).css('width', $(this).width() + 'px');
|
||||
});
|
||||
$('#index_columns').find('tbody').sortable({
|
||||
axis: 'y',
|
||||
containment: $('#index_columns').find('tbody'),
|
||||
tolerance: 'pointer'
|
||||
});
|
||||
// We dont need the slider at this moment.
|
||||
$(this).find('fieldset.tblFooters').remove();
|
||||
},
|
||||
modal: true,
|
||||
buttons: button_options,
|
||||
close: function () {
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a advanced index type selection dialog.
|
||||
*
|
||||
* @param array source_array Array holding a particular type of indexes
|
||||
* @param string index_choice Choice of index
|
||||
* @param string col_index Index of new column on form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_indexTypeSelectionDialog (source_array, index_choice, col_index) {
|
||||
var $single_column_radio = $('<input type="radio" id="single_column" name="index_choice"' +
|
||||
' checked="checked">' +
|
||||
'<label for="single_column">' + PMA_messages.strCreateSingleColumnIndex + '</label>');
|
||||
var $composite_index_radio = $('<input type="radio" id="composite_index"' +
|
||||
' name="index_choice">' +
|
||||
'<label for="composite_index">' + PMA_messages.strCreateCompositeIndex + '</label>');
|
||||
var $dialog_content = $('<fieldset id="advance_index_creator"></fieldset>');
|
||||
$dialog_content.append('<legend>' + index_choice.toUpperCase() + '</legend>');
|
||||
|
||||
|
||||
// For UNIQUE/INDEX type, show choice for single-column and composite index.
|
||||
$dialog_content.append($single_column_radio);
|
||||
$dialog_content.append($composite_index_radio);
|
||||
|
||||
var button_options = {};
|
||||
// 'OK' operation.
|
||||
button_options[PMA_messages.strGo] = function () {
|
||||
if ($('#single_column').is(':checked')) {
|
||||
var index = {
|
||||
'Key_name': (index_choice === 'primary' ? 'PRIMARY' : ''),
|
||||
'Index_choice': index_choice.toUpperCase()
|
||||
};
|
||||
PMA_showAddIndexDialog(source_array, (source_array.length), [col_index], col_index, index);
|
||||
}
|
||||
|
||||
if ($('#composite_index').is(':checked')) {
|
||||
if ($('input[name="composite_with"]').length !== 0 && $('input[name="composite_with"]:checked').length === 0
|
||||
) {
|
||||
PMA_ajaxShowMessage(
|
||||
'<div class="error"><img src="themes/dot.gif" title=""' +
|
||||
' alt="" class="icon ic_s_error" /> ' +
|
||||
PMA_messages.strFormEmpty +
|
||||
' </div>',
|
||||
false
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
var array_index = $('input[name="composite_with"]:checked').val();
|
||||
var source_length = source_array[array_index].columns.length;
|
||||
var target_columns = [];
|
||||
for (var i = 0; i < source_length; i++) {
|
||||
target_columns.push(source_array[array_index].columns[i].col_index);
|
||||
}
|
||||
target_columns.push(col_index);
|
||||
|
||||
PMA_showAddIndexDialog(source_array, array_index, target_columns, col_index,
|
||||
source_array[array_index]);
|
||||
}
|
||||
|
||||
$(this).remove();
|
||||
};
|
||||
button_options[PMA_messages.strCancel] = function () {
|
||||
// Handle state on 'Cancel'.
|
||||
var $select_list = $('select[name="field_key[' + col_index + ']"]');
|
||||
if (! $select_list.attr('data-index').length) {
|
||||
$select_list.find('option[value*="none"]').attr('selected', 'selected');
|
||||
} else {
|
||||
var previous_index = $select_list.attr('data-index').split(',');
|
||||
$select_list.find('option[value*="' + previous_index[0].toLowerCase() + '"]')
|
||||
.attr('selected', 'selected');
|
||||
}
|
||||
$(this).remove();
|
||||
};
|
||||
var $dialog = $('<div/>').append($dialog_content).dialog({
|
||||
minWidth: 525,
|
||||
minHeight: 200,
|
||||
modal: true,
|
||||
title: PMA_messages.strAddIndex,
|
||||
resizable: false,
|
||||
buttons: button_options,
|
||||
open: function () {
|
||||
$('#composite_index').on('change', function () {
|
||||
if ($(this).is(':checked')) {
|
||||
$dialog_content.append(PMA_getCompositeIndexList(source_array, col_index));
|
||||
}
|
||||
});
|
||||
$('#single_column').on('change', function () {
|
||||
if ($(this).is(':checked')) {
|
||||
if ($('#composite_index_list').length) {
|
||||
$('#composite_index_list').remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
close: function () {
|
||||
$('#composite_index').off('change');
|
||||
$('#single_column').off('change');
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbind all event handlers before tearing down a page
|
||||
*/
|
||||
AJAX.registerTeardown('indexes.js', function () {
|
||||
$(document).off('click', '#save_index_frm');
|
||||
$(document).off('click', '#preview_index_frm');
|
||||
$(document).off('change', '#select_index_choice');
|
||||
$(document).off('click', 'a.drop_primary_key_index_anchor.ajax');
|
||||
$(document).off('click', '#table_index tbody tr td.edit_index.ajax, #index_div .add_index.ajax');
|
||||
$(document).off('click', '#index_frm input[type=submit]');
|
||||
$('body').off('change', 'select[name*="field_key"]');
|
||||
$(document).off('click', '.show_index_dialog');
|
||||
});
|
||||
|
||||
/**
|
||||
* @description <p>Ajax scripts for table index page</p>
|
||||
*
|
||||
* Actions ajaxified here:
|
||||
* <ul>
|
||||
* <li>Showing/hiding inputs depending on the index type chosen</li>
|
||||
* <li>create/edit/drop indexes</li>
|
||||
* </ul>
|
||||
*/
|
||||
AJAX.registerOnload('indexes.js', function () {
|
||||
// Re-initialize variables.
|
||||
primary_indexes = [];
|
||||
unique_indexes = [];
|
||||
indexes = [];
|
||||
fulltext_indexes = [];
|
||||
spatial_indexes = [];
|
||||
|
||||
// for table creation form
|
||||
var $engine_selector = $('.create_table_form select[name=tbl_storage_engine]');
|
||||
if ($engine_selector.length) {
|
||||
PMA_hideShowConnection($engine_selector);
|
||||
}
|
||||
|
||||
var $form = $('#index_frm');
|
||||
if ($form.length > 0) {
|
||||
showIndexEditDialog($form);
|
||||
}
|
||||
|
||||
$(document).on('click', '#save_index_frm', function (event) {
|
||||
event.preventDefault();
|
||||
var $form = $('#index_frm');
|
||||
var argsep = PMA_commonParams.get('arg_separator');
|
||||
var submitData = $form.serialize() + argsep + 'do_save_data=1' + argsep + 'ajax_request=true' + argsep + 'ajax_page_request=true';
|
||||
var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
|
||||
AJAX.source = $form;
|
||||
$.post($form.attr('action'), submitData, AJAX.responseHandler);
|
||||
});
|
||||
|
||||
$(document).on('click', '#preview_index_frm', function (event) {
|
||||
event.preventDefault();
|
||||
PMA_previewSQL($('#index_frm'));
|
||||
});
|
||||
|
||||
$(document).on('change', '#select_index_choice', function (event) {
|
||||
event.preventDefault();
|
||||
checkIndexType();
|
||||
checkIndexName('index_frm');
|
||||
});
|
||||
|
||||
/**
|
||||
* Ajax Event handler for 'Drop Index'
|
||||
*/
|
||||
$(document).on('click', 'a.drop_primary_key_index_anchor.ajax', function (event) {
|
||||
event.preventDefault();
|
||||
var $anchor = $(this);
|
||||
/**
|
||||
* @var $curr_row Object containing reference to the current field's row
|
||||
*/
|
||||
var $curr_row = $anchor.parents('tr');
|
||||
/** @var Number of columns in the key */
|
||||
var rows = $anchor.parents('td').attr('rowspan') || 1;
|
||||
/** @var Rows that should be hidden */
|
||||
var $rows_to_hide = $curr_row;
|
||||
for (var i = 1, $last_row = $curr_row.next(); i < rows; i++, $last_row = $last_row.next()) {
|
||||
$rows_to_hide = $rows_to_hide.add($last_row);
|
||||
}
|
||||
|
||||
var question = escapeHtml(
|
||||
$curr_row.children('td')
|
||||
.children('.drop_primary_key_index_msg')
|
||||
.val()
|
||||
);
|
||||
|
||||
$anchor.PMA_confirm(question, $anchor.attr('href'), function (url) {
|
||||
var $msg = PMA_ajaxShowMessage(PMA_messages.strDroppingPrimaryKeyIndex, false);
|
||||
var params = getJSConfirmCommonParam(this, $anchor.getPostData());
|
||||
$.post(url, params, function (data) {
|
||||
if (typeof data !== 'undefined' && data.success === true) {
|
||||
PMA_ajaxRemoveMessage($msg);
|
||||
var $table_ref = $rows_to_hide.closest('table');
|
||||
if ($rows_to_hide.length === $table_ref.find('tbody > tr').length) {
|
||||
// We are about to remove all rows from the table
|
||||
$table_ref.hide('medium', function () {
|
||||
$('div.no_indexes_defined').show('medium');
|
||||
$rows_to_hide.remove();
|
||||
});
|
||||
$table_ref.siblings('div.notice').hide('medium');
|
||||
} else {
|
||||
// We are removing some of the rows only
|
||||
$rows_to_hide.hide('medium', function () {
|
||||
$(this).remove();
|
||||
});
|
||||
}
|
||||
if ($('.result_query').length) {
|
||||
$('.result_query').remove();
|
||||
}
|
||||
if (data.sql_query) {
|
||||
$('<div class="result_query"></div>')
|
||||
.html(data.sql_query)
|
||||
.prependTo('#structure_content');
|
||||
PMA_highlightSQL($('#page_content'));
|
||||
}
|
||||
PMA_commonActions.refreshMain(false, function () {
|
||||
$('a.ajax[href^=#indexes]').trigger('click');
|
||||
});
|
||||
PMA_reloadNavigation();
|
||||
} else {
|
||||
PMA_ajaxShowMessage(PMA_messages.strErrorProcessingRequest + ' : ' + data.error, false);
|
||||
}
|
||||
}); // end $.post()
|
||||
}); // end $.PMA_confirm()
|
||||
}); // end Drop Primary Key/Index
|
||||
|
||||
/**
|
||||
*Ajax event handler for index edit
|
||||
**/
|
||||
$(document).on('click', '#table_index tbody tr td.edit_index.ajax, #index_div .add_index.ajax', function (event) {
|
||||
event.preventDefault();
|
||||
var url;
|
||||
var title;
|
||||
if ($(this).find('a').length === 0) {
|
||||
// Add index
|
||||
var valid = checkFormElementInRange(
|
||||
$(this).closest('form')[0],
|
||||
'added_fields',
|
||||
'Column count has to be larger than zero.'
|
||||
);
|
||||
if (! valid) {
|
||||
return;
|
||||
}
|
||||
url = $(this).closest('form').serialize();
|
||||
title = PMA_messages.strAddIndex;
|
||||
} else {
|
||||
// Edit index
|
||||
url = $(this).find('a').attr('href');
|
||||
if (url.substring(0, 16) === 'tbl_indexes.php?') {
|
||||
url = url.substring(16, url.length);
|
||||
}
|
||||
title = PMA_messages.strEditIndex;
|
||||
}
|
||||
url += PMA_commonParams.get('arg_separator') + 'ajax_request=true';
|
||||
indexEditorDialog(url, title, function () {
|
||||
// refresh the page using ajax
|
||||
PMA_commonActions.refreshMain(false, function () {
|
||||
$('a.ajax[href^=#indexes]').trigger('click');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Ajax event handler for advanced index creation during table creation
|
||||
* and column addition.
|
||||
*/
|
||||
$('body').on('change', 'select[name*="field_key"]', function () {
|
||||
// Index of column on Table edit and create page.
|
||||
var col_index = /\d+/.exec($(this).attr('name'));
|
||||
col_index = col_index[0];
|
||||
// Choice of selected index.
|
||||
var index_choice = /[a-z]+/.exec($(this).val());
|
||||
index_choice = index_choice[0];
|
||||
// Array containing corresponding indexes.
|
||||
var source_array = null;
|
||||
|
||||
if (index_choice === 'none') {
|
||||
PMA_removeColumnFromIndex(col_index);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Select a source array.
|
||||
source_array = PMA_getIndexArray(index_choice);
|
||||
if (source_array === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (source_array.length === 0) {
|
||||
var index = {
|
||||
'Key_name': (index_choice === 'primary' ? 'PRIMARY' : ''),
|
||||
'Index_choice': index_choice.toUpperCase()
|
||||
};
|
||||
PMA_showAddIndexDialog(source_array, 0, [col_index], col_index, index);
|
||||
} else {
|
||||
if (index_choice === 'primary') {
|
||||
var array_index = 0;
|
||||
var source_length = source_array[array_index].columns.length;
|
||||
var target_columns = [];
|
||||
for (var i = 0; i < source_length; i++) {
|
||||
target_columns.push(source_array[array_index].columns[i].col_index);
|
||||
}
|
||||
target_columns.push(col_index);
|
||||
|
||||
PMA_showAddIndexDialog(source_array, array_index, target_columns, col_index,
|
||||
source_array[array_index]);
|
||||
} else {
|
||||
// If there are multiple columns selected for an index, show advanced dialog.
|
||||
PMA_indexTypeSelectionDialog(source_array, index_choice, col_index);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('click', '.show_index_dialog', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Get index details.
|
||||
var previous_index = $(this).prev('select')
|
||||
.attr('data-index')
|
||||
.split(',');
|
||||
|
||||
var index_choice = previous_index[0];
|
||||
var array_index = previous_index[1];
|
||||
|
||||
var source_array = PMA_getIndexArray(index_choice);
|
||||
var source_length = source_array[array_index].columns.length;
|
||||
|
||||
var target_columns = [];
|
||||
for (var i = 0; i < source_length; i++) {
|
||||
target_columns.push(source_array[array_index].columns[i].col_index);
|
||||
}
|
||||
|
||||
PMA_showAddIndexDialog(source_array, array_index, target_columns, -1, source_array[array_index]);
|
||||
});
|
||||
|
||||
$('#index_frm').on('submit', function () {
|
||||
if (typeof(this.elements['index[Key_name]'].disabled) !== 'undefined') {
|
||||
this.elements['index[Key_name]'].disabled = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1,101 +0,0 @@
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* @fileoverview Handle shortcuts in various pages
|
||||
* @name Shortcuts handler
|
||||
*
|
||||
* @requires jQuery
|
||||
* @requires jQueryUI
|
||||
*/
|
||||
|
||||
/**
|
||||
* Register key events on load
|
||||
*/
|
||||
$(document).ready(function () {
|
||||
var databaseOp = false;
|
||||
var tableOp = false;
|
||||
var keyD = 68;
|
||||
var keyT = 84;
|
||||
var keyK = 75;
|
||||
var keyS = 83;
|
||||
var keyF = 70;
|
||||
var keyE = 69;
|
||||
var keyH = 72;
|
||||
var keyC = 67;
|
||||
var keyBackSpace = 8;
|
||||
$(document).on('keyup', function (e) {
|
||||
if (e.target.nodeName === 'INPUT' || e.target.nodeName === 'TEXTAREA' || e.target.nodeName === 'SELECT') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.keyCode === keyD) {
|
||||
setTimeout(function () {
|
||||
databaseOp = false;
|
||||
}, 2000);
|
||||
} else if (e.keyCode === keyT) {
|
||||
setTimeout(function () {
|
||||
tableOp = false;
|
||||
}, 2000);
|
||||
}
|
||||
});
|
||||
$(document).on('keydown', function (e) {
|
||||
if (e.ctrlKey && e.altKey && e.keyCode === keyC) {
|
||||
PMA_console.toggle();
|
||||
}
|
||||
|
||||
if (e.ctrlKey && e.keyCode === keyK) {
|
||||
e.preventDefault();
|
||||
PMA_console.toggle();
|
||||
}
|
||||
|
||||
if (e.target.nodeName === 'INPUT' || e.target.nodeName === 'TEXTAREA' || e.target.nodeName === 'SELECT') {
|
||||
return;
|
||||
}
|
||||
|
||||
var isTable;
|
||||
var isDb;
|
||||
if (e.keyCode === keyD) {
|
||||
databaseOp = true;
|
||||
} else if (e.keyCode === keyK) {
|
||||
e.preventDefault();
|
||||
PMA_console.toggle();
|
||||
} else if (e.keyCode === keyS) {
|
||||
if (databaseOp === true) {
|
||||
isTable = PMA_commonParams.get('table');
|
||||
isDb = PMA_commonParams.get('db');
|
||||
if (isDb && ! isTable) {
|
||||
$('.tab .ic_b_props').first().trigger('click');
|
||||
}
|
||||
} else if (tableOp === true) {
|
||||
isTable = PMA_commonParams.get('table');
|
||||
isDb = PMA_commonParams.get('db');
|
||||
if (isDb && isTable) {
|
||||
$('.tab .ic_b_props').first().trigger('click');
|
||||
}
|
||||
} else {
|
||||
$('#pma_navigation_settings_icon').trigger('click');
|
||||
}
|
||||
} else if (e.keyCode === keyF) {
|
||||
if (databaseOp === true) {
|
||||
isTable = PMA_commonParams.get('table');
|
||||
isDb = PMA_commonParams.get('db');
|
||||
if (isDb && ! isTable) {
|
||||
$('.tab .ic_b_search').first().trigger('click');
|
||||
}
|
||||
} else if (tableOp === true) {
|
||||
isTable = PMA_commonParams.get('table');
|
||||
isDb = PMA_commonParams.get('db');
|
||||
if (isDb && isTable) {
|
||||
$('.tab .ic_b_search').first().trigger('click');
|
||||
}
|
||||
}
|
||||
} else if (e.keyCode === keyT) {
|
||||
tableOp = true;
|
||||
} else if (e.keyCode === keyE) {
|
||||
$('.ic_b_export').first().trigger('click');
|
||||
} else if (e.keyCode === keyBackSpace) {
|
||||
window.history.back();
|
||||
} else if (e.keyCode === keyH) {
|
||||
$('.ic_b_home').first().trigger('click');
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -49,6 +49,10 @@ $(document).ready(function () {
|
||||
}
|
||||
});
|
||||
$(document).on('keydown', function (e) {
|
||||
// disable the shortcuts when session has timed out.
|
||||
if ($('#modalOverlay').length > 0) {
|
||||
return;
|
||||
}
|
||||
if (e.ctrlKey && e.altKey && e.keyCode === keyC) {
|
||||
Console.toggle();
|
||||
}
|
||||
|
||||
@ -501,10 +501,5 @@ $html = $template->render('columns_definitions/column_definitions_form', [
|
||||
unset($form_params);
|
||||
|
||||
$response = Response::getInstance();
|
||||
$response->getHeader()->getScripts()->addFiles(
|
||||
[
|
||||
'vendor/jquery/jquery.uitablefilter.js',
|
||||
'indexes.js'
|
||||
]
|
||||
);
|
||||
$response->getHeader()->getScripts()->addFiles('indexes');
|
||||
$response->addHTML($html);
|
||||
|
||||
@ -22,7 +22,7 @@ require_once 'libraries/common.inc.php';
|
||||
$response = Response::getInstance();
|
||||
$header = $response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('tbl_structure.js');
|
||||
$scripts->addFile('tbl_structure');
|
||||
|
||||
// Check parameters
|
||||
Util::checkParameters(['db', 'table']);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user