From f9a8d772e35982bed1c39b286b3120b9b5f64c0c Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Fri, 13 May 2011 20:05:35 -0500 Subject: Customizable facet groups. The IPA.entity has been modified to support customizable facet groups. The default list of facet groups is defined in IPA.entity_header and can be overriden in the entity definition. Ticket #1219 --- install/ui/associate.js | 11 +- install/ui/details.js | 1 + install/ui/dns.js | 2 +- install/ui/entity.js | 400 +++++++++++++++++++----------------- install/ui/group.js | 4 +- install/ui/host.js | 2 +- install/ui/netgroup.js | 40 +++- install/ui/service.js | 2 +- install/ui/test/data/ipa_init.json | 13 ++ install/ui/test/data/user_show.json | 3 + install/ui/user.js | 64 ++++-- ipalib/plugins/baseldap.py | 3 + ipalib/plugins/internal.py | 8 + 13 files changed, 329 insertions(+), 224 deletions(-) diff --git a/install/ui/associate.js b/install/ui/associate.js index 15fdfbd72..679e00700 100644 --- a/install/ui/associate.js +++ b/install/ui/associate.js @@ -664,14 +664,12 @@ IPA.association_facet = function (spec) { var that = IPA.facet(spec); - var index = that.name.indexOf('_'); - that.attribute_member = spec.attribute_member || that.name.substring(0, index); - that.other_entity = spec.other_entity || that.name.substring(index+1); - - that.facet_group = spec.facet_group || - IPA.fetch_facet_group(that.entity_name,that.attribute_member); + that.attribute_member = spec.attribute_member; + that.other_entity = spec.other_entity; + that.facet_group = spec.facet_group; that.label = that.label ? that.label : (IPA.metadata.objects[that.other_entity] ? IPA.metadata.objects[that.other_entity].label : that.other_entity); + that.read_only = spec.read_only; that.associator = spec.associator || IPA.bulk_associator; that.add_method = spec.add_method || 'add_member'; @@ -683,7 +681,6 @@ IPA.association_facet = function (spec) { that.adder_columns = []; that.adder_columns_by_name = {}; - that.get_column = function(name) { return that.columns_by_name[name]; }; diff --git a/install/ui/details.js b/install/ui/details.js index a4b36db73..44560b5b0 100644 --- a/install/ui/details.js +++ b/install/ui/details.js @@ -265,6 +265,7 @@ IPA.details_facet = function(spec) { var that = IPA.facet(spec); that.label = (IPA.messages && IPA.messages.facets && IPA.messages.facets.details) || spec.label; + that.facet_group = spec.facet_group || 'settings'; that.sections = []; diff --git a/install/ui/dns.js b/install/ui/dns.js index 6784584b6..e62459afb 100644 --- a/install/ui/dns.js +++ b/install/ui/dns.js @@ -56,7 +56,7 @@ IPA.entity_factories.dnszone = function() { facet({ factory: IPA.records_facet, name: 'records', - facet_group:'Member', + facet_group: 'member', label: IPA.metadata.objects.dnsrecord.label, columns: [ { diff --git a/install/ui/entity.js b/install/ui/entity.js index f649833e1..dbee2b32d 100644 --- a/install/ui/entity.js +++ b/install/ui/entity.js @@ -39,6 +39,7 @@ IPA.facet = function (spec) { that.dialogs = []; that.dialogs_by_name = {}; + // facet group name that.facet_group = spec.facet_group; that.__defineGetter__('entity_name', function() { @@ -203,16 +204,29 @@ IPA.table_facet = function(spec) { return that; }; -IPA.fetch_facet_group = function (name,attribute_member){ - var relationships = IPA.metadata.objects[name].relationships; - var relationship = relationships[attribute_member]; - if (!relationship){ - relationship = ['Member', '', 'no_']; - } - var facet_group = relationship[0]; - return facet_group; -}; +IPA.facet_group = function(spec) { + spec = spec || {}; + + var that = {}; + + that.name = spec.name; + that.label = spec.label; + + that.facets = []; + that.facets_by_name = {}; + + that.add_facet = function(facet) { + that.facets.push(facet); + that.facets_by_name[facet.name] = facet; + }; + + that.get_facet = function(name) { + return that.facets_by_name[name]; + }; + + return that; +}; IPA.entity = function (spec) { @@ -231,13 +245,11 @@ IPA.entity = function (spec) { that.facets = []; that.facets_by_name = {}; + // current facet that.facet_name = null; - /*TODO: Facet_groups are currently unordered. If we need to - * maintain order, we will introduce a class that keeps the order - in an array, while maintaining the dictionary for direct access.*/ - that.facet_groups = {}; - that.autogenerate_associations = false; + that.facet_groups = []; + that.facet_groups_by_name = {}; that.get_dialog = function(name) { return that.dialogs_by_name[name]; @@ -254,31 +266,30 @@ IPA.entity = function (spec) { return that; }; - function init_dialogs (){ - var i; - for (i = 0; i < that.dialogs.length; i += 1){ - that.dialogs[i].init(); - } - return that; - } + that.add_facet_group = function(facet_group) { + that.facet_groups.push(facet_group); + that.facet_groups_by_name[facet_group.name] = facet_group; + }; + + that.get_facet_group = function(name) { + return that.facet_groups_by_name[name]; + }; + + that.remove_facet_groups = function() { + that.facet_groups = []; + that.facet_groups_by_name = {}; + }; that.get_facet = function(name) { - if (name === 'default'){ - var facet_group; - var facet; - if (that.facet_groups["Member"]){ - facet_group = that.facet_groups["Member"]; - facet = facet_group[0]; - } else if (that.facets_by_name.details){ - facet= that.facets_by_name.details; - }else if (that.facet_groups["Member Of"]){ - facet_group = that.facet_groups["Member Of"]; - facet = facet_group[0]; - } - if (facet){ - name = facet.name; - return facet; + if (name === 'default') { + // return the first facet in the first facet group + for (var i=0; i', { 'class': 'facet-tab-group' - }).appendTo(container); + }).appendTo(that.facet_tabs); $('