Autogenerating Quick Links.

ipa_entity_quick_links() has been added to generate quick links
automatically from object's attribute_members, the same logic used
for generating facet list. The search definition for each entity
has been updated to use the new function. A unit test has been
added for this function.
This commit is contained in:
Endi S. Dewata 2010-10-01 12:53:13 -05:00 committed by Adam Young
parent 38490d35d3
commit aa7ecb6f5f
11 changed files with 173 additions and 215 deletions

View File

@ -202,3 +202,50 @@ function ipa_entity_generate_views(obj_name, container, switch_view)
container.append(ul);
}
function ipa_entity_quick_links(tr, attr, value, entry_attrs) {
var obj_name = tr.closest('.search-container').attr('title');
var pkey = ipa_objs[obj_name].primary_key;
var pkey_value = entry_attrs[pkey][0];
var td = $("<td/>");
tr.append(td);
$("<a/>", {
href: "#details",
click: function() {
var state = {};
state[obj_name+'-facet'] = 'details';
state[obj_name+'-pkey'] = pkey_value;
nav_push_state(state);
return false;
}
}).append($('<img/>', {
src: obj_name+'_details.png'
})).appendTo(td);
var attribute_members = ipa_objs[obj_name].attribute_members;
for (attr_name in attribute_members) {
var objs = attribute_members[attr_name];
for (var i = 0; i < objs.length; ++i) {
var m = objs[i];
$("<a/>", {
href: '#'+m,
click: function(m) {
return function() {
var state = {};
state[obj_name+'-facet'] = 'associate';
state[obj_name+'-enroll'] = m;
state[obj_name+'-pkey'] = pkey_value;
nav_push_state(state);
return false;
}
}(m)
}).append($('<img/>', {
src: m+'_member.png'
})).appendTo(td);
}
}
}

View File

@ -24,7 +24,7 @@ ipa_entity_set_search_definition('group', [
['cn', 'Name', null],
['gidnumber', 'GID', null],
['description', 'Description', null],
['quick_links', 'Quick Links', group_render_quick_links]
['quick_links', 'Quick Links', ipa_entity_quick_links]
]);
ipa_entity_set_add_definition('group', [
@ -64,47 +64,3 @@ function f_posix(dlg, mode)
return (false);
}
}
function group_render_quick_links(tr, attr, value, entry_attrs) {
var td = $("<td/>");
tr.append(td);
$("<a/>", {
href: "jslink",
html: $("<img src='group_details.png' />"),
click: function() {
var state = {};
state['group-facet'] = 'details';
state['group-pkey'] = entry_attrs['cn'][0];
$.bbq.pushState(state);
return false;
}
}).appendTo(td);
$("<a/>", {
href: "jslink",
html: $("<img src='user_enroll.png' />"),
click: function() {
var state = {};
state['group-facet'] = 'associate';
state['group-enroll'] = 'user';
state['group-pkey'] = entry_attrs['cn'][0];
$.bbq.pushState(state);
return false;
}
}).appendTo(td);
$("<a/>", {
href: "jslink",
html: $("<img src='netgroup_member.png' />"),
click: function() {
var state = {};
state['group-facet'] = 'associate';
state['group-enroll'] = 'netgroup';
state['group-pkey'] = entry_attrs['cn'][0];
$.bbq.pushState(state);
return false;
}
}).appendTo(td);
}

View File

