make USE work in the context of ajaxification
[phpmyadmin/crack.git] / js / db_structure.js
blob8e658fb8dd54c3b22bd68c407420e6e3ca3e8e96
1 /**
2  * @fileoverview    functions used on the database structure page
3  * @name            Database Structure
4  *
5  * @requires    jQuery
6  * @requires    jQueryUI
7  * @required    js/functions.js
8  */
10 /**
11  * AJAX scripts for db_structure.php
12  * 
13  * Actions ajaxified here:
14  * Drop Database
15  * Truncate Table
16  * Drop Table
17  *
18  */
19 $(document).ready(function() {
21     /**
22      * Ajax Event handler for 'Truncate Table'
23      *
24      * @uses    $.PMA_confirm()
25      * @uses    PMA_ajaxShowMessage()
26      */
27     $(".truncate_table_anchor").live('click', function(event) {
28         event.preventDefault();
30         //extract current table name and build the question string
31         /**
32          * @var curr_table_name String containing the name of the table to be truncated
33          */
34         var curr_table_name = $(this).parents('tr').children('th').children('a').text();
35         /**
36          * @var question    String containing the question to be asked for confirmation
37          */
38         var question = 'TRUNCATE ' + curr_table_name;
39         /**
40          * @var this_anchor Object  referring to the anchor clicked
41          */
42         var this_anchor = $(this);
44         $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
46             PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
48             $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
49                 if(data.success == true) {
50                     PMA_ajaxShowMessage(data.message);
51                     //Remove the action's href and class, so as to disable further attempts to truncate the table
52                     // @todo: How to replace the icon with the disabled version?
53                     $(this_anchor)
54                     .removeAttr('href')
55                     .removeClass('.truncate_table_anchor');
56                 }
57                 else {
58                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
59                 }
60             }) // end $.get()
61         }) //end $.PMA_confirm()
62     }); //end of Truncate Table Ajax action
64     /**
65      * Ajax Event handler for 'Drop Table'
66      *
67      * @uses    $.PMA_confirm()
68      * @uses    PMA_ajaxShowMessage()
69      */
70     $(".drop_table_anchor").live('click', function(event) {
71         event.preventDefault();
73         //extract current table name and build the question string
74         /**
75          * @var curr_row    Object containing reference to the current row
76          */
77         var curr_row = $(this).parents('tr');
78         /**
79          * @var curr_table_name String containing the name of the table to be truncated
80          */
81         var curr_table_name = $(curr_row).children('th').children('a').text();
82         /**
83          * @var question    String containing the question to be asked for confirmation
84          */
85         var question = 'DROP TABLE ' + curr_table_name;
87         $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
89             PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
91             $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
92                 if(data.success == true) {
93                     PMA_ajaxShowMessage(data.message);
94                     //need to find a better solution here.  The icon should be replaced
95                     $(curr_row).hide("medium").remove();
96                 }
97                 else {
98                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
99                 }
100             }); // end $.get()
101         }); // end $.PMA_confirm()
102     }); //end of Drop Table Ajax action
104     /**
105      * Ajax Event handler for 'Drop Event'
106      * 
107      * @uses    $.PMA_confirm()
108      * @uses    PMA_ajaxShowMessage()
109      */
110     $('.drop_event_anchor').live('click', function(event) {
111         event.preventDefault();
113         /**
114          * @var curr_event_row  Object reference to current event's row
115          */
116         var curr_event_row = $(this).parents('tr');
117         /**
118          * @var curr_event_name String containing the name of {@link curr_event_row}
119          */
120         var curr_event_name = $(curr_event_row).children('td:first').text();
121         /**
122          * @var question    String containing the question to be asked for confirmation
123          */
124         var question = 'DROP EVENT ' + curr_event_name;
126         $(this).PMA_confirm(question, $(this).attr('href') , function(url) {
128             PMA_ajaxShowMessage(PMA_messages['strDroppingEvent']);
130             $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
131                 if(data.success == true) {
132                     PMA_ajaxShowMessage(data.message);
133                     $(curr_event_row).hide("medium").remove();
134                 }
135                 else {
136                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
137                 }
138             }) // end $.get()
139         }) // end $.PMA_confirm()
140     }) //end Drop Event
142     /**
143      * Ajax Event handler for 'Drop Procedure'
144      * 
145      * @uses    $.PMA_confirm()
146      * @uses    PMA_ajaxShowMessage()
147      */
148     $('.drop_procedure_anchor').live('click', function(event) {
149         event.preventDefault();
151         /**
152          * @var curr_proc_row   Object containing reference to the current procedure's row
153          */
154         var curr_proc_row = $(this).parents('tr');
155         /**
156          * @var question    String containing the question to be asked for confirmation
157          */
158         var question = $(curr_proc_row).children('.drop_procedure_sql').val();
160         $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
162             PMA_ajaxShowMessage(PMA_messages['strDroppingProcedure']);
164             $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
165                 if(data.success == true) {
166                     PMA_ajaxShowMessage(data.message);
167                     $(curr_event_row).hide("medium").remove();
168                 }
169                 else {
170                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
171                 }
172             }) // end $.get()
173         }) // end $.PMA_confirm()
174     }) //end Drop Procedure
175     
176     $('.drop_tracking_anchor').live('click', function(event) {
177         event.preventDefault();
179         /**
180          * @var curr_tracking_row   Object containing reference to the current tracked table's row
181          */
182         var curr_tracking_row = $(this).parents('tr');
183          /**
184          * @var question    String containing the question to be asked for confirmation
185          */
186         var question = PMA_messages['strDeleteTrackingData'];
188         $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
190             PMA_ajaxShowMessage(PMA_messages['strDeletingTrackingData']);
192             $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
193                 if(data.success == true) {
194                     PMA_ajaxShowMessage(data.message);
195                     $(curr_tracking_row).hide("medium").remove();
196                 }
197                 else {
198                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
199                 }
200             }) // end $.get()
201         }) // end $.PMA_confirm()
202     }) //end Drop Tracking
204     //Calculate Real End for InnoDB
205     /**
206      * Ajax Event handler for calculatig the real end for a InnoDB table
207      * 
208      * @uses    $.PMA_confirm
209      */
210     $('#real_end_input').live('click', function(event) {
211         event.preventDefault();
213         /**
214          * @var question    String containing the question to be asked for confirmation
215          */
216         var question = PMA_messages['strOperationTakesLongTime'];
218         $(this).PMA_confirm(question, '', function() {
219             return true;
220         })
221         return false;
222     }) //end Calculate Real End for InnoDB
224 }, 'top.frame_content'); // end $(document).ready()