Disable edit box in grid editing, while edit area is shown
[phpmyadmin/arisferyanto.git] / js / db_structure.js
bloba3f1c378fbcb9a48590d44c2de0206ccf2d4b615
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)
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)
35     $rows_td.text('0');
36     // set size to unknown (not sure how to get the exact
37     // value here, as an empty InnoDB table would have a size)
38     $size_td.text('-');
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);
46         }
47     }
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() {
55     /**
56      * Ajax Event handler for 'Insert Table'
57      *
58      * @uses    PMA_ajaxShowMessage()
59      * @see     $cfg['AjaxEnable']
60      */
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);
68         }
70         if ($("#insert_table_dialog").length > 0) {
71             $("#insert_table_dialog").remove();
72         }
73            var $div = $('<div id="insert_table_dialog"></div>');
74            var target = "tbl_change.php";
76         /**
77          *  @var    button_options  Object that stores the options passed to jQueryUI
78          *                          dialog
79          */
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) {
92                 $div
93                 .append(data.error)
94                 .dialog({
95                     title: PMA_messages['strInsertTable'],
96                     height: 230,
97                     width: 900,
98                     modal: true,
99                     open: PMA_verifyColumnsProperties,
100                     buttons : button_options_error
101                 })// end dialog options
102             } else {
103                 var $dialog = $div
104                     .append(data)
105                     .dialog({
106                         title: PMA_messages['strInsertTable'],
107                         height: 600,
108                         width: 900,
109                         modal: true,
110                         open: PMA_verifyColumnsProperties,
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));
118                 });
119                 $(".insertRowTable").addClass("ajax");
120                 $("#buttonYes").addClass("ajax");
121                 $div = $("#insert_table_dialog");
122                 PMA_convertFootnotesToTooltips($div);
123             }
124             PMA_ajaxRemoveMessage($msgbox);
125         }) // end $.get()
127     });
129     $("#insertForm .insertRowTable.ajax input[type=submit]").live('click', function(event) {
130         event.preventDefault();
131         /**
132          *  @var    the_form    object referring to the insert form
133          */
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);
141             } else {
142                 PMA_ajaxShowMessage(data.error);
143             }
144             if ($("#insert_table_dialog").length > 0) {
145                 $("#insert_table_dialog").dialog("close").remove();
146             }
147             /**Update the row count at the tableForm*/
148             current_insert_table.closest('tr').find('.value.tbl_rows').html(data.row_count);
149         }) // end $.post()
150     }) // end insert table button "Go"
152     $("#buttonYes.ajax").live('click', function(event){
153         event.preventDefault();
154         /**
155          *  @var    the_form    object referring to the insert form
156          */
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("#floating_menubar");
169                     $("#result_query .notice").remove();
170                     $("#result_query").prepend((data.message));
171                 }
172                 if (selected_after_insert == "new_insert") {
173                     /**Trigger the insert dialog for new_insert option*/
174                     current_insert_table.trigger('click');
175                 }
177             } else {
178                 PMA_ajaxShowMessage(data.error);
179             }
180             if ($("#insert_table_dialog").length > 0) {
181                 $("#insert_table_dialog").dialog("close").remove();
182             }
183             /**Update the row count at the tableForm*/
184             current_insert_table.closest('tr').find('.value.tbl_rows').html(data.row_count);
185         }) // end $.post()
186     });
188     /**
189      * Ajax Event handler for 'Truncate Table'
190      *
191      * @uses    $.PMA_confirm()
192      * @uses    PMA_ajaxShowMessage()
193      * @see     $cfg['AjaxEnable']
194      */
195     $(".truncate_table_anchor").live('click', function(event) {
196         event.preventDefault();
198         /**
199          * @var $this_anchor Object  referring to the anchor clicked
200          */
201         var $this_anchor = $(this);
203         //extract current table name and build the question string
204         /**
205          * @var curr_table_name String containing the name of the table to be truncated
206          */
207         var curr_table_name = $this_anchor.parents('tr').children('th').children('a').text();
208         /**
209          * @var question    String containing the question to be asked for confirmation
210          */
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(/b_empty/, '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)
227                     $this_anchor
228                         .replaceWith(span)
229                         .removeClass('truncate_table_anchor');
230                 } else {
231                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
232                 }
233             }) // end $.get()
234         }) //end $.PMA_confirm()
235     }); //end of Truncate Table Ajax action
237     /**
238      * Ajax Event handler for 'Drop Table'
239      *
240      * @uses    $.PMA_confirm()
241      * @uses    PMA_ajaxShowMessage()
242      * @see     $cfg['AjaxEnable']
243      */
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
250         /**
251          * @var $curr_row    Object containing reference to the current row
252          */
253         var $curr_row = $this_anchor.parents('tr');
254         /**
255          * @var curr_table_name String containing the name of the table to be truncated
256          */
257         var curr_table_name = $curr_row.children('th').children('a').text();
258         /**
259          * @var question    String containing the question to be asked for confirmation
260          */
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();
275                     }
276                 } else {
277                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
278                 }
279             }); // end $.get()
280         }); // end $.PMA_confirm()
281     }); //end of Drop Table Ajax action
283     /**
284      * Ajax Event handler for 'Drop tracking'
285      *
286      * @uses    $.PMA_confirm()
287      * @uses    PMA_ajaxShowMessage()
288      * @see     $cfg['AjaxEnable']
289      */
290     $('.drop_tracking_anchor').live('click', function(event) {
291         event.preventDefault();
293         var $anchor = $(this);
295         /**
296          * @var curr_tracking_row   Object containing reference to the current tracked table's row
297          */
298         var curr_tracking_row = $anchor.parents('tr');
299          /**
300          * @var question    String containing the question to be asked for confirmation
301          */
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();
312                 }
313                 else {
314                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
315                 }
316             }) // end $.get()
317         }) // end $.PMA_confirm()
318     }) //end Drop Tracking
320     //Calculate Real End for InnoDB
321     /**
322      * Ajax Event handler for calculatig the real end for a InnoDB table
323      *
324      * @uses    $.PMA_confirm
325      */
326     $('#real_end_input').live('click', function(event) {
327         event.preventDefault();
329         /**
330          * @var question    String containing the question to be asked for confirmation
331          */
332         var question = PMA_messages['strOperationTakesLongTime'];
334         $(this).PMA_confirm(question, '', function() {
335             return true;
336         })
337         return false;
338     }) //end Calculate Real End for InnoDB
340 }, 'top.frame_content'); // end $(document).ready()