/* 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= 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 = $(''); $name.insertAfter($('select[name="field_key[' + this.col_index + ']"]')); } var $text = $('').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 = $( '' ); // Add each column to list available for composite index. var source_length = source_array.length; var already_present = false; for (var i=0; i' + '' + '