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()
60 * @see $cfg['AjaxEnable']
62 $(".truncate_table_anchor").live('click', function(event
) {
63 event
.preventDefault();
66 * @var $this_anchor Object referring to the anchor clicked
68 var $this_anchor
= $(this);
70 //extract current table name and build the question string
72 * @var curr_table_name String containing the name of the table to be truncated
74 var curr_table_name
= $this_anchor
.parents('tr').children('th').children('a').text();
76 * @var question String containing the question to be asked for confirmation
78 var question
= 'TRUNCATE ' + curr_table_name
;
80 $this_anchor
.PMA_confirm(question
, $this_anchor
.attr('href'), function(url
) {
82 PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
84 $.get(url
, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data
) {
85 if (data
.success
== true) {
86 PMA_ajaxShowMessage(data
.message
);
87 //Fetch inner span of this anchor
88 //and replace the icon with its disabled version
89 var span
= $this_anchor
.html().replace(/b_empty.png/, 'bd_empty.png');
90 PMA_adjustTotals($this_anchor
);
92 //To disable further attempts to truncate the table,
93 //replace the a element with its inner span (modified)
96 .removeClass('truncate_table_anchor');
98 PMA_ajaxShowMessage(PMA_messages
['strErrorProcessingRequest'] + " : " + data
.error
);
101 }) //end $.PMA_confirm()
102 }); //end of Truncate Table Ajax action
105 * Ajax Event handler for 'Drop Table'
107 * @uses $.PMA_confirm()
108 * @uses PMA_ajaxShowMessage()
109 * @see $cfg['AjaxEnable']
111 $(".drop_table_anchor").live('click', function(event
) {
112 event
.preventDefault();
114 var $this_anchor
= $(this);
116 //extract current table name and build the question string
118 * @var $curr_row Object containing reference to the current row
120 var $curr_row
= $this_anchor
.parents('tr');
122 * @var curr_table_name String containing the name of the table to be truncated
124 var curr_table_name
= $curr_row
.children('th').children('a').text();
126 * @var question String containing the question to be asked for confirmation
128 var question
= 'DROP TABLE ' + curr_table_name
;
130 $this_anchor
.PMA_confirm(question
, $this_anchor
.attr('href'), function(url
) {
132 PMA_ajaxShowMessage(PMA_messages
['strProcessingRequest']);
134 $.get(url
, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data
) {
135 if (data
.success
== true) {
136 PMA_ajaxShowMessage(data
.message
);
137 PMA_adjustTotals($this_anchor
);
138 $curr_row
.hide("medium").remove();
140 if (window
.parent
&& window
.parent
.frame_navigation
) {
141 window
.parent
.frame_navigation
.location
.reload();
144 PMA_ajaxShowMessage(PMA_messages
['strErrorProcessingRequest'] + " : " + data
.error
);
147 }); // end $.PMA_confirm()
148 }); //end of Drop Table Ajax action
151 * Ajax Event handler for 'Drop Event'
153 * @uses $.PMA_confirm()
154 * @uses PMA_ajaxShowMessage()
155 * @see $cfg['AjaxEnable']
157 $('.drop_event_anchor').live('click', function(event
) {
158 event
.preventDefault();
161 * @var curr_event_row Object reference to current event's row
163 var curr_event_row
= $(this).parents('tr');
165 * @var curr_event_name String containing the name of {@link curr_event_row}
167 var curr_event_name
= $(curr_event_row
).children('td:first').text();
169 * @var question String containing the question to be asked for confirmation
171 var question
= 'DROP EVENT ' + curr_event_name
;
173 $(this).PMA_confirm(question
, $(this).attr('href') , function(url
) {
175 PMA_ajaxShowMessage(PMA_messages
['strDroppingEvent']);
177 $.get(url
, {'is_js_confirmed': 1, 'ajax_request': true}, function(data
) {
178 if(data
.success
== true) {
179 PMA_ajaxShowMessage(data
.message
);
180 $(curr_event_row
).hide("medium").remove();
183 PMA_ajaxShowMessage(PMA_messages
['strErrorProcessingRequest'] + " : " + data
.error
);
186 }) // end $.PMA_confirm()
190 * Ajax Event handler for 'Drop Procedure'
192 * @uses $.PMA_confirm()
193 * @uses PMA_ajaxShowMessage()
194 * @see $cfg['AjaxEnable']
196 $('.drop_procedure_anchor').live('click', function(event
) {
197 event
.preventDefault();
200 * @var curr_proc_row Object containing reference to the current procedure's row
202 var curr_proc_row
= $(this).parents('tr');
204 * @var question String containing the question to be asked for confirmation
206 var question
= $(curr_proc_row
).children('td').children('.drop_procedure_sql').val();
208 $(this).PMA_confirm(question
, $(this).attr('href'), function(url
) {
210 PMA_ajaxShowMessage(PMA_messages
['strDroppingProcedure']);
212 $.get(url
, {'is_js_confirmed': 1, 'ajax_request': true}, function(data
) {
213 if(data
.success
== true) {
214 PMA_ajaxShowMessage(data
.message
);
215 $(curr_event_row
).hide("medium").remove();
218 PMA_ajaxShowMessage(PMA_messages
['strErrorProcessingRequest'] + " : " + data
.error
);
221 }) // end $.PMA_confirm()
222 }) //end Drop Procedure
225 * Ajax Event handler for 'Drop tracking'
227 * @uses $.PMA_confirm()
228 * @uses PMA_ajaxShowMessage()
229 * @see $cfg['AjaxEnable']
231 $('.drop_tracking_anchor').live('click', function(event
) {
232 event
.preventDefault();
234 var $anchor
= $(this);
237 * @var curr_tracking_row Object containing reference to the current tracked table's row
239 var curr_tracking_row
= $anchor
.parents('tr');
241 * @var question String containing the question to be asked for confirmation
243 var question
= PMA_messages
['strDeleteTrackingData'];
245 $anchor
.PMA_confirm(question
, $anchor
.attr('href'), function(url
) {
247 PMA_ajaxShowMessage(PMA_messages
['strDeletingTrackingData']);
249 $.get(url
, {'is_js_confirmed': 1, 'ajax_request': true}, function(data
) {
250 if(data
.success
== true) {
251 PMA_ajaxShowMessage(data
.message
);
252 $(curr_tracking_row
).hide("medium").remove();
255 PMA_ajaxShowMessage(PMA_messages
['strErrorProcessingRequest'] + " : " + data
.error
);
258 }) // end $.PMA_confirm()
259 }) //end Drop Tracking
261 //Calculate Real End for InnoDB
263 * Ajax Event handler for calculatig the real end for a InnoDB table
265 * @uses $.PMA_confirm
267 $('#real_end_input').live('click', function(event
) {
268 event
.preventDefault();
271 * @var question String containing the question to be asked for confirmation
273 var question
= PMA_messages
['strOperationTakesLongTime'];
275 $(this).PMA_confirm(question
, '', function() {
279 }) //end Calculate Real End for InnoDB
281 }, 'top.frame_content'); // end $(document).ready()