Merge branch 'QA_3_4'
[phpmyadmin-themes.git] / js / db_structure.js
blob03aa8e15857d6edd30564028f2747d97b3b312ff
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * @fileoverview    functions used on the database structure page
4  * @name            Database Structure
5  *
6  * @requires    jQuery
7  * @requires    jQueryUI
8  * @required    js/functions.js
9  */
11 /**
12  * AJAX scripts for db_structure.php
13  * 
14  * Actions ajaxified here:
15  * Drop Database
16  * Truncate Table
17  * Drop Table
18  *
19  */
21 /**
22  * Adjust number of rows and total size in the summary
23  * when emptying or dropping a table
24  *
25  * @param jQuery object     $this_anchor
26  */
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)
34     $rows_td.text('0');
35     // set size to unknown (not sure how to get the exact
36     // value here, as an empty InnoDB table would have a size) 
37     $size_td.text('-');
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);
45         }
46     }
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     /**
56      * Ajax Event handler for 'Truncate Table'
57      *
58      * @uses    $.PMA_confirm()
59      * @uses    PMA_ajaxShowMessage()
60      */
61     $(".truncate_table_anchor").live('click', function(event) {
62         event.preventDefault();
64         /**
65          * @var $this_anchor Object  referring to the anchor clicked
66          */
67         var $this_anchor = $(this);
69         //extract current table name and build the question string
70         /**
71          * @var curr_table_name String containing the name of the table to be truncated
72          */
73         var curr_table_name = $this_anchor.parents('tr').children('th').children('a').text();
74         /**
75          * @var question    String containing the question to be asked for confirmation
76          */
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)
93                     $this_anchor
94                         .replaceWith(span)
95                         .removeClass('truncate_table_anchor');
96                 } else {
97                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
98                 }
99             }) // end $.get()
100         }) //end $.PMA_confirm()
101     }); //end of Truncate Table Ajax action
103     /**
104      * Ajax Event handler for 'Drop Table'
105      *
106      * @uses    $.PMA_confirm()
107      * @uses    PMA_ajaxShowMessage()
108      */
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
115         /**
116          * @var $curr_row    Object containing reference to the current row
117          */
118         var $curr_row = $this_anchor.parents('tr');
119         /**
120          * @var curr_table_name String containing the name of the table to be truncated
121          */
122         var curr_table_name = $curr_row.children('th').children('a').text();
123         /**
124          * @var question    String containing the question to be asked for confirmation
125          */
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();
140                     }
141                 } else {
142                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
143                 }
144             }); // end $.get()
145         }); // end $.PMA_confirm()
146     }); //end of Drop Table Ajax action
148     /**
149      * Ajax Event handler for 'Drop Event'
150      * 
151      * @uses    $.PMA_confirm()
152      * @uses    PMA_ajaxShowMessage()
153      */
154     $('.drop_event_anchor').live('click', function(event) {
155         event.preventDefault();
157         /**
158          * @var curr_event_row  Object reference to current event's row
159          */
160         var curr_event_row = $(this).parents('tr');
161         /**
162          * @var curr_event_name String containing the name of {@link curr_event_row}
163          */
164         var curr_event_name = $(curr_event_row).children('td:first').text();
165         /**
166          * @var question    String containing the question to be asked for confirmation
167          */
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();
178                 }
179                 else {
180                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
181                 }
182             }) // end $.get()
183         }) // end $.PMA_confirm()
184     }) //end Drop Event
186     /**
187      * Ajax Event handler for 'Drop Procedure'
188      * 
189      * @uses    $.PMA_confirm()
190      * @uses    PMA_ajaxShowMessage()
191      */
192     $('.drop_procedure_anchor').live('click', function(event) {
193         event.preventDefault();
195         /**
196          * @var curr_proc_row   Object containing reference to the current procedure's row
197          */
198         var curr_proc_row = $(this).parents('tr');
199         /**
200          * @var question    String containing the question to be asked for confirmation
201          */
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();
212                 }
213                 else {
214                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
215                 }
216             }) // end $.get()
217         }) // end $.PMA_confirm()
218     }) //end Drop Procedure
219     
220     $('.drop_tracking_anchor').live('click', function(event) {
221         event.preventDefault();
223         /**
224          * @var curr_tracking_row   Object containing reference to the current tracked table's row
225          */
226         var curr_tracking_row = $(this).parents('tr');
227          /**
228          * @var question    String containing the question to be asked for confirmation
229          */
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();
240                 }
241                 else {
242                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
243                 }
244             }) // end $.get()
245         }) // end $.PMA_confirm()
246     }) //end Drop Tracking
248     //Calculate Real End for InnoDB
249     /**
250      * Ajax Event handler for calculatig the real end for a InnoDB table
251      * 
252      * @uses    $.PMA_confirm
253      */
254     $('#real_end_input').live('click', function(event) {
255         event.preventDefault();
257         /**
258          * @var question    String containing the question to be asked for confirmation
259          */
260         var question = PMA_messages['strOperationTakesLongTime'];
262         $(this).PMA_confirm(question, '', function() {
263             return true;
264         })
265         return false;
266     }) //end Calculate Real End for InnoDB
268 }, 'top.frame_content'); // end $(document).ready()