diff options
author | Madhura Jayaratne <madhura.cj@gmail.com> | 2011-12-11 13:24:14 +0400 |
---|---|---|
committer | Madhura Jayaratne <madhura.cj@gmail.com> | 2011-12-11 13:24:14 +0400 |
commit | e7e5f058b1b3ead3f94728800e5e1bc36a7b1d09 (patch) | |
tree | 7a4766f0747a01e7709cd587cc23824a0ea38a57 | |
parent | 8fa0b5b57fda035d77382ba96079468486c5df56 (diff) |
Better AJAX functionality for Tracking page in Database view
-rw-r--r-- | db_tracking.php | 2 | ||||
-rw-r--r-- | js/db_structure.js | 63 |
2 files changed, 58 insertions, 7 deletions
diff --git a/db_tracking.php b/db_tracking.php index 1078fa26fb..a448647c2c 100644 --- a/db_tracking.php +++ b/db_tracking.php @@ -76,6 +76,7 @@ $all_tables_result = PMA_query_as_controluser($all_tables_query); // If a HEAD version exists if (PMA_DBI_num_rows($all_tables_result) > 0) { ?> + <div id="tracked_tables"> <h3><?php echo __('Tracked tables');?></h3> <table id="versions" class="data"> @@ -146,6 +147,7 @@ if (PMA_DBI_num_rows($all_tables_result) > 0) { ?> </tbody> </table> + </div> <?php } diff --git a/js/db_structure.js b/js/db_structure.js index bb1e38e959..70a593285f 100644 --- a/js/db_structure.js +++ b/js/db_structure.js @@ -366,7 +366,7 @@ $(document).ready(function() { /** * @var curr_tracking_row Object containing reference to the current tracked table's row */ - var curr_tracking_row = $anchor.parents('tr'); + var $curr_tracking_row = $anchor.parents('tr'); /** * @var question String containing the question to be asked for confirmation */ @@ -378,15 +378,64 @@ $(document).ready(function() { $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) { if(data.success == true) { + var $tracked_table = $curr_tracking_row.parents('table'); + var table_name = $curr_tracking_row.find('td:nth-child(2)').text(); + + // Check how many rows will be left after we remove + if ($tracked_table.find('tbody tr').length === 1) { + // We are removing the only row it has + $('#tracked_tables').hide("slow").remove(); + } else { + // There are more rows left after the deletion + $curr_tracking_row.hide("slow", function () { + $(this).remove(); + // Maybe some row classes are wrong now. Iterate and correct. + var ct = 0; + var rowclass = ''; + $tracked_table.find('tbody tr').each(function () { + rowclass = (ct % 2 === 0) ? 'odd' : 'even'; + $(this).removeClass().addClass(rowclass); + ct++; + }); + }); + } + + // Make the removed table visible in the list of 'Untracked tables'. + $untracked_table = $('table#noversions'); + $untracked_table.find('tbody tr').each(function () { + var $row = $(this); + var tmp_tbl_name = $row.find('td:nth-child(1)').text(); + if (tmp_tbl_name > table_name) { + var $cloned = $row.clone(); + // Change the table name of the cloned row. + $cloned.find('td:first-child').text(table_name); + // Change the link of the cloned row. + var new_url = $cloned + .find('td:nth-child(2) a') + .attr('href') + .replace('table=' + tmp_tbl_name, 'table=' + table_name); + $cloned.find('td:nth-child(2) a').attr('href', new_url); + $cloned.insertBefore($row); + return false; + } + }); + + // Maybe some row classes are wrong now. Iterate and correct. + var ct = 0; + var rowclass = ''; + $untracked_table.find('tbody tr').each(function () { + rowclass = (ct % 2 === 0) ? 'odd' : 'even'; + $(this).removeClass().addClass(rowclass); + ct++; + }); + PMA_ajaxShowMessage(data.message); - $(curr_tracking_row).hide("medium").remove(); - } - else { + } else { PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error, false); } - }) // end $.get() - }) // end $.PMA_confirm() - }) //end Drop Tracking + }); // end $.get() + }); // end $.PMA_confirm() + }); //end Drop Tracking //Calculate Real End for InnoDB /** |