diff options
author | Madhura Jayaratne <madhura.cj@gmail.com> | 2015-03-20 10:23:02 +0300 |
---|---|---|
committer | Madhura Jayaratne <madhura.cj@gmail.com> | 2015-03-20 11:09:27 +0300 |
commit | 06a5e07808fb41918f242aa977b9f3b57fef9f47 (patch) | |
tree | 8420255967d660afd5e1d0d9ef3c676af60a2078 /js/indexes.js | |
parent | 14d5a7b7d82bd7b8a8061384a68a00343725c113 (diff) |
rfe #1626 Display/edit index name
Signed-off-by: Madhura Jayaratne <madhura.cj@gmail.com>
Diffstat (limited to 'js/indexes.js')
-rw-r--r-- | js/indexes.js | 90 |
1 files changed, 77 insertions, 13 deletions
diff --git a/js/indexes.js b/js/indexes.js index 1e997a5edc..a74238b0f0 100644 --- a/js/indexes.js +++ b/js/indexes.js @@ -171,8 +171,10 @@ function PMA_removeColumnFromIndex(col_index) */ function PMA_addColumnToIndex(source_array, array_index, index_choice, col_index) { - // Remove column from other indexes (if any). - PMA_removeColumnFromIndex(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 columns = []; @@ -194,9 +196,31 @@ function PMA_addColumnToIndex(source_array, array_index, index_choice, col_index 'columns': columns }; - // Update index details on form. - $('select[name="field_key[' + col_index + ']"]') - .attr('data-index', index_choice + ',' + array_index); + // 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()); } @@ -315,14 +339,16 @@ function PMA_showAddIndexDialog(source_array, array_index, target_columns, col_i $(this).dialog('close'); }; 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'); + 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'); }; @@ -477,6 +503,7 @@ AJAX.registerTeardown('indexes.js', function () { $(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'); }); /** @@ -684,4 +711,41 @@ AJAX.registerOnload('indexes.js', function () { } } }); + + $(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]; + + 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; + default: + return; + } + + 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]); + }) }); |