1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * @fileoverview functions used on the table structure page
4 * @name Table Structure
8 * @required js/functions.js
12 * AJAX scripts for tbl_structure.php
14 * Actions ajaxified here:
17 * Drop Primary Key/Index
20 $(document).ready(function() {
23 * Attach Event Handler for 'Drop Column'
25 * @uses $.PMA_confirm()
26 * @uses PMA_ajaxShowMessage()
27 * (see $GLOBALS['cfg']['AjaxEnable'])
29 $(".drop_column_anchor").live('click', function(event) {
30 event.preventDefault();
33 * @var curr_table_name String containing the name of the current table
35 var curr_table_name = window.parent.table;
37 * @var curr_row Object reference to the currently selected row (i.e. field in the table)
39 var curr_row = $(this).parents('tr');
41 * @var curr_column_name String containing name of the field referred to by {@link curr_row}
43 var curr_column_name = $(curr_row).children('th').children('label').text();
45 * @var question String containing the question to be asked for confirmation
47 var question = PMA_messages['strDoYouReally'] + ' :\n ALTER TABLE `' + curr_table_name + '` DROP `' + curr_column_name + '`';
49 $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
51 PMA_ajaxShowMessage(PMA_messages['strDroppingColumn']);
53 $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
54 if(data.success == true) {
55 PMA_ajaxShowMessage(data.message);
56 $(curr_row).hide("medium").remove();
59 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
62 }); // end $.PMA_confirm()
63 }) ; //end of Drop Column Anchor action
66 * Ajax Event handler for 'Add Primary Key'
68 * @uses $.PMA_confirm()
69 * @uses PMA_ajaxShowMessage()
70 * (see $GLOBALS['cfg']['AjaxEnable'])
72 $(".action_primary a").live('click', function(event) {
73 event.preventDefault();
76 * @var curr_table_name String containing the name of the current table
78 var curr_table_name = window.parent.table;
80 * @var curr_column_name String containing name of the field referred to by {@link curr_row}
82 var curr_column_name = $(this).parents('tr').children('th').children('label').text();
84 * @var question String containing the question to be asked for confirmation
86 var question = PMA_messages['strDoYouReally'] + ' :\n ALTER TABLE `' + curr_table_name + '` ADD PRIMARY KEY(`' + curr_column_name + '`)';
88 $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
90 PMA_ajaxShowMessage(PMA_messages['strAddingPrimaryKey']);
92 $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
93 if(data.success == true) {
94 PMA_ajaxShowMessage(data.message);
96 if (typeof data.reload != 'undefined') {
97 window.parent.frame_content.location.reload();
101 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
104 }) // end $.PMA_confirm()
105 })//end Add Primary Key
108 * Ajax Event handler for 'Drop Primary Key/Index'
110 * @uses $.PMA_confirm()
111 * @uses PMA_ajaxShowMessage()
112 * (see $GLOBALS['cfg']['AjaxEnable'])
114 $('.drop_primary_key_index_anchor').live('click', function(event) {
115 event.preventDefault();
120 * @var $curr_row Object containing reference to the current field's row
122 var $curr_row = $anchor.parents('tr');
123 /** @var Number of columns in the key */
124 var rows = $anchor.parents('td').attr('rowspan') || 1;
125 /** @var Rows that should be hidden */
126 var $rows_to_hide = $curr_row;
127 for (var i = 1, $last_row = $curr_row.next(); i < rows; i++, $last_row = $last_row.next()) {
128 $rows_to_hide = $rows_to_hide.add($last_row);
131 var question = $curr_row.children('td').children('.drop_primary_key_index_msg').val();
133 $anchor.PMA_confirm(question, $anchor.attr('href'), function(url) {
135 PMA_ajaxShowMessage(PMA_messages['strDroppingPrimaryKeyIndex']);
137 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
138 if(data.success == true) {
139 PMA_ajaxShowMessage(data.message);
140 $rows_to_hide.hide("medium").remove();
143 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
146 }) // end $.PMA_confirm()
147 }) //end Drop Primary Key/Index
150 *Ajax event handler for muti column change
152 $("#fieldsForm.ajax .mult_submit[value=change]").live('click', function(event){
153 event.preventDefault();
155 /*Check whether atleast one row is selected for change*/
156 if($("#tablestructure tbody tr").hasClass("marked")){
157 var div = $('<div id="change_column_dialog"></div>');
160 * @var button_options Object that stores the options passed to jQueryUI
163 var button_options = {};
164 // in the following function we need to use $(this)
165 button_options[PMA_messages['strCancel']] = function() {$(this).parent().dialog('close').remove();}
167 var button_options_error = {};
168 button_options_error[PMA_messages['strOK']] = function() {$(this).parent().dialog('close').remove();}
169 var $form = $("#fieldsForm");
170 var $msgbox = PMA_ajaxShowMessage();
172 $.get( $form.attr('action') , $form.serialize()+"&ajax_request=true&submit_mult=change" , function(data) {
173 //in the case of an error, show the error message returned.
174 if (data.success != undefined && data.success == false) {
178 title: PMA_messages['strChangeTbl'],
181 open: PMA_verifyTypeOfAllColumns,
182 buttons : button_options_error
183 })// end dialog options
188 title: PMA_messages['strChangeTbl'],
191 open: PMA_verifyTypeOfAllColumns,
192 buttons : button_options
194 //Remove the top menu container from the dialog
195 .find("#topmenucontainer").hide()
196 ; // end dialog options
197 $("#append_fields_form input[name=do_save_data]").addClass("ajax");
199 PMA_ajaxRemoveMessage($msgbox);
202 PMA_ajaxShowMessage(PMA_messages['strNoRowSelected']);
207 *Ajax action for submitting the column change form
209 $("#append_fields_form input[name=do_save_data].ajax").live('click', function(event) {
210 event.preventDefault();
212 * @var the_form object referring to the export form
214 var $form = $("#append_fields_form");
216 PMA_prepareForAjaxRequest($form);
217 //User wants to submit the form
218 $.post($form.attr('action'), $form.serialize()+"&do_save_data=Save", function(data) {
219 if ($("#sqlqueryresults").length != 0) {
220 $("#sqlqueryresults").remove();
221 } else if ($(".error").length != 0) {
222 $(".error").remove();
224 if (data.success == true) {
225 PMA_ajaxShowMessage(data.message);
226 $("<div id='sqlqueryresults'></div>").insertAfter("#topmenucontainer");
227 $("#sqlqueryresults").html(data.sql_query);
228 $("#result_query .notice").remove();
229 $("#result_query").prepend((data.message));
230 if ($("#change_column_dialog").length > 0) {
231 $("#change_column_dialog").dialog("close").remove();
233 /*Reload the field form*/
234 $.post($("#fieldsForm").attr('action'), $("#fieldsForm").serialize()+"&ajax_request=true", function(form_data) {
235 $("#fieldsForm").remove();
236 var $temp_div = $("<div id='temp_div'><div>").append(form_data);
237 if ($("#sqlqueryresults").length != 0) {
238 $temp_div.find("#fieldsForm").insertAfter("#sqlqueryresults");
240 $temp_div.find("#fieldsForm").insertAfter(".error");
242 /*Call the function to display the more options in table*/
243 displayMoreTableOpts();
246 var $temp_div = $("<div id='temp_div'><div>").append(data);
247 var $error = $temp_div.find(".error code").addClass("error");
248 PMA_ajaxShowMessage($error);
251 }) // end insert table button "do_save_data"
254 *Ajax event handler for index edit
256 $("#table_index tbody tr td.edit_index.ajax").live('click', function(event){
257 event.preventDefault();
258 var url = $(this).find("a").attr("href");
259 if (url.substring(0, 16) == "tbl_indexes.php?") {
260 url = url.substring(16, url.length );
262 url = url + "&ajax_request=true";
264 var div = $('<div id="edit_index_dialog"></div>');
267 * @var button_options Object that stores the options passed to jQueryUI
270 var button_options = {};
271 // in the following function we need to use $(this)
272 button_options[PMA_messages['strCancel']] = function() {$(this).parent().dialog('close').remove();}
274 var button_options_error = {};
275 button_options_error[PMA_messages['strOK']] = function() {$(this).parent().dialog('close').remove();}
276 var $msgbox = PMA_ajaxShowMessage();
278 $.get( "tbl_indexes.php" , url , function(data) {
279 //in the case of an error, show the error message returned.
280 if (data.success != undefined && data.success == false) {
284 title: PMA_messages['strEdit'],
287 open: PMA_verifyTypeOfAllColumns,
288 buttons : button_options_error
289 })// end dialog options
294 title: PMA_messages['strEdit'],
297 open: PMA_verifyTypeOfAllColumns,
298 buttons : button_options
300 //Remove the top menu container from the dialog
301 .find("#topmenucontainer").hide()
302 ; // end dialog options
304 PMA_ajaxRemoveMessage($msgbox);
309 *Ajax action for submiting the index form
311 $("#index_frm.ajax input[name=do_save_data]").live('click', function(event) {
312 event.preventDefault();
314 * @var the_form object referring to the export form
316 var $form = $("#index_frm");
318 PMA_prepareForAjaxRequest($form);
319 //User wants to submit the form
320 $.post($form.attr('action'), $form.serialize()+"&do_save_data=Save", function(data) {
321 if ($("#sqlqueryresults").length != 0) {
322 $("#sqlqueryresults").remove();
324 if (data.success == true) {
325 PMA_ajaxShowMessage(data.message);
326 $("<div id='sqlqueryresults'></div>").insertAfter("#topmenucontainer");
327 $("#sqlqueryresults").html(data.sql_query);
328 $("#result_query .notice").remove();
329 $("#result_query").prepend((data.message));
331 /*Reload the field form*/
332 $("#table_index").remove();
333 var temp_div = $("<div id='temp_div'><div>").append(data.index_table);
334 $(temp_div).find("#table_index").insertAfter("#index_header");
335 if ($("#edit_index_dialog").length > 0) {
336 $("#edit_index_dialog").dialog("close").remove();
340 var temp_div = $("<div id='temp_div'><div>").append(data.error);
341 var error = $(temp_div).find(".error code").addClass("error");
342 PMA_ajaxShowMessage(error);
346 }) // end insert table button "do_save_data"
349 *Ajax action for submiting the index form for add more columns
351 $("#index_frm.ajax input[name=add_fields]").live('click', function(event) {
352 event.preventDefault();
354 * @var the_form object referring to the export form
356 var $form = $("#index_frm");
358 PMA_prepareForAjaxRequest($form);
359 //User wants to submit the form
360 $.post($form.attr('action'), $form.serialize()+"&add_fields=Go", function(data) {
361 $("#index_columns").remove();
362 var temp_div = $("<div id='temp_div'><div>").append(data);
363 $(temp_div).find("#index_columns").insertAfter("#index_frm fieldset .error");
365 }) // end insert table button "Go"
367 /**Add the show/hide index table option if the index is available*/
368 if ($("#index_div.ajax").find("#table_index").length != 0) {
370 *Prepare a div containing a link for toggle the index table
372 $('<div id="toggletableindexdiv"><a id="toggletableindexlink"></a></div>')
373 .insertAfter('#index_div')
374 /** don't show it until we have index table on-screen */
377 /** Changing the displayed text according to the hide/show criteria in table index*/
379 $('#toggletableindexlink')
380 .html(PMA_messages['strHideIndexes'])
381 .bind('click', function() {
383 $('#index_div').slideToggle();
384 if ($link.text() == PMA_messages['strHideIndexes']) {
385 $link.text(PMA_messages['strShowIndexes']);
387 $link.text(PMA_messages['strHideIndexes']);
389 /** avoid default click action */
392 } //end show/hide table index
395 }) // end $(document).ready()