1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * @fileoverview functions used on the database structure page
4 * @name Database Structure
8 * @required js/functions.js
12 * AJAX scripts for db_structure.php
14 * Actions ajaxified here:
22 * Adjust number of rows and total size in the summary
23 * when emptying or dropping a table
25 * @param jQuery object $this_anchor
27 function PMA_adjustTotals($this_anchor) {
28 var $parent_tr = $this_anchor.closest('tr');
29 var $rows_td = $parent_tr.find('.tbl_rows');
30 var $size_td = $parent_tr.find('.tbl_size');
31 var num_rows = parseInt($rows_td.text());
32 // set number of rows to 0
33 // (not really needed in case we are dropping the table)
35 // set size to unknown (not sure how to get the exact
36 // value here, as an empty InnoDB table would have a size)
39 // try to compute a new total row number
40 if (! isNaN(num_rows)) {
41 $total_rows_td = $('#tbl_summary_row').find('.tbl_rows');
42 var total_rows = parseInt($total_rows_td.text());
43 if (! isNaN(total_rows)) {
44 $total_rows_td.text(total_rows - num_rows);
48 // prefix total size with "~"
49 var $total_size_td = $('#tbl_summary_row').find('.tbl_size');
50 $total_size_td.text($total_size_td.text().replace(/^/,'~'));
53 $(document).ready(function() {
55 * Ajax Event handler for 'Insert Table'
57 * @uses PMA_ajaxShowMessage()
58 * @see $cfg['AjaxEnable']
60 var currrent_insert_table;
61 $("td.insert_table a.ajax").live('click', function(event){
62 event.preventDefault();
63 currrent_insert_table = $(this);
64 var url = $(this).attr("href");
65 if (url.substring(0, 15) == "tbl_change.php?") {
66 url = url.substring(15);
69 var div = $('<div id="insert_table_dialog"></div>');
70 var target = "tbl_change.php";
73 * @var button_options Object that stores the options passed to jQueryUI
76 var button_options = {};
77 // in the following function we need to use $(this)
78 button_options[PMA_messages['strCancel']] = function() {$(this).parent().dialog('close').remove();}
80 var button_options_error = {};
81 button_options_error[PMA_messages['strOK']] = function() {$(this).parent().dialog('close').remove();}
83 var $msgbox = PMA_ajaxShowMessage();
85 $.get( target , url+"&ajax_request=true" , function(data) {
86 //in the case of an error, show the error message returned.
87 if (data.success != undefined && data.success == false) {
91 title: PMA_messages['strInsertTable'],
94 open: PMA_verifyTypeOfAllColumns,
95 buttons : button_options_error
96 })// end dialog options
101 title: PMA_messages['strInsertTable'],
104 open: PMA_verifyTypeOfAllColumns,
105 buttons : button_options
107 //Remove the top menu container from the dialog
108 .find("#topmenucontainer").hide()
109 ; // end dialog options
110 $(".insertRowTable").addClass("ajax");
111 $("#buttonYes").addClass("ajax");
113 PMA_ajaxRemoveMessage($msgbox);
118 $("#insertForm .insertRowTable.ajax input[value=Go]").live('click', function(event) {
119 event.preventDefault();
121 * @var the_form object referring to the insert form
123 var $form = $("#insertForm");
124 $("#result_query").remove();
125 PMA_prepareForAjaxRequest($form);
126 //User wants to submit the form
127 $.post($form.attr('action'), $form.serialize() , function(data) {
128 if(data.success == true) {
129 PMA_ajaxShowMessage(data.message);
131 PMA_ajaxShowMessage(data.error);
133 if ($("#insert_table_dialog").length > 0) {
134 $("#insert_table_dialog").dialog("close").remove();
136 /**Update the row count at the tableForm*/
137 currrent_insert_table.closest('tr').find('.value.tbl_rows').html(data.row_count);
139 }) // end insert table button "Go"
141 $("#buttonYes.ajax").live('click', function(event){
142 event.preventDefault();
144 * @var the_form object referring to the insert form
146 var $form = $("#insertForm");
147 /**Get the submit type and the after insert type in the form*/
148 var selected_submit_type = $("#insertForm").find("#actions_panel .control_at_footer option:selected").attr('value');
149 var selected_after_insert = $("#insertForm").find("#actions_panel select[name=after_insert] option:selected").attr('value');
150 $("#result_query").remove();
151 PMA_prepareForAjaxRequest($form);
152 //User wants to submit the form
153 $.post($form.attr('action'), $form.serialize() , function(data) {
154 if(data.success == true) {
155 PMA_ajaxShowMessage(data.message);
156 if (selected_submit_type == "showinsert") {
157 $(data.sql_query).insertAfter("#topmenucontainer");
158 $("#result_query .notice").remove();
159 $("#result_query").prepend((data.message));
161 if (selected_after_insert == "new_insert") {
162 /**Trigger the insert dialog for new_insert option*/
163 currrent_insert_table.trigger('click');
167 PMA_ajaxShowMessage(data.error);
169 if ($("#insert_table_dialog").length > 0) {
170 $("#insert_table_dialog").dialog("close").remove();
172 /**Update the row count at the tableForm*/
173 currrent_insert_table.closest('tr').find('.value.tbl_rows').html(data.row_count);
178 * Ajax Event handler for 'Truncate Table'
180 * @uses $.PMA_confirm()
181 * @uses PMA_ajaxShowMessage()
182 * @see $cfg['AjaxEnable']
184 $(".truncate_table_anchor").live('click', function(event) {
185 event.preventDefault();
188 * @var $this_anchor Object referring to the anchor clicked
190 var $this_anchor = $(this);
192 //extract current table name and build the question string
194 * @var curr_table_name String containing the name of the table to be truncated
196 var curr_table_name = $this_anchor.parents('tr').children('th').children('a').text();
198 * @var question String containing the question to be asked for confirmation
200 var question = 'TRUNCATE ' + curr_table_name;
202 $this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function(url) {
204 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
206 $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
207 if (data.success == true) {
208 PMA_ajaxShowMessage(data.message);
209 //Fetch inner span of this anchor
210 //and replace the icon with its disabled version
211 var span = $this_anchor.html().replace(/b_empty.png/, 'bd_empty.png');
212 PMA_adjustTotals($this_anchor);
214 //To disable further attempts to truncate the table,
215 //replace the a element with its inner span (modified)
218 .removeClass('truncate_table_anchor');
220 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
223 }) //end $.PMA_confirm()
224 }); //end of Truncate Table Ajax action
227 * Ajax Event handler for 'Drop Table'
229 * @uses $.PMA_confirm()
230 * @uses PMA_ajaxShowMessage()
231 * @see $cfg['AjaxEnable']
233 $(".drop_table_anchor").live('click', function(event) {
234 event.preventDefault();
236 var $this_anchor = $(this);
238 //extract current table name and build the question string
240 * @var $curr_row Object containing reference to the current row
242 var $curr_row = $this_anchor.parents('tr');
244 * @var curr_table_name String containing the name of the table to be truncated
246 var curr_table_name = $curr_row.children('th').children('a').text();
248 * @var question String containing the question to be asked for confirmation
250 var question = 'DROP TABLE ' + curr_table_name;
252 $this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function(url) {
254 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
256 $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
257 if (data.success == true) {
258 PMA_ajaxShowMessage(data.message);
259 PMA_adjustTotals($this_anchor);
260 $curr_row.hide("medium").remove();
262 if (window.parent && window.parent.frame_navigation) {
263 window.parent.frame_navigation.location.reload();
266 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
269 }); // end $.PMA_confirm()
270 }); //end of Drop Table Ajax action
273 * Ajax Event handler for 'Drop tracking'
275 * @uses $.PMA_confirm()
276 * @uses PMA_ajaxShowMessage()
277 * @see $cfg['AjaxEnable']
279 $('.drop_tracking_anchor').live('click', function(event) {
280 event.preventDefault();
282 var $anchor = $(this);
285 * @var curr_tracking_row Object containing reference to the current tracked table's row
287 var curr_tracking_row = $anchor.parents('tr');
289 * @var question String containing the question to be asked for confirmation
291 var question = PMA_messages['strDeleteTrackingData'];
293 $anchor.PMA_confirm(question, $anchor.attr('href'), function(url) {
295 PMA_ajaxShowMessage(PMA_messages['strDeletingTrackingData']);
297 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
298 if(data.success == true) {
299 PMA_ajaxShowMessage(data.message);
300 $(curr_tracking_row).hide("medium").remove();
303 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
306 }) // end $.PMA_confirm()
307 }) //end Drop Tracking
309 //Calculate Real End for InnoDB
311 * Ajax Event handler for calculatig the real end for a InnoDB table
313 * @uses $.PMA_confirm
315 $('#real_end_input').live('click', function(event) {
316 event.preventDefault();
319 * @var question String containing the question to be asked for confirmation
321 var question = PMA_messages['strOperationTakesLongTime'];
323 $(this).PMA_confirm(question, '', function() {
327 }) //end Calculate Real End for InnoDB
329 }, 'top.frame_content'); // end $(document).ready()