1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * @fileoverview function used for index manipulation pages
4 * @name Table Structure
8 * @required js/functions.js
12 * Hides/shows the inputs and submits appropriately depending
13 * on whether the index type chosen is 'SPATIAL' or not.
15 function checkIndexType()
18 * @var Object Dropdown to select the index type.
20 $select_index_type = $('#select_index_type');
22 * @var Object Table header for the size column.
24 $size_header = $('#index_columns thead tr th:nth-child(2)');
26 * @var Object Inputs to specify the columns for the index.
28 $column_inputs = $('select[name="index[columns][names][]"]');
30 * @var Object Inputs to specify sizes for columns of the index.
32 $size_inputs = $('input[name="index[columns][sub_parts][]"]');
34 * @var Object Footer containg the controllers to add more columns
36 $add_more = $('#index_frm .tblFooters');
38 if ($select_index_type.val() == 'SPATIAL') {
39 // Disable and hide the size column
41 $size_inputs.each(function () {
43 .prop('disabled', true)
47 // Disable and hide the columns of the index other than the first one
49 $column_inputs.each(function () {
50 $column_input = $(this);
53 .prop('disabled', true)
60 // Hide controllers to add more columns
63 // Enable and show the size column
65 $size_inputs.each(function () {
67 .prop('disabled', false)
71 // Enable and show the columns of the index
72 $column_inputs.each(function () {
74 .prop('disabled', false)
78 // Show controllers to add more columns
84 * Unbind all event handlers before tearing down a page
86 AJAX.registerTeardown('indexes.js', function () {
87 $('#select_index_type').die('change');
88 $('a.drop_primary_key_index_anchor.ajax').die('click');
89 $("#table_index tbody tr td.edit_index.ajax, #indexes .add_index.ajax").die('click');
90 $('#index_frm input[type=submit]').die('click');
94 * @description <p>Ajax scripts for table index page</p>
96 * Actions ajaxified here:
98 * <li>Showing/hiding inputs depending on the index type chosen</li>
99 * <li>create/edit/drop indexes</li>
102 AJAX.registerOnload('indexes.js', function () {
104 checkIndexName("index_frm");
105 $('#select_index_type').live('change', function (event) {
106 event.preventDefault();
108 checkIndexName("index_frm");
112 * Ajax Event handler for 'Drop Index'
114 $('a.drop_primary_key_index_anchor.ajax').live('click', function (event) {
115 event.preventDefault();
116 var $anchor = $(this);
118 * @var $curr_row Object containing reference to the current field's row
120 var $curr_row = $anchor.parents('tr');
121 /** @var Number of columns in the key */
122 var rows = $anchor.parents('td').attr('rowspan') || 1;
123 /** @var Rows that should be hidden */
124 var $rows_to_hide = $curr_row;
125 for (var i = 1, $last_row = $curr_row.next(); i < rows; i++, $last_row = $last_row.next()) {
126 $rows_to_hide = $rows_to_hide.add($last_row);
129 var question = escapeHtml(
130 $curr_row.children('td')
131 .children('.drop_primary_key_index_msg')
135 $anchor.PMA_confirm(question, $anchor.attr('href'), function (url) {
136 var $msg = PMA_ajaxShowMessage(PMA_messages.strDroppingPrimaryKeyIndex, false);
137 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function (data) {
138 if (data.success === true) {
139 PMA_ajaxRemoveMessage($msg);
140 var $table_ref = $rows_to_hide.closest('table');
141 if ($rows_to_hide.length == $table_ref.find('tbody > tr').length) {
142 // We are about to remove all rows from the table
143 $table_ref.hide('medium', function () {
144 $('div.no_indexes_defined').show('medium');
145 $rows_to_hide.remove();
147 $table_ref.siblings('div.notice').hide('medium');
149 // We are removing some of the rows only
150 toggleRowColors($rows_to_hide.last().next());
151 $rows_to_hide.hide("medium", function () {
155 if ($('#result_query').length) {
156 $('#result_query').remove();
158 if (data.sql_query) {
159 $('<div id="result_query"></div>')
160 .html(data.sql_query)
161 .prependTo('#page_content');
162 PMA_highlightSQL($('#page_content'));
164 PMA_commonActions.refreshMain(false, function () {
165 $("a.ajax[href^=#indexes]").click();
167 PMA_reloadNavigation();
169 PMA_ajaxShowMessage(PMA_messages.strErrorProcessingRequest + " : " + data.error, false);
172 }); // end $.PMA_confirm()
173 }); //end Drop Primary Key/Index
176 *Ajax event handler for index edit
178 $("#table_index tbody tr td.edit_index.ajax, #indexes .add_index.ajax").live('click', function (event) {
179 event.preventDefault();
181 if ($(this).find("a").length === 0) {
183 var valid = checkFormElementInRange(
184 $(this).closest('form')[0],
186 'Column count has to be larger than zero.'
191 url = $(this).closest('form').serialize();
192 title = PMA_messages.strAddIndex;
195 url = $(this).find("a").attr("href");
196 if (url.substring(0, 16) == "tbl_indexes.php?") {
197 url = url.substring(16, url.length);
199 title = PMA_messages.strEditIndex;
201 url += "&ajax_request=true";
202 indexEditorDialog(url, title, function () {
203 // refresh the page using ajax
204 PMA_commonActions.refreshMain(false, function () {
205 $("a.ajax[href^=#indexes]").click();