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
This commit is contained in:
Richard Jones 2014-07-01 18:02:53 +10:00
parent 75a5f5f1f9
commit b170a07b7c
3 changed files with 12 additions and 2 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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: