From b170a07b7c17ab0969da4c91c801c88347ce2c0e Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 1 Jul 2014 18:02:53 +1000 Subject: [PATCH] Reinstate highlighting of selected container in Containers view The AJAX updating of the containers is the culprit here in a couple of ways. Firstly, the AJAX update (the short-circuit in MultiTableView.construct_tables) doesn't have the context from the URL which indicates which of the rows should be highlighted. This is because the current_item_id is only set on the navigation table in the case where the whole browser is being rendered, rather than just part of it. Shifting setting that attribute to all cases allows lower-level access to the attribute. Secondly, the handling of the AJAX update (in DataTable.maybe_preempt) doesn't check the row it creates to see whether it should be selected. Change-Id: Ibecb761a4bde25c1ea4e33a581dd0586ecc42ea0 Closes-bug: 1299828 --- horizon/browsers/base.py | 2 -- horizon/browsers/views.py | 8 ++++++++ horizon/tables/base.py | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/horizon/browsers/base.py b/horizon/browsers/base.py index 946935c25..4b9193b57 100644 --- a/horizon/browsers/base.py +++ b/horizon/browsers/base.py @@ -126,8 +126,6 @@ class ResourceBrowser(html.HTMLElement): self.content_table = tables[self.content_table_class._meta.name] navigation_item = self.kwargs.get(self.navigation_kwarg_name) content_path = self.kwargs.get(self.content_kwarg_name) - # Tells the navigation table what is selected. - self.navigation_table.current_item_id = navigation_item if self.has_breadcrumb: self.prepare_breadcrumb(tables, navigation_item, content_path) diff --git a/horizon/browsers/views.py b/horizon/browsers/views.py index 30b6dd896..46c0b9273 100644 --- a/horizon/browsers/views.py +++ b/horizon/browsers/views.py @@ -41,6 +41,14 @@ class ResourceBrowserView(MultiTableView): ct._no_data_message = _("Select a %s to browse.") % item return browser + def get_tables(self): + tables = super(ResourceBrowserView, self).get_tables() + # Tells the navigation table what is selected. + navigation_table = tables[self.browser_class.navigation_table_class._meta.name] + navigation_item = self.kwargs.get(self.browser_class.navigation_kwarg_name) + navigation_table.current_item_id = navigation_item + return tables + def get_context_data(self, **kwargs): context = super(ResourceBrowserView, self).get_context_data(**kwargs) browser = self.get_browser() diff --git a/horizon/tables/base.py b/horizon/tables/base.py index 4bb366318..ef16ba94f 100644 --- a/horizon/tables/base.py +++ b/horizon/tables/base.py @@ -1370,9 +1370,13 @@ class DataTable(object): if table_name == self.name: # Handle AJAX row updating. new_row = self._meta.row_class(self) + if new_row.ajax and new_row.ajax_action_name == action_name: try: datum = new_row.get_data(request, obj_id) + if self.get_object_id(datum) == self.current_item_id: + self.selected = True + new_row.classes.append('current_selected') new_row.load_cells(datum) error = False except Exception: