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() {
56 * Ajax Event handler for 'Truncate Table'
58 * @uses $.PMA_confirm()
59 * @uses PMA_ajaxShowMessage()
61 $(".truncate_table_anchor").live('click', function(event) {
62 event.preventDefault();
65 * @var $this_anchor Object referring to the anchor clicked
67 var $this_anchor = $(this);
69 //extract current table name and build the question string
71 * @var curr_table_name String containing the name of the table to be truncated
73 var curr_table_name = $this_anchor.parents('tr').children('th').children('a').text();
75 * @var question String containing the question to be asked for confirmation
77 var question = 'TRUNCATE ' + curr_table_name;
79 $this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function(url) {
81 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
83 $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
84 if (data.success == true) {
85 PMA_ajaxShowMessage(data.message);
86 //Fetch inner span of this anchor
87 //and replace the icon with its disabled version
88 var span = $this_anchor.html().replace(/b_empty.png/, 'bd_empty.png');
89 PMA_adjustTotals($this_anchor);
91 //To disable further attempts to truncate the table,
92 //replace the a element with its inner span (modified)
95 .removeClass('truncate_table_anchor');
97 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
100 }) //end $.PMA_confirm()
101 }); //end of Truncate Table Ajax action
104 * Ajax Event handler for 'Drop Table'
106 * @uses $.PMA_confirm()
107 * @uses PMA_ajaxShowMessage()
109 $(".drop_table_anchor").live('click', function(event) {
110 event.preventDefault();
112 var $this_anchor = $(this);
114 //extract current table name and build the question string
116 * @var $curr_row Object containing reference to the current row
118 var $curr_row = $this_anchor.parents('tr');
120 * @var curr_table_name String containing the name of the table to be truncated
122 var curr_table_name = $curr_row.children('th').children('a').text();
124 * @var question String containing the question to be asked for confirmation
126 var question = 'DROP TABLE ' + curr_table_name;
128 $this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function(url) {
130 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
132 $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
133 if (data.success == true) {
134 PMA_ajaxShowMessage(data.message);
135 PMA_adjustTotals($this_anchor);
136 $curr_row.hide("medium").remove();
138 if (window.parent && window.parent.frame_navigation) {
139 window.parent.frame_navigation.location.reload();
142 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
145 }); // end $.PMA_confirm()
146 }); //end of Drop Table Ajax action
149 * Ajax Event handler for 'Drop Event'
151 * @uses $.PMA_confirm()
152 * @uses PMA_ajaxShowMessage()
154 $('.drop_event_anchor').live('click', function(event) {
155 event.preventDefault();
158 * @var curr_event_row Object reference to current event's row
160 var curr_event_row = $(this).parents('tr');
162 * @var curr_event_name String containing the name of {@link curr_event_row}
164 var curr_event_name = $(curr_event_row).children('td:first').text();
166 * @var question String containing the question to be asked for confirmation
168 var question = 'DROP EVENT ' + curr_event_name;
170 $(this).PMA_confirm(question, $(this).attr('href') , function(url) {
172 PMA_ajaxShowMessage(PMA_messages['strDroppingEvent']);
174 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
175 if(data.success == true) {
176 PMA_ajaxShowMessage(data.message);
177 $(curr_event_row).hide("medium").remove();
180 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
183 }) // end $.PMA_confirm()
187 * Ajax Event handler for 'Drop Procedure'
189 * @uses $.PMA_confirm()
190 * @uses PMA_ajaxShowMessage()
192 $('.drop_procedure_anchor').live('click', function(event) {
193 event.preventDefault();
196 * @var curr_proc_row Object containing reference to the current procedure's row
198 var curr_proc_row = $(this).parents('tr');
200 * @var question String containing the question to be asked for confirmation
202 var question = $(curr_proc_row).children('.drop_procedure_sql').val();
204 $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
206 PMA_ajaxShowMessage(PMA_messages['strDroppingProcedure']);
208 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
209 if(data.success == true) {
210 PMA_ajaxShowMessage(data.message);
211 $(curr_event_row).hide("medium").remove();
214 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
217 }) // end $.PMA_confirm()
218 }) //end Drop Procedure
220 $('.drop_tracking_anchor').live('click', function(event) {
221 event.preventDefault();
224 * @var curr_tracking_row Object containing reference to the current tracked table's row
226 var curr_tracking_row = $(this).parents('tr');
228 * @var question String containing the question to be asked for confirmation
230 var question = PMA_messages['strDeleteTrackingData'];
232 $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
234 PMA_ajaxShowMessage(PMA_messages['strDeletingTrackingData']);
236 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
237 if(data.success == true) {
238 PMA_ajaxShowMessage(data.message);
239 $(curr_tracking_row).hide("medium").remove();
242 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
245 }) // end $.PMA_confirm()
246 }) //end Drop Tracking
248 //Calculate Real End for InnoDB
250 * Ajax Event handler for calculatig the real end for a InnoDB table
252 * @uses $.PMA_confirm
254 $('#real_end_input').live('click', function(event) {
255 event.preventDefault();
258 * @var question String containing the question to be asked for confirmation
260 var question = PMA_messages['strOperationTakesLongTime'];
262 $(this).PMA_confirm(question, '', function() {
266 }) //end Calculate Real End for InnoDB
268 }, 'top.frame_content'); // end $(document).ready()