diff options
author | Endi S. Dewata <edewata@redhat.com> | 2010-10-01 12:53:13 -0500 |
---|---|---|
committer | Adam Young <ayoung@redhat.com> | 2010-10-01 16:17:51 -0400 |
commit | aa7ecb6f5ff234fa9001bbea3ebe2e5360656139 (patch) | |
tree | 8c9957db5803b46daefe12c2889a470f2f83f564 /install | |
parent | 38490d35d3b8410a8077fb035b57cea86dd3bdab (diff) | |
download | freeipa-aa7ecb6f5ff234fa9001bbea3ebe2e5360656139.tar.gz freeipa-aa7ecb6f5ff234fa9001bbea3ebe2e5360656139.tar.xz freeipa-aa7ecb6f5ff234fa9001bbea3ebe2e5360656139.zip |
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.
Diffstat (limited to 'install')
-rw-r--r-- | install/static/entity.js | 47 | ||||
-rw-r--r-- | install/static/group.js | 46 | ||||
-rw-r--r-- | install/static/host.js | 3 | ||||
-rw-r--r-- | install/static/hostgroup.js | 3 | ||||
-rw-r--r-- | install/static/netgroup.js | 3 | ||||
-rw-r--r-- | install/static/rolegroup.js | 72 | ||||
-rw-r--r-- | install/static/service.js | 33 | ||||
-rw-r--r-- | install/static/test/entity_tests.html | 1 | ||||
-rw-r--r-- | install/static/test/entity_tests.js | 115 | ||||
-rw-r--r-- | install/static/test/ipa_tests.js | 6 | ||||
-rw-r--r-- | install/static/user.js | 59 |
11 files changed, 173 insertions, 215 deletions
diff --git a/install/static/entity.js b/install/static/entity.js index 39836fe39..5be67a394 100644 --- a/install/static/entity.js +++ b/install/static/entity.js @@ -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); + } + } +} diff --git a/install/static/group.js b/install/static/group.js index b1c0d895e..4c2c5b0a4 100644 --- a/install/static/group.js +++ b/install/static/group.js @@ -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); -} diff --git a/install/static/host.js b/install/static/host.js index f59c1a3c0..432f2f755 100644 --- a/install/static/host.js +++ b/install/static/host.js @@ -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', [ diff --git a/install/static/hostgroup.js b/install/static/hostgroup.js index 512ebcf8a..e3863fe38 100644 --- a/install/static/hostgroup.js +++ b/install/static/hostgroup.js @@ -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', [ diff --git a/install/static/netgroup.js b/install/static/netgroup.js index 625ebfdd4..577590ac2 100644 --- a/install/static/netgroup.js +++ b/install/static/netgroup.js @@ -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', [ diff --git a/install/static/rolegroup.js b/install/static/rolegroup.js index 2e52f1055..0297554d1 100644 --- a/install/static/rolegroup.js +++ b/install/static/rolegroup.js @@ -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); -} diff --git a/install/static/service.js b/install/static/service.js index 8d8e103d9..c12e5636d 100644 --- a/install/static/service.js +++ b/install/static/service.js @@ -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(); diff --git a/install/static/test/entity_tests.html b/install/static/test/entity_tests.html index 224bb23da..a6d3f72fe 100644 --- a/install/static/test/entity_tests.html +++ b/install/static/test/entity_tests.html @@ -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> diff --git a/install/static/test/entity_tests.js b/install/static/test/entity_tests.js index 78fa2d4f3..09967c2c5 100644 --- a/install/static/test/entity_tests.js +++ b/install/static/test/entity_tests.js @@ -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; +}); diff --git a/install/static/test/ipa_tests.js b/install/static/test/ipa_tests.js index 8617a8439..58315585d 100644 --- a/install/static/test/ipa_tests.js +++ b/install/static/test/ipa_tests.js @@ -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); } ); }); diff --git a/install/static/user.js b/install/static/user.js index 5ac7f0ae3..2698c8b00 100644 --- a/install/static/user.js +++ b/install/static/user.js @@ -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); -} |