Merge "Enhancement on prompts to list selected objects."

This commit is contained in:
Jenkins 2013-04-24 12:25:30 +00:00 committed by Gerrit Code Review
commit 09965a929f
4 changed files with 28 additions and 19 deletions

View File

@ -129,30 +129,28 @@ horizon.datatables.confirm = function (action) {
var $action = $(action),
$modal_parent = $(action).closest('.modal'),
name_array = new Array(),
name_thead, row_index, col_index, closest_table_id,
action_string, name_string, title, body, modal, form;
closest_table_id, action_string, name_string,
title, body, modal, form;
if($action.hasClass("disabled")) {
return;
}
action_string = $action.text();
name_string = "";
// Searchs a name field
// Add the display name defined by table.get_object_display(datum)
closest_table_id = $(action).closest("table").attr("id");
name_thead = $("#"+closest_table_id+" thead").first().find("th:contains('Name')");
row_index = $(name_thead).parent().index("tr");
col_index = $(name_thead).index("tr:eq("+row_index+") th");
if (col_index != -1) {
name_string = gettext("You have selected ");
if($(action).closest("div").hasClass("table_actions")) {
// One or more checkboxes selected
$("#"+closest_table_id+" tr").has(":checkbox:checked").find("td:eq("+col_index+")").each(function() {
name_array.push(" \"" + $(this).text() + "\"");
});
name_array.join(", ");
name_string += name_array.toString() + ". ";
// Check if data-display attribute is available
if ($("#"+closest_table_id+" tr[data-display]").length > 0) {
name_string = gettext("You have selected ");
if($(action).closest("div").hasClass("table_actions")) {
// One or more checkboxes selected
$("#"+closest_table_id+" tr[data-display]").has(":checkbox:checked").each(function() {
name_array.push(" \"" + $(this).attr("data-display") + "\"");
});
name_array.join(", ");
name_string += name_array.toString() + ". ";
} else {
// If no checkbox is selected
name_string += " \"" + $(action).closest("tr").find("td:eq("+col_index+")").text() + "\". ";
// If no checkbox is selected
name_string += " \"" + $(action).closest("tr").attr("data-display") + "\". ";
}
}
title = gettext("Confirm ") + action_string;

View File

@ -479,6 +479,11 @@ class Row(html.HTMLElement):
self.id = "%(table)s%(sep)srow%(sep)s%(id)s" % id_vals
self.attrs['id'] = self.id
# Add the row's display name if available
display_name = table.get_object_display(datum)
if display_name:
self.attrs['data-display'] = escape(display_name)
def __repr__(self):
return '<%s: %s>' % (self.__class__.__name__, self.id)
@ -1249,7 +1254,9 @@ class DataTable(object):
By default, this returns a ``name`` attribute from the given object,
but this can be overriden to return other values.
"""
return datum.name
if hasattr(datum, 'name'):
return datum.name
return None
def has_more_data(self):
"""

View File

@ -143,7 +143,8 @@ class InstanceViewTest(test.BaseAdminViewTests):
self.assertContains(res, "test_tenant", 1, 200)
self.assertContains(res, "instance-host", 1, 200)
self.assertContains(res, "server_1", 1, 200)
# two instances of name, other name comes from row data-display
self.assertContains(res, "server_1", 2, 200)
self.assertContains(res, "10.0.0.1", 1, 200)
self.assertContains(res, "512MB RAM | 1 VCPU | 0 Disk", 1, 200)
self.assertContains(res, "Active", 1, 200)

View File

@ -267,6 +267,7 @@ def data(TEST):
"description": u"NotDefault."})
rule = {'id': get_id(is_uuid),
'group': {},
'ip_protocol': u"tcp",
'from_port': u"80",
'to_port': u"80",
@ -274,6 +275,7 @@ def data(TEST):
'ip_range': {'cidr': u"0.0.0.0/32"}}
icmp_rule = {'id': get_id(is_uuid),
'group': {},
'ip_protocol': u"icmp",
'from_port': u"9",
'to_port': u"5",
@ -281,6 +283,7 @@ def data(TEST):
'ip_range': {'cidr': u"0.0.0.0/32"}}
group_rule = {'id': 3,
'group': {},
'ip_protocol': u"tcp",
'from_port': u"80",
'to_port': u"80",