From 4632aa58ae9d1874f559031f592e2873c0fb4f64 Mon Sep 17 00:00:00 2001 From: Kieran Spear Date: Mon, 14 Jan 2013 14:35:18 +1100 Subject: [PATCH] Don't update count on tables without a summary row The horizon.tabs javascript was updating the last row of any in the tab when the focus was changed to a different tab, stomping over the last row of the table. This commit limits updates to tables with the .datatable class, and adds a class to the updated in affected templates so it can be selected a little more unambiguously. Fixes bug #1080513. Change-Id: I1b778bdc77887dcf540c96c2ab8be239bc13258c --- horizon/static/horizon/js/horizon.tables.js | 10 +++++----- horizon/static/horizon/js/horizon.tabs.js | 4 +++- horizon/templates/horizon/common/_data_table.html | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/horizon/static/horizon/js/horizon.tables.js b/horizon/static/horizon/js/horizon.tables.js index 035daac267..ffe8fdde32 100644 --- a/horizon/static/horizon/js/horizon.tables.js +++ b/horizon/static/horizon/js/horizon.tables.js @@ -18,7 +18,7 @@ horizon.datatables = { // Trigger the update handlers. $rows_to_update.each(function(index, row) { var $row = $(this), - $table = $row.closest('table'); + $table = $row.closest('table.datatable'); horizon.ajax.queue({ url: $row.attr('data-update-url'), error: function (jqXHR, textStatus, errorThrown) { @@ -185,10 +185,10 @@ horizon.datatables.update_footer_count = function (el, modifier) { // code paths for table or browser footers... $browser = $el.closest("#browser_wrapper"); if ($browser.length) { - $footer = $($browser.find('.tfoot span')[1]); + $footer = $browser.find('.tfoot span.content_table_count'); } else { - $footer = $el.find('tr:last span:first'); + $footer = $el.find('table.datatable tfoot span.table_count'); } row_count = $el.find('tbody tr:visible').length + modifier - $el.find('.empty').length; footer_text_template = ngettext("Displaying %s item", "Displaying %s items", row_count); @@ -198,7 +198,7 @@ horizon.datatables.update_footer_count = function (el, modifier) { horizon.datatables.set_table_sorting = function (parent) { // Function to initialize the tablesorter plugin strictly on sortable columns. -$(parent).find("table.table").each(function () { +$(parent).find("table.datatable").each(function () { var $table = $(this), header_options = {}; // Disable if not sortable or has <= 1 item @@ -289,7 +289,7 @@ horizon.datatables.set_table_filter = function (parent) { horizon.addInitFunction(function() { horizon.datatables.validate_button(); - horizon.datatables.update_footer_count($.find('table'),0); + horizon.datatables.update_footer_count($.find('table.datatable'),0); // Bind the "select all" checkbox action. $('div.table_wrapper, #modal_wrapper').on('click', 'table thead .multi_select_column :checkbox', function(evt) { var $this = $(this), diff --git a/horizon/static/horizon/js/horizon.tabs.js b/horizon/static/horizon/js/horizon.tabs.js index 823620bba3..dd536c2b70 100644 --- a/horizon/static/horizon/js/horizon.tabs.js +++ b/horizon/static/horizon/js/horizon.tabs.js @@ -34,7 +34,9 @@ horizon.addInitFunction(function () { $(document).on("shown", ".nav-tabs a[data-toggle='tab']", function (evt) { var $tab = $(evt.target), $content = $($(evt.target).attr('data-target')); - horizon.datatables.update_footer_count($content.find("table")); + $content.find("table.datatable").each(function () { + horizon.datatables.update_footer_count($(this)); + }); horizon.cookies.update("tabs", $tab.closest(".nav-tabs").attr("id"), $tab.attr('data-target')); }); diff --git a/horizon/templates/horizon/common/_data_table.html b/horizon/templates/horizon/common/_data_table.html index 0560f996e1..7384c369bf 100644 --- a/horizon/templates/horizon/common/_data_table.html +++ b/horizon/templates/horizon/common/_data_table.html @@ -3,7 +3,7 @@
{% if needs_form_wrapper %}
{% csrf_token %}{% endif %} {% with columns=table.get_columns rows=table.get_rows %} -
+
@@ -50,7 +50,7 @@ {% endif %}
- {% blocktrans count counter=rows|length %}Displaying {{ counter }} item{% plural %}Displaying {{ counter }} items{% endblocktrans %} + {% blocktrans count counter=rows|length %}Displaying {{ counter }} item{% plural %}Displaying {{ counter }} items{% endblocktrans %} {% if table.has_more_data %} | More »