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)
29 var $parent_tr = $this_anchor.closest('tr');
30 var $rows_td = $parent_tr.find('.tbl_rows');
31 var $size_td = $parent_tr.find('.tbl_size');
32 var num_rows = parseInt($rows_td.text());
33 // set number of rows to 0
34 // (not really needed in case we are dropping the table)
36 // set size to unknown (not sure how to get the exact
37 // value here, as an empty InnoDB table would have a size)
40 // try to compute a new total row number
41 if (! isNaN(num_rows)) {
42 $total_rows_td = $('#tbl_summary_row').find('.tbl_rows');
43 var total_rows = parseInt($total_rows_td.text());
44 if (! isNaN(total_rows)) {
45 $total_rows_td.text(total_rows - num_rows);
49 // prefix total size with "~"
50 var $total_size_td = $('#tbl_summary_row').find('.tbl_size');
51 $total_size_td.text($total_size_td.text().replace(/^/,'~'));
54 $(document).ready(function() {
56 * Ajax Event handler for 'Insert Table'
58 * @uses PMA_ajaxShowMessage()
59 * @see $cfg['AjaxEnable']
61 var current_insert_table;
62 $("td.insert_table a.ajax").live('click', function(event){
63 event.preventDefault();
64 current_insert_table = $(this);
65 var $url = $(this).attr("href");
66 if ($url.substring(0, 15) == "tbl_change.php?") {
67 $url = $url.substring(15);
70 if ($("#insert_table_dialog").length > 0) {
71 $("#insert_table_dialog").remove();
73 var $div = $('<div id="insert_table_dialog"></div>');
74 var target = "tbl_change.php";
77 * @var button_options Object that stores the options passed to jQueryUI
80 var button_options = {};
81 // in the following function we need to use $(this)
82 button_options[PMA_messages['strCancel']] = function() {$(this).dialog('close').remove();}
84 var button_options_error = {};
85 button_options_error[PMA_messages['strOK']] = function() {$(this).dialog('close').remove();}
87 var $msgbox = PMA_ajaxShowMessage();
89 $.get( target , $url+"&ajax_request=true" , function(data) {
90 //in the case of an error, show the error message returned.
91 if (data.success != undefined && data.success == false) {
95 title: PMA_messages['strInsertTable'],
99 open: PMA_verifyTypeOfAllColumns,
100 buttons : button_options_error
101 })// end dialog options
106 title: PMA_messages['strInsertTable'],
110 open: PMA_verifyTypeOfAllColumns,
111 buttons : button_options
112 });// end dialog options
113 //Remove the top menu container from the dialog
114 $dialog.find("#topmenucontainer").hide();
115 //Adding the datetime pikers for the dialog
116 $dialog.find('.datefield, .datetimefield').each(function () {
117 PMA_addDatepicker($(this));
119 $(".insertRowTable").addClass("ajax");
120 $("#buttonYes").addClass("ajax");
121 $div = $("#insert_table_dialog");
122 PMA_convertFootnotesToTooltips($div);
124 PMA_ajaxRemoveMessage($msgbox);
129 $("#insertForm .insertRowTable.ajax input[value=Go]").live('click', function(event) {
130 event.preventDefault();
132 * @var the_form object referring to the insert form
134 var $form = $("#insertForm");
135 $("#result_query").remove();
136 PMA_prepareForAjaxRequest($form);
137 //User wants to submit the form
138 $.post($form.attr('action'), $form.serialize() , function(data) {
139 if(data.success == true) {
140 PMA_ajaxShowMessage(data.message);
142 PMA_ajaxShowMessage(data.error);
144 if ($("#insert_table_dialog").length > 0) {
145 $("#insert_table_dialog").dialog("close").remove();
147 /**Update the row count at the tableForm*/
148 current_insert_table.closest('tr').find('.value.tbl_rows').html(data.row_count);
150 }) // end insert table button "Go"
152 $("#buttonYes.ajax").live('click', function(event){
153 event.preventDefault();
155 * @var the_form object referring to the insert form
157 var $form = $("#insertForm");
158 /**Get the submit type and the after insert type in the form*/
159 var selected_submit_type = $("#insertForm").find("#actions_panel .control_at_footer option:selected").attr('value');
160 var selected_after_insert = $("#insertForm").find("#actions_panel select[name=after_insert] option:selected").attr('value');
161 $("#result_query").remove();
162 PMA_prepareForAjaxRequest($form);
163 //User wants to submit the form
164 $.post($form.attr('action'), $form.serialize() , function(data) {
165 if(data.success == true) {
166 PMA_ajaxShowMessage(data.message);
167 if (selected_submit_type == "showinsert") {
168 $(data.sql_query).insertAfter("#topmenucontainer");
169 $("#result_query .notice").remove();
170 $("#result_query").prepend((data.message));
172 if (selected_after_insert == "new_insert") {
173 /**Trigger the insert dialog for new_insert option*/
174 current_insert_table.trigger('click');
178 PMA_ajaxShowMessage(data.error);
180 if ($("#insert_table_dialog").length > 0) {
181 $("#insert_table_dialog").dialog("close").remove();
183 /**Update the row count at the tableForm*/
184 current_insert_table.closest('tr').find('.value.tbl_rows').html(data.row_count);
189 * Ajax Event handler for 'Truncate Table'
191 * @uses $.PMA_confirm()
192 * @uses PMA_ajaxShowMessage()
193 * @see $cfg['AjaxEnable']
195 $(".truncate_table_anchor").live('click', function(event) {
196 event.preventDefault();
199 * @var $this_anchor Object referring to the anchor clicked
201 var $this_anchor = $(this);
203 //extract current table name and build the question string
205 * @var curr_table_name String containing the name of the table to be truncated
207 var curr_table_name = $this_anchor.parents('tr').children('th').children('a').text();
209 * @var question String containing the question to be asked for confirmation
211 var question = 'TRUNCATE ' + curr_table_name;
213 $this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function(url) {
215 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
217 $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
218 if (data.success == true) {
219 PMA_ajaxShowMessage(data.message);
220 //Fetch inner span of this anchor
221 //and replace the icon with its disabled version
222 var span = $this_anchor.html().replace(/ic_b_empty/, 'ic_bd_empty');
223 PMA_adjustTotals($this_anchor);
225 //To disable further attempts to truncate the table,
226 //replace the a element with its inner span (modified)
229 .removeClass('truncate_table_anchor');
231 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
234 }) //end $.PMA_confirm()
235 }); //end of Truncate Table Ajax action
238 * Ajax Event handler for 'Drop Table'
240 * @uses $.PMA_confirm()
241 * @uses PMA_ajaxShowMessage()
242 * @see $cfg['AjaxEnable']
244 $(".drop_table_anchor").live('click', function(event) {
245 event.preventDefault();
247 var $this_anchor = $(this);
249 //extract current table name and build the question string
251 * @var $curr_row Object containing reference to the current row
253 var $curr_row = $this_anchor.parents('tr');
255 * @var curr_table_name String containing the name of the table to be truncated
257 var curr_table_name = $curr_row.children('th').children('a').text();
259 * @var question String containing the question to be asked for confirmation
261 var question = 'DROP TABLE ' + curr_table_name;
263 $this_anchor.PMA_confirm(question, $this_anchor.attr('href'), function(url) {
265 PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
267 $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
268 if (data.success == true) {
269 PMA_ajaxShowMessage(data.message);
270 PMA_adjustTotals($this_anchor);
271 $curr_row.hide("medium").remove();
273 if (window.parent && window.parent.frame_navigation) {
274 window.parent.frame_navigation.location.reload();
277 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
280 }); // end $.PMA_confirm()
281 }); //end of Drop Table Ajax action
284 * Ajax Event handler for 'Drop tracking'
286 * @uses $.PMA_confirm()
287 * @uses PMA_ajaxShowMessage()
288 * @see $cfg['AjaxEnable']
290 $('.drop_tracking_anchor').live('click', function(event) {
291 event.preventDefault();
293 var $anchor = $(this);
296 * @var curr_tracking_row Object containing reference to the current tracked table's row
298 var curr_tracking_row = $anchor.parents('tr');
300 * @var question String containing the question to be asked for confirmation
302 var question = PMA_messages['strDeleteTrackingData'];
304 $anchor.PMA_confirm(question, $anchor.attr('href'), function(url) {
306 PMA_ajaxShowMessage(PMA_messages['strDeletingTrackingData']);
308 $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
309 if(data.success == true) {
310 PMA_ajaxShowMessage(data.message);
311 $(curr_tracking_row).hide("medium").remove();
314 PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
317 }) // end $.PMA_confirm()
318 }) //end Drop Tracking
320 //Calculate Real End for InnoDB
322 * Ajax Event handler for calculatig the real end for a InnoDB table
324 * @uses $.PMA_confirm
326 $('#real_end_input').live('click', function(event) {
327 event.preventDefault();
330 * @var question String containing the question to be asked for confirmation
332 var question = PMA_messages['strOperationTakesLongTime'];
334 $(this).PMA_confirm(question, '', function() {
338 }) //end Calculate Real End for InnoDB
340 }, 'top.frame_content'); // end $(document).ready()