Translation update done using Pootle.
[phpmyadmin/testing.git] / js / db_structure.js
blob4affd75bd2cf68629769a9be4991b019a545bb88
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      * @see     $cfg['AjaxEnable']
61      */
62     $(".truncate_table_anchor").live('click', function(event) {
63         event.preventDefault();
65         /**
66          * @var $this_anchor Object  referring to the anchor clicked
67          */
68         var $this_anchor = $(this);
70         //extract current table name and build the question string
71         /**
72          * @var curr_table_name String containing the name of the table to be truncated
73          */
74         var curr_table_name = $this_anchor.parents('tr').children('th').children('a').text();
75         /**
76          * @var question    String containing the question to be asked for confirmation
77          */
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)
94                     $this_anchor
95                         .replaceWith(span)
96                         .removeClass('truncate_table_anchor');
97                 } else {
98                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
99                 }
100             }) // end $.get()
101         }) //end $.PMA_confirm()
102     }); //end of Truncate Table Ajax action
104     /**
105      * Ajax Event handler for 'Drop Table'
106      *
107      * @uses    $.PMA_confirm()
108      * @uses    PMA_ajaxShowMessage()
109      * @see     $cfg['AjaxEnable']
110      */
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
117         /**
118          * @var $curr_row    Object containing reference to the current row
119          */
120         var $curr_row = $this_anchor.parents('tr');
121         /**
122          * @var curr_table_name String containing the name of the table to be truncated
123          */
124         var curr_table_name = $curr_row.children('th').children('a').text();
125         /**
126          * @var question    String containing the question to be asked for confirmation
127          */
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();
142                     }
143                 } else {
144                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
145                 }
146             }); // end $.get()
147         }); // end $.PMA_confirm()
148     }); //end of Drop Table Ajax action
150     /**
151      * Ajax Event handler for 'Drop Event'
152      * 
153      * @uses    $.PMA_confirm()
154      * @uses    PMA_ajaxShowMessage()
155      * @see     $cfg['AjaxEnable']
156      */
157     $('.drop_event_anchor').live('click', function(event) {
158         event.preventDefault();
160         /**
161          * @var curr_event_row  Object reference to current event's row
162          */
163         var curr_event_row = $(this).parents('tr');
164         /**
165          * @var curr_event_name String containing the name of {@link curr_event_row}
166          */
167         var curr_event_name = $(curr_event_row).children('td:first').text();
168         /**
169          * @var question    String containing the question to be asked for confirmation
170          */
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();
181                 }
182                 else {
183                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
184                 }
185             }) // end $.get()
186         }) // end $.PMA_confirm()
187     }) //end Drop Event
189     /**
190      * Ajax Event handler for 'Drop Procedure'
191      * 
192      * @uses    $.PMA_confirm()
193      * @uses    PMA_ajaxShowMessage()
194      * @see     $cfg['AjaxEnable']
195      */
196     $('.drop_procedure_anchor').live('click', function(event) {
197         event.preventDefault();
199         /**
200          * @var curr_proc_row   Object containing reference to the current procedure's row
201          */
202         var curr_proc_row = $(this).parents('tr');
203         /**
204          * @var question    String containing the question to be asked for confirmation
205          */
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();
216                 }
217                 else {
218                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
219                 }
220             }) // end $.get()
221         }) // end $.PMA_confirm()
222     }) //end Drop Procedure
223     
224     /**
225      * Ajax Event handler for 'Drop tracking'
226      * 
227      * @uses    $.PMA_confirm()
228      * @uses    PMA_ajaxShowMessage()
229      * @see     $cfg['AjaxEnable']
230      */
231     $('.drop_tracking_anchor').live('click', function(event) {
232         event.preventDefault();
234         var $anchor = $(this);
236         /**
237          * @var curr_tracking_row   Object containing reference to the current tracked table's row
238          */
239         var curr_tracking_row = $anchor.parents('tr');
240          /**
241          * @var question    String containing the question to be asked for confirmation
242          */
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();
253                 }
254                 else {
255                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
256                 }
257             }) // end $.get()
258         }) // end $.PMA_confirm()
259     }) //end Drop Tracking
261     //Calculate Real End for InnoDB
262     /**
263      * Ajax Event handler for calculatig the real end for a InnoDB table
264      * 
265      * @uses    $.PMA_confirm
266      */
267     $('#real_end_input').live('click', function(event) {
268         event.preventDefault();
270         /**
271          * @var question    String containing the question to be asked for confirmation
272          */
273         var question = PMA_messages['strOperationTakesLongTime'];
275         $(this).PMA_confirm(question, '', function() {
276             return true;
277         })
278         return false;
279     }) //end Calculate Real End for InnoDB
281 }, 'top.frame_content'); // end $(document).ready()