@ -24,7 +24,8 @@ ipa_entity_set_search_definition('host', [
['fqdn', 'Name', null],
['description', 'Description', null],
['enrolled', 'Enrolled?', null],
['manages', 'Manages?', null]
['manages', 'Manages?', null],
['quick_links', 'Quick Links', ipa_entity_quick_links]
]);
ipa_entity_set_add_definition('host', [

View File

@ -22,7 +22,8 @@
ipa_entity_set_search_definition('hostgroup', [
['cn', 'Name', null],
['description', 'Description', null]
['description', 'Description', null],
['quick_links', 'Quick Links', ipa_entity_quick_links]
]);
ipa_entity_set_add_definition('hostgroup', [

View File

@ -22,7 +22,8 @@
ipa_entity_set_search_definition('netgroup', [
['cn', 'Name', null],
['description', 'Description', null]
['description', 'Description', null],
['quick_links', 'Quick Links', ipa_entity_quick_links]
]);
ipa_entity_set_add_definition('netgroup', [

View File

@ -23,7 +23,7 @@
ipa_entity_set_search_definition('rolegroup', [
['cn', 'Role-group name', null],
['description', 'Description', null],
['quick_links', 'Quick Links', rolegroup_render_quick_links]
['quick_links', 'Quick Links', ipa_entity_quick_links]
]);
ipa_entity_set_add_definition('rolegroup', [
@ -39,73 +39,3 @@ ipa_entity_set_details_definition('rolegroup', [
['description', 'Description', null],
]]
]);
function rolegroup_render_quick_links(tr, attr, value, entry_attrs) {
var td = $("<td/>");
tr.append(td);
$("<a/>", {
href: "jslink",
html: $("<img src='rolegroup_details.png' />"),
click: function() {
var state = {};
state['rolegroup-facet'] = 'details';
state['rolegroup-pkey'] = entry_attrs['cn'][0];
$.bbq.pushState(state);
return false;
}
}).appendTo(td);
$("<a/>", {
href: "jslink",
html: $("<img src='user_member.png' />"),
click: function() {
var state = {};
state['rolegroup-facet'] = 'associate';
state['rolegroup-enroll'] = 'user';
state['rolegroup-pkey'] = entry_attrs['cn'][0];
$.bbq.pushState(state);
return false;
}
}).appendTo(td);
$("<a/>", {
href: "jslink",
html: $("<img src='group_member.png' />"),
click: function() {
var state = {};
state['rolegroup-facet'] = 'associate';
state['rolegroup-enroll'] = 'group';
state['rolegroup-pkey'] = entry_attrs['cn'][0];
$.bbq.pushState(state);
return false;
}
}).appendTo(td);
$("<a/>", {
href: "jslink",
html: $("<img src='host_member.png' />"),
click: function() {
var state = {};
state['rolegroup-facet'] = 'associate';
state['rolegroup-enroll'] = 'host';
state['rolegroup-pkey'] = entry_attrs['cn'][0];
$.bbq.pushState(state);
return false;
}
}).appendTo(td);
$("<a/>", {
href: "jslink",
html: $("<img src='hostgroup_member.png' />"),
click: function() {
var state = {};
state['rolegroup-facet'] = 'associate';
state['rolegroup-enroll'] = 'hostgroup';
state['rolegroup-pkey'] = entry_attrs['cn'][0];
$.bbq.pushState(state);
return false;
}
}).appendTo(td);
}

View File

@ -22,7 +22,7 @@
ipa_entity_set_search_definition('service', [
['krbprincipalname', 'Principal', null],
['quick_links', 'Quick Links', service_render_quick_links]
['quick_links', 'Quick Links', ipa_entity_quick_links]
]);
ipa_entity_set_add_definition('service', [
@ -39,37 +39,6 @@ ipa_entity_set_details_definition('service', [
]]
]);
function service_render_quick_links(tr, attr, value, entry_attrs) {
var td = $("<td/>");
tr.append(td);
$("<a/>", {
href: "jslink",
html: $("<img src='service_details.png' />"),
click: function() {
var state = {};
state['service-facet'] = 'details';
state['service-pkey'] = entry_attrs['krbprincipalname'][0];
$.bbq.pushState(state);
return false;
}
}).appendTo(td);
$("<a/>", {
href: "jslink",
html: $("<img src='host_enroll.png' />"),
click: function() {
var state = {};
state['service-facet'] = 'associate';
state['service-enroll'] = 'host';
state['service-pkey'] = entry_attrs['krbprincipalname'][0];
$.bbq.pushState(state);
return false;
}
}).appendTo(td);
}
function service_add_krbprincipalname(add_dialog, flag) {
if (flag == IPA_ADD_UPDATE) {
var service = add_dialog.find('input[name=service]').val();

View File

@ -9,6 +9,7 @@
<script type="text/javascript" src="../details.js"></script>
<script type="text/javascript" src="../search.js"></script>
<script type="text/javascript" src="../add.js"></script>
<script type="text/javascript" src="../navigation.js"></script>
<script type="text/javascript" src="../entity.js"></script>
<script type="text/javascript" src="entity_tests.js"></script>
</head>

View File

@ -69,11 +69,11 @@ test("Testing ipa_entity_generate_views().", function() {
ipa_init(
"data",
true,
function(data, status, xhr) {
function(data, text_status, xhr) {
ok(true, "ipa_init() succeeded.");
},
function(xhr, options, thrownError) {
ok(false, "ipa_init() failed: "+thrownError);
function(xhr, text_status, error_thrown) {
ok(false, "ipa_init() failed: "+error_thrown);
}
);
@ -135,3 +135,112 @@ test("Testing ipa_entity_generate_views().", function() {
"Checking callback invocations"
);
});
test("Testing ipa_entity_quick_links().", function() {
var orig_push_state = nav_push_state;
var orig_get_state = nav_get_state;
var orig_remove_state = nav_remove_state;
var state = {};
nav_push_state = function(params) {
$.extend(state, params);
};
nav_get_state = function(key) {
return state[key];
};
nav_remove_state = function(key) {
delete state[key];
};
ipa_ajax_options["async"] = false;
ipa_init(
"data",
true,
function(data, text_status, xhr) {
ok(true, "ipa_init() succeeded.");
},
function(xhr, text_status, error_thrown) {
ok(false, "ipa_init() failed: "+error_thrown);
}
);
var obj_name = "user";
var pkey = ipa_objs[obj_name].primary_key;
var pkey_value = "test";
var entry_attrs = {};
entry_attrs[pkey] = [pkey_value];
var container = $("<div/>", {
title: obj_name,
class: "search-container"
});
var search_table = $('<table/>', {
class: 'search-table'
}).appendTo(container);
var tbody = $("<tbody/>").appendTo(search_table);
var tr = $("<tr/>").appendTo(tbody);
ipa_entity_quick_links(tr, null, null, entry_attrs);
var td = tr.children().first();
var link = td.children().first();
equals(
link.attr("href"), "#details",
"Checking details link"
);
link.click();
equals(
state[obj_name+"-facet"], "details",
"Checking state[\""+obj_name+"-facet\"]"
);
equals(
state[obj_name+"-pkey"], pkey_value,
"Checking state[\""+obj_name+"-pkey\"]"
);
var attribute_members = ipa_objs[obj_name].attribute_members;
for (attr_name in attribute_members) {
var objs = attribute_members[attr_name];
for (var i = 0; i < objs.length; ++i) {
var m = objs[i];
link = link.next();
equals(
link.attr("href"), "#"+m,
"Checking "+m+" link"
);
link.click();
equals(
state[obj_name+"-facet"], "associate",
"Checking state[\""+obj_name+"-facet\"]"
);
equals(
state[obj_name+"-enroll"], m,
"Checking state[\""+obj_name+"-enroll\"]"
);
equals(
state[obj_name+"-pkey"], pkey_value,
"Checking state[\""+obj_name+"-pkey\"]"
);
}
}
nav_push_state = orig_push_state;
nav_get_state = orig_get_state;
nav_remove_state = orig_remove_state;
});

View File

@ -27,11 +27,11 @@ test("Testing ipa_init().", function() {
ipa_init(
"data",
true,
function(data, status, xhr) {
function(data, text_status, xhr) {
ok(true, "ipa_init() succeeded.");
},
function(xhr, options, thrownError) {
ok(false, "ipa_init() failed: "+thrownError);
function(xhr, text_status, error_thrown) {
ok(false, "ipa_init() failed: "+error_thrown);
}
);
});

View File

@ -27,7 +27,7 @@ ipa_entity_set_search_definition('user', [
['mail', 'EMAIL', null],
['telephonenumber', 'Phone', null],
['title', 'Job Title', null],
['quick_links', 'Quick Links', user_render_quick_links]
['quick_links', 'Quick Links', ipa_entity_quick_links]
]);
ipa_entity_set_add_definition('user', [
@ -208,60 +208,3 @@ function a_numbers(jobj, result, mode)
function a_manager(jobj, result, mode)
{
}
function user_render_quick_links(tr, attr, value, entry_attrs) {
var td = $("<td/>");
tr.append(td);
$("<a/>", {
href: "jslink",
html: $("<img src='user_details.png' />"),
click: function() {
var state = {};
state['user-facet'] = 'details';
state['user-pkey'] = entry_attrs['uid'][0];
$.bbq.pushState(state);
return false;
}
}).appendTo(td);
$("<a/>", {
href: "jslink",
html: $("<img src='group_member.png' />"),
click: function() {
var state = {};
state['user-facet'] = 'associate';
state['user-enroll'] = 'group';
state['user-pkey'] = entry_attrs['uid'][0];
$.bbq.pushState(state);
return false;
}
}).appendTo(td);
$("<a/>", {
href: "jslink",
html: $("<img src='netgroup_member.png' />"),
click: function() {
var state = {};
state['user-facet'] = 'associate';
state['user-enroll'] = 'netgroup';
state['user-pkey'] = entry_attrs['uid'][0];
$.bbq.pushState(state);
return false;
}
}).appendTo(td);
$("<a/>", {
href: "jslink",
html: $("<img src='rolegroup_member.png' />"),
click: function() {
var state = {};
state['user-facet'] = 'associate';
state['user-enroll'] = 'role';
state['user-pkey'] = entry_attrs['uid'][0];
$.bbq.pushState(state);
return false;
}
}).appendTo(td);
}