', 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
.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 = $('' +
'');
var $composite_index_radio = $('' +
'');
var $dialog_content = $('');
$dialog_content.append('');
// 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(
'
' +
PMA_messages.strFormEmpty +
'
',
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').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, #indexes .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
Ajax scripts for table index page
*
* Actions ajaxified here:
*
*
Showing/hiding inputs depending on the index type chosen
*
create/edit/drop indexes
*
*/
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 submitData = $form.serialize() + '&do_save_data=1&ajax_request=true&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);
$.post(url, {'is_js_confirmed': 1, 'ajax_request': true}, 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
toggleRowColors($rows_to_hide.last().next());
$rows_to_hide.hide("medium", function () {
$(this).remove();
});
}
if ($('.result_query').length) {
$('.result_query').remove();
}
if (data.sql_query) {
$('')
.html(data.sql_query)
.prependTo('#structure_content');
PMA_highlightSQL($('#page_content'));
}
PMA_commonActions.refreshMain(false, function () {
$("a.ajax[href^=#indexes]").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, #indexes .add_index.ajax", function (event) {
event.preventDefault();
var url, 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 += "&ajax_request=true";
indexEditorDialog(url, title, function () {
// refresh the page using ajax
PMA_commonActions.refreshMain(false, function () {
$("a.ajax[href^=#indexes]").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