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 current_insert_table;
61 $("td.insert_table a.ajax").live('click', function(event){
62 event.preventDefault();
63 current_insert_table = $(this);
64 var $url = $(this).attr("href");
65 if ($url.substring(0, 15) == "tbl_change.php?") {
66 $url = $url.substring(15);
69 if ($("#insert_table_dialog").length > 0) {
70 $("#insert_table_dialog").remove();
72 var $div = $('<div id="insert_table_dialog"></div>');
73 var target = "tbl_change.php";
76 * @var button_options Object that stores the options passed to jQueryUI
79 var button_options = {};
80 // in the following function we need to use $(this)
81 button_options[PMA_messages['strCancel']] = function() {$(this).dialog('close').remove();}
83 var button_options_error = {};
84 button_options_error[PMA_messages['strOK']] = function() {$(this).dialog('close').remove();}
86 var $msgbox = PMA_ajaxShowMessage();
88 $.get( target , $url+"&ajax_request=true" , function(data) {
89 //in the case of an error, show the error message returned.
90 if (data.success != undefined && data.success == false) {
94 title: PMA_messages['strInsertTable'],
98 open: PMA_verifyTypeOfAllColumns,
99 buttons : button_options_error
100 })// end dialog options
105 title: PMA_messages['strInsertTable'],
109 open: PMA_verifyTypeOfAllColumns,
110 buttons : button_options
111 });// end dialog options
112 //Remove the top menu container from the dialog
113 $dialog.find("#topmenucontainer").hide();
114 //Adding the datetime pikers for the dialog
115 $dialog.find('.datefield, .datetimefield').each(function () {
116 PMA_addDatepicker($(this));
118 $(".insertRowTable").addClass("ajax");
119 $("#buttonYes").addClass("ajax");
120 $div = $("#insert_table_dialog");
121 PMA_convertFootnotesToTooltips($div);
123 PMA_ajaxRemoveMessage($msgbox);
128 $("#insertForm .insertRowTable.ajax input[value=Go]").live('click', function(event) {
129 event.preventDefault();
131 * @var the_form object referring to the insert form
133 var $form = $("#insertForm");
134 $("#result_query").remove();
135 PMA_prepareForAjaxRequest($form);
136 //User wants to submit the form
137 $.post($form.attr('action'), $form.serialize() , function(data) {
138 if(data.success == true) {
139 PMA_ajaxShowMessage(data.message);
141 PMA_ajaxShowMessage(data.error);
143 if ($("#insert_table_dialog").length > 0) {
144 $("#insert_table_dialog").dialog("close").remove();
146 /**Update the row count at the tableForm*/
147 current_insert_table.closest('tr').find('.value.tbl_rows').html(data.row_count);
149 }) // end insert table button "Go"
151 $("#buttonYes.ajax").live('click', function(event){
152 event.preventDefault();
154 * @var the_form object referring to the insert form
156 var $form = $("#insertForm");
157 /**Get the submit type and the after insert type in the form*/
158 var selected_submit_type = $("#insertForm").find("#actions_panel .control_at_footer option:selected").attr('value');
159 var selected_after_insert = $("#insertForm").find("#actions_panel select[name=after_insert] option:selected").attr('value');
160 $("#result_query").remove();
161 PMA_prepareForAjaxRequest($form);
162 //User wants to submit the form
163 $.post($form.attr('action'), $form.serialize() , function(data) {
164 if(data.success == true) {
165 PMA_ajaxShowMessage(data.message);
166 if (selected_submit_type == "showinsert") {
167 $(data.sql_query).insertAfter("#topmenucontainer");
168 $("#result_query .notice").remove();
169 $("#result_query").prepend((data.message));
171 if (selected_after_insert == "new_insert") {
172 /**Trigger the insert dialog for new_insert option*/
173 current_insert_table.trigger('click');
177 PMA_ajaxShowMessage(data.error);
179 if ($("#insert_table_dialog").length > 0) {
180 $("#insert_table_dialog").dialog("close").remove();
182 /**Update the row count at the tableForm*/
183 current_insert_table.closest('tr').find('.value.tbl_rows').html(data.row_count);
188 * Ajax Event handler for 'Truncate Table'
190 * @uses $.PMA_confirm()
191 * @uses PMA_ajaxShowMessage()
192 * @see $cfg['AjaxEnable']
194 $(".truncate_table_anchor").live('click', function(event) {
195 event.preventDefault();
198 * @var $this_anchor Object referring to the anchor clicked
200 var $this_anchor = $(this);
202 //extract current table name and build the question string
204 * @var curr_table_name String containing the name of the table to be truncated
206 var curr_table_name = $this_anchor.parents('tr').children('th').children('a').text();
208 * @var question String containing the question to be asked for confirmation
210 var question = 'TRUNCATE ' + curr_table_name;
212 $this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function(url) {
214 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
216 $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
217 if (data.success == true) {
218 PMA_ajaxShowMessage(data.message);
219 //Fetch inner span of this anchor
220 //and replace the icon with its disabled version
221 var span = $this_anchor.html().replace(/ic_b_empty/, 'ic_bd_empty');
222 PMA_adjustTotals($this_anchor);
224 //To disable further attempts to truncate the table,
225 //replace the a element with its inner span (modified)
228 .removeClass('truncate_table_anchor');
230 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
233 }) //end $.PMA_confirm()
234 }); //end of Truncate Table Ajax action
237 * Ajax Event handler for 'Drop Table'
239 * @uses $.PMA_confirm()
240 * @uses PMA_ajaxShowMessage()
241 * @see $cfg['AjaxEnable']
243 $(".drop_table_anchor").live('click', function(event) {
244 event.preventDefault();
246 var $this_anchor = $(this);
248 //extract current table name and build the question string
250 * @var $curr_row Object containing reference to the current row
252 var $curr_row = $this_anchor.parents('tr');
254 * @var curr_table_name String containing the name of the table to be truncated
256 var curr_table_name = $curr_row.children('th').children('a').text();
258 * @var question String containing the question to be asked for confirmation
260 var question = 'DROP TABLE ' + curr_table_name;
262 $this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function(url) {
264 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
266 $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
267 if (data.success == true) {
268 PMA_ajaxShowMessage(data.message);
269 PMA_adjustTotals($this_anchor);
270 $curr_row.hide("medium").remove();
272 if (window.parent && window.parent.frame_navigation) {
273 window.parent.frame_navigation.location.reload();
276 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
279 }); // end $.PMA_confirm()
280 }); //end of Drop Table Ajax action
283 * Ajax Event handler for 'Drop tracking'
285 * @uses $.PMA_confirm()
286 * @uses PMA_ajaxShowMessage()
287 * @see $cfg['AjaxEnable']
289 $('.drop_tracking_anchor').live('click', function(event) {
290 event.preventDefault();
292 var $anchor = $(this);
295 * @var curr_tracking_row Object containing reference to the current tracked table's row
297 var curr_tracking_row = $anchor.parents('tr');
299 * @var question String containing the question to be asked for confirmation
301 var question = PMA_messages['strDeleteTrackingData'];
303 $anchor.PMA_confirm(question, $anchor.attr('href'), function(url) {
305 PMA_ajaxShowMessage(PMA_messages['strDeletingTrackingData']);
307 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
308 if(data.success == true) {
309 PMA_ajaxShowMessage(data.message);
310 $(curr_tracking_row).hide("medium").remove();
313 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
316 }) // end $.PMA_confirm()
317 }) //end Drop Tracking
319 //Calculate Real End for InnoDB
321 * Ajax Event handler for calculatig the real end for a InnoDB table
323 * @uses $.PMA_confirm
325 $('#real_end_input').live('click', function(event) {
326 event.preventDefault();
329 * @var question String containing the question to be asked for confirmation
331 var question = PMA_messages['strOperationTakesLongTime'];
333 $(this).PMA_confirm(question, '', function() {
337 }) //end Calculate Real End for InnoDB
339 }, 'top.frame_content'); // end $(document).ready()