On 4/20/2011 4:32 PM, Endi Sukma Dewata wrote:
On 4/20/2011 11:50 AM, Adam Young wrote:
Leave the factories as the top level object. For the factory name, say
'entitle' check that the object is in the metadata. If not, don't
create
the entity. Then, when processing the tabs, if the entity does not
exist, drop the tab from the tab set. The explicit enumeration of
entities in webui.js is not necessary, nor is putting every entity's
factory into its own namespace.

I think it would be even better to create only the entities that are
actually needed. So entity creation should be done after we determine
the user and the tab set for that user. What do you think?

Absolutely. I think that the check should be something like:
that.start_entities = function(){
...
for (name in that.entity_factories){
if (!metadata.objects[name]) continue;
...

}

and then the tab gets dropped later if the entity doesn't exist.

I don't think this approach will work for DNS. If dns_is_enabled is
false the entity should not be created either. I'm not sure inserting
this logic in the IPA.start_entities() would be a good idea. The
start_entities() should read from a list of entities to be created
instead of filtering out the entities within the loop.

Attached is a new patch that creates only the entities that are enabled and needed by the navigation tabs. It passes jslint, qunit, and essential Selenium tests.

This patch can be applied against master or your patch #221.

--
Endi S. Dewata
From 6ca409845363fb7620060384c6e5457da06afd74 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Wed, 20 Apr 2011 19:11:10 -0500
Subject: [PATCH] Fixed entity creation and navigation.

Currently all entities are always created regardless its usage. Some
entities such as DNS and entitlement may not actually be available
depending on server configuration. Also the user's authorization
determines which entities are accessible via navigation tabs. The
Web UI has been modified to take these factors into consideration
when creating the entities and navigation tabs.
---
 install/ui/ipa.js                   |   52 +++++------
 install/ui/navigation.js            |  146 ++++++++++++++++++++----------
 install/ui/test/details_tests.js    |    2 +-
 install/ui/test/entity_tests.js     |    2 +-
 install/ui/test/navigation_tests.js |  138 ++++++++++++++---------------
 install/ui/webui.js                 |  168 ++++++++++++++++++++--------------
 6 files changed, 291 insertions(+), 217 deletions(-)

diff --git a/install/ui/ipa.js b/install/ui/ipa.js
index a4fbec4014202956799d1a058f1e0ec767f7959a..de90e7feff775411872f9b78983dfb8e1bb3717b 100644
--- a/install/ui/ipa.js
+++ b/install/ui/ipa.js
@@ -134,18 +134,26 @@ var IPA = ( function () {
         return that.entities_by_name[name];
     };
 
-    function add_entity(entity) {
+    that.add_entity = function(entity) {
         that.entities.push(entity);
         that.entities_by_name[entity.name] = entity;
-    }
+    };
 
-    that.start_entities = function(){
-        var factory;
-        var name ;
-        for (name in that.entity_factories){
-            factory = that.entity_factories[name];
+    that.init_entities = function(entity_names) {
+        var entity_name;
+
+        if (!entity_names) {
+            entity_names = [];
+            for (entity_name in that.entity_factories) {
+                entity_names.push(entity_name);
+            }
+        }
+
+        for (var i=0; i<entity_names.length; i++) {
+            entity_name = entity_names[i];
+            var factory = that.entity_factories[entity_name];
             var entity = factory();
-            add_entity(entity);
+            that.add_entity(entity);
             entity.init();
         }
     };
@@ -180,31 +188,19 @@ var IPA = ( function () {
         return true;
     };
 
-    that.show_page = function (entity_name, facet_name) {
-        if (!IPA.test_dirty()){
-            return false;
+    that.switch_and_show_page = function(entity_name, facet_name, pkey) {
+        if (!IPA.test_dirty()) {
+            return;
         }
 
         var state = {};
+
+        if (pkey) {
+            state[entity_name + '-pkey'] = pkey;
+        }
+
         state[entity_name + '-facet'] = facet_name;
         $.bbq.pushState(state);
-        return true;
-    };
-
-    that.switch_and_show_page = function (this_entity,  facet_name, pkey) {
-        if (!IPA.test_dirty()){
-            return false;
-        }
-
-        if (!pkey){
-            that.show_page(this_entity,  facet_name);
-            return false;
-        }
-        var state = {};
-        state[this_entity+'-pkey'] = pkey;
-        state[this_entity + '-facet'] = facet_name;
-        $.bbq.pushState(state);
-        return true;
     };
 
     that.display_activity_icon = function() {
diff --git a/install/ui/navigation.js b/install/ui/navigation.js
index 365bde66de39c36e473fc2429f78039e41a8b374..37e24da79be31298dd0b7f156ce314274547462b 100644
--- a/install/ui/navigation.js
+++ b/install/ui/navigation.js
@@ -2,6 +2,7 @@
 
 /*  Authors:
  *    Pavel Zuna <pz...@redhat.com>
+ *    Endi S. Dewata <edew...@redhat.com>
  *
  * Copyright (C) 2010 Red Hat
  * see file 'COPYING' for use and warranty information
@@ -20,38 +21,37 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-IPA.nav = {
-    tabs_lists : {},
-    nav_container : {},
+IPA.navigation = function(spec) {
 
-    push_state : function (params) {
-        if (!IPA.test_dirty()){
+    spec = spec || {};
+
+    var that = {};
+
+    that.tab_set = spec.tab_set || [];
+    that.container = spec.container;
+    that.tabclass = spec.tabclass || 'tabs';
+
+    that.push_state = function(params) {
+        if (!IPA.test_dirty()) {
             return false;
         }
         $.bbq.pushState(params);
         return true;
-    },
+    };
 
-    get_state : function (key) {
+    that.get_state = function(key) {
         return $.bbq.getState(key, true);
-    },
+    };
 
-    remove_state : function (key) {
+    that.remove_state = function(key) {
         $.bbq.removeState(key);
-    },
+    };
 
-    create : function (nls, container, tabclass) {
-        if (!container)
-            container = $('#navigation');
-        if (!tabclass)
-            tabclass = 'tabs';
+    that.create = function() {
 
-        IPA.nav.tabs_lists = nls;
-        IPA.nav.nav_container = container;
+        that._create(that.tab_set, that.container, 1);
 
-        IPA.nav.generate_tabs(nls, container, tabclass, 1);
-
-        var tabs = $('.' + tabclass);
+        var tabs = $('.' + that.tabclass);
         tabs.tabs({
             select: function(event, ui) {
                 var panel = $(ui.panel);
@@ -59,20 +59,20 @@ IPA.nav = {
                 var id = parent.attr('id');
                 var state = {};
                 state[id] = ui.index;
-                return IPA.nav.push_state(state);
+                return that.push_state(state);
             }
         });
-    },
+    };
 
-    generate_tabs : function (nls, container, tabclass, depth) {
-        container.addClass(tabclass);
+    that._create = function(tab_set, container, depth) {
+
+        container.addClass(that.tabclass);
         container.addClass('tabs'+depth);
 
-        var ul = $('<ul/>');
-        container.append(ul);
+        var ul = $('<ul/>').appendTo(container);
 
-        for (var i = 0; i < nls.length; ++i) {
-            var tab = nls[i];
+        for (var i=0; i<tab_set.length; i++) {
+            var tab = tab_set[i];
 
             var label = tab.name;
             if (tab.entity) {
@@ -83,10 +83,10 @@ IPA.nav = {
                 label = tab.label;
             }
 
-            var li = IPA.nav.create_tab_li(tab.name, label);
+            var li = that.create_tab_li(tab.name, label);
             ul.append(li);
 
-            var div = IPA.nav.create_tab_div(tab.name);
+            var div = that.create_tab_div(tab.name);
             container.append(div);
 
             if (tab.entity) {
@@ -94,53 +94,103 @@ IPA.nav = {
             }
 
             if (tab.children && depth === 1) {
-                IPA.nav.generate_tabs(tab.children, div, tabclass, depth +1 );
+                that._create(tab.children, div, depth+1 );
             }
         }
-    },
+    };
 
-    create_tab_li : function (id, name) {
+    that.create_tab_li = function(id, name) {
         return $('<li/>').append($('<a/>', {
             href: '#'+id,
             title: id,
             html: name
         }));
-    },
+    };
 
-    create_tab_div : function (id) {
+    that.create_tab_div = function(id) {
         return $('<div/>', {
             id: id
         });
-    },
+    };
 
-    update_tabs : function () {
-        IPA.nav._update_tabs(IPA.nav.tabs_lists, IPA.nav.nav_container,1);
-    },
+    that.update = function() {
+        that._update(that.tab_set, that.container, 1);
+    };
+
+    that._update = function(tab_set, container, depth) {
 
-    _update_tabs : function (nls, container,depth) {
         var id = container.attr('id');
-        var index = IPA.nav.get_state(id);
-        if (!index || index >= nls.length) index = 0;
+        var index = that.get_state(id);
+        if (!index || index >= tab_set.length) index = 0;
 
         container.tabs('select', index);
 
-        var tab = nls[index];
+        var tab = tab_set[index];
         var container2 = $('#' + tab.name);
 
-        if (tab.children   && depth === 1 ) {
-            IPA.nav._update_tabs(tab.children, container2,depth+1);
+        if (tab.children && depth === 1) {
+            that._update(tab.children, container2, depth+1);
 
         } else if (tab.entity) {
             var entity_name = tab.entity;
 
-            var nested_entity = IPA.nav.get_state(entity_name+'-entity');
+            var nested_entity = that.get_state(entity_name+'-entity');
 
-            if (nested_entity){
+            if (nested_entity) {
                 entity_name = nested_entity;
             }
 
             var entity = IPA.get_entity(entity_name);
             entity.setup(container2);
         }
-    }
+    };
+
+    that.get_entity_names = function() {
+        var entities = [];
+        that._get_entity_names(that.tab_set, entities);
+        return entities;
+    };
+
+    that._get_entity_names = function(nodes, entities) {
+        for (var i=0; i<nodes.length; i++) {
+            var node = nodes[i];
+
+            if (node.entity) {
+                entities.push(node.entity);
+            }
+
+            if (node.children) {
+                that._get_entity_names(node.children, entities);
+            }
+        }
+    };
+
+    that.trim = function(entity_names) {
+        for (var i=0; i<entity_names.length; i++) {
+            var entity_name = entity_names[i];
+            that._trim(that.tab_set, entity_name);
+        }
+    };
+
+    that._trim = function(nodes, entity_name) {
+        var i = 0;
+        while (i<nodes.length) {
+            var node = nodes[i];
+
+            if (entity_name == node.entity) {
+                nodes.splice(i, 1);
+
+            } else {
+                if (node.children) {
+                    that._trim(node.children, entity_name);
+                }
+                i++;
+            }
+        }
+    };
+
+    // methods that should be invoked by subclasses
+    that.navigation_update = that.update;
+
+    return that;
 };
diff --git a/install/ui/test/details_tests.js b/install/ui/test/details_tests.js
index c63a0af88c1d7101ab4aba278d9a8c2e33960f82..ab61621626f438b2419db5471f70853157699479 100644
--- a/install/ui/test/details_tests.js
+++ b/install/ui/test/details_tests.js
@@ -42,7 +42,7 @@ module('details', {
             function(){
                 return IPA.entity({name:obj_name});
             };
-        IPA.start_entities();
+        IPA.init_entities();
     },
     teardown: function() {
         details_container.remove();
diff --git a/install/ui/test/entity_tests.js b/install/ui/test/entity_tests.js
index 0adc091fdae25995da04a83ffeeb16a4307cbd0c..565df6939cc21fb1f0343ed669c6338cf790c076 100644
--- a/install/ui/test/entity_tests.js
+++ b/install/ui/test/entity_tests.js
@@ -40,7 +40,7 @@ module('entity',{
                             add_fields:[]}).
                         build();
                 };
-                IPA.start_entities();
+                IPA.init_entities();
             },
             function(xhr, text_status, error_thrown) {
                 ok(false, "ipa_init() failed: "+error_thrown);
diff --git a/install/ui/test/navigation_tests.js b/install/ui/test/navigation_tests.js
index 7eb14ce40d367d1459be8c00af48be4d640b678a..fac38a50f5be1eff077b1aa55da98bcc1b8405da 100644
--- a/install/ui/test/navigation_tests.js
+++ b/install/ui/test/navigation_tests.js
@@ -34,13 +34,7 @@ module('navigation', {
     }
 });
 
-test("Testing IPA.nav.create().", function() {
-
-    var mock_tabs_lists =  [
-        { name:'identity', label:'IDENTITY', children: [
-            {name:'user', entity:'user'},
-            {name:'group', entity:'group'}
-        ]}];
+test("Testing IPA.navigation.create().", function() {
 
     var entity;
 
@@ -63,57 +57,69 @@ test("Testing IPA.nav.create().", function() {
         return that;
     };
 
-    IPA.start_entities();
+    IPA.init_entities();
 
     IPA.metadata = {};
-    var navigation = $('<div id="navigation"/>').appendTo(document.body);
+    var container = $('<div id="navigation"/>').appendTo(document.body);
     var user_mock_called = false;
     var group_mock_called = false;
-    IPA.nav.create(mock_tabs_lists, navigation, 'tabs');
-    IPA.nav.update_tabs();
+
+    var navigation = IPA.navigation({
+        container: container,
+        tab_set: [
+            { name:'identity', label:'IDENTITY', children: [
+                {name:'user', entity:'user'},
+                {name:'group', entity:'group'}
+            ]}
+        ]
+    });
+
+    navigation.create();
+    navigation.update();
+
     ok(user_mock_called, "mock user setup was called");
     ok(!group_mock_called, "mock group setup was not called because the tab is inactive");
-    same( navigation[0].children.length, 2, "Two Child tabs");
-    same( navigation[0].children[1].id, 'identity', "Identity Tab");
-    same( navigation[0].children[1].children[1].id, 'user', "User Tab");
-    same( navigation[0].children[1].children[2].id, 'group', "User Tab");
-    navigation.remove();
+    same( container[0].children.length, 2, "Two Child tabs");
+    same( container[0].children[1].id, 'identity', "Identity Tab");
+    same( container[0].children[1].children[1].id, 'user', "User Tab");
+    same( container[0].children[1].children[2].id, 'group', "User Tab");
+    container.remove();
 });
 
-test("Testing IPA.nav.update_tabs() with valid index.", function() {
+test("Testing IPA.navigation.update() with valid index.", function() {
 
-    var orig_push_state = IPA.nav.push_state;
-    var orig_get_state = IPA.nav.get_state;
-    var orig_remove_state = IPA.nav.remove_state;
+    var container = $('<div id="navigation"/>').appendTo(document.body);
+
+    var navigation = IPA.navigation({
+        container: container,
+        tab_set: [
+            { name:'identity', label:'IDENTITY', children: [
+                {name:'one', label:'One', setup: function (){}},
+                {name:'two', label:'Two', setup: function (){}}
+            ]}
+        ]
+    });
 
     var state = {};
 
-    IPA.nav.push_state = function(params) {
+    navigation.push_state = function(params) {
         $.extend(state, params);
     };
-    IPA.nav.get_state = function(key) {
+
+    navigation.get_state = function(key) {
         return state[key];
     };
-    IPA.nav.remove_state = function(key) {
+
+    navigation.remove_state = function(key) {
         delete state[key];
     };
 
-    var mock_tabs_lists =
-        [
-            { name:'identity', label:'IDENTITY', children: [
-                {name:'one', label:'One', setup: function (){}},
-                {name:'two', label:'Two', setup: function (){}}
-            ]}];
-
-    var navigation = $('<div id="navigation"/>').appendTo(document.body);
-
-    IPA.nav.create(mock_tabs_lists, navigation, 'tabs');
-
-    IPA.nav.push_state({"identity":1});
-    IPA.nav.update_tabs();
+    navigation.create();
+    navigation.push_state({"identity":1});
+    navigation.update();
 
     same(
-        navigation.tabs('option', 'selected'), 0,
+        container.tabs('option', 'selected'), 0,
         "Active tab at level 1"
     );
 
@@ -122,49 +128,45 @@ test("Testing IPA.nav.update_tabs() with valid index.", function() {
         "Active tab at level 2"
     );
 
-    IPA.nav.remove_state("identity");
+    navigation.remove_state("identity");
 
-    navigation.remove();
-
-    IPA.nav.push_state = orig_push_state;
-    IPA.nav.get_state = orig_get_state;
-    IPA.nav.remove_state = orig_remove_state;
+    container.remove();
 });
 
-test("Testing IPA.nav.update_tabs() with out-of-range index.", function() {
+test("Testing IPA.navigation.update() with out-of-range index.", function() {
 
-    var orig_push_state = IPA.nav.push_state;
-    var orig_get_state = IPA.nav.get_state;
-    var orig_remove_state = IPA.nav.remove_state;
+    var container = $('<div id="navigation"/>').appendTo(document.body);
+
+    var navigation = IPA.navigation({
+        container: container,
+        tab_set: [
+            { name:'identity', label:'IDENTITY', children: [
+                {name:'one', label:'One', setup: function (){}},
+                {name:'two', label:'Two', setup: function (){}}
+            ]}
+        ]
+    });
 
     var state = {};
 
-    IPA.nav.push_state = function(params) {
+    navigation.push_state = function(params) {
         $.extend(state, params);
     };
-    IPA.nav.get_state = function(key) {
+
+    navigation.get_state = function(key) {
         return state[key];
     };
-    IPA.nav.remove_state = function(key) {
+
+    navigation.remove_state = function(key) {
         delete state[key];
     };
 
-    var mock_tabs_lists =
-        [
-            { name:'identity', label:'IDENTITY', children: [
-                {name:'one', label:'One', setup: function (){}},
-                {name:'two', label:'Two', setup: function (){}}
-            ]}];
-
-    var navigation = $('<div id="navigation"/>').appendTo(document.body);
-
-    IPA.nav.create(mock_tabs_lists, navigation, 'tabs');
-
-    IPA.nav.push_state({"identity":2});
-    IPA.nav.update_tabs();
+    navigation.create();
+    navigation.push_state({"identity":2});
+    navigation.update();
 
     same(
-        navigation.tabs('option', 'selected'), 0,
+        container.tabs('option', 'selected'), 0,
         "Active tab at level 1"
     );
 
@@ -173,11 +175,7 @@ test("Testing IPA.nav.update_tabs() with out-of-range index.", function() {
         "Active tab at level 2"
     );
 
-    IPA.nav.remove_state("identity");
+    navigation.remove_state("identity");
 
-    navigation.remove();
-
-    IPA.nav.push_state = orig_push_state;
-    IPA.nav.get_state = orig_get_state;
-    IPA.nav.remove_state = orig_remove_state;
+    container.remove();
 });
diff --git a/install/ui/webui.js b/install/ui/webui.js
index bf60fa19bc8d637b92b8448e3ab2b7205e18ab29..077d5e04510464877464ddea3fde86526a33171b 100644
--- a/install/ui/webui.js
+++ b/install/ui/webui.js
@@ -3,6 +3,7 @@
 
 /*  Authors:
  *    Pavel Zuna <pz...@redhat.com>
+ *    Endi S. Dewata <edew...@redhat.com>
  *
  * Copyright (C) 2010 Red Hat
  * see file 'COPYING' for use and warranty information
@@ -25,58 +26,79 @@
 
 /* tabs definition for IPA webUI */
 
+IPA.admin_navigation = function(spec) {
 
-IPA.admin_tab_set = function () {
-    var tabset = [
-        {name:'identity', label: IPA.messages.tabs.identity,  children:[
-            {name:'user', entity:'user'},
-            {name:'group', entity:'group'},
-            {name:'host', entity:'host'},
-            {name:'hostgroup', entity:'hostgroup'},
-            {name:'netgroup', entity:'netgroup'},
-            {name:'service', entity:'service'}
+    spec = spec || {};
+
+    var that = IPA.navigation(spec);
+
+    that.tab_set = [
+        {name: 'identity', label: IPA.messages.tabs.identity, children: [
+            {name: 'user', entity: 'user'},
+            {name: 'group', entity: 'group'},
+            {name: 'host', entity: 'host'},
+            {name: 'hostgroup', entity: 'hostgroup'},
+            {name: 'netgroup', entity: 'netgroup'},
+            {name: 'service', entity: 'service'}
         ]},
-        {name:'policy', label: IPA.messages.tabs.policy, children:[
-            {name:'hbacrule', label: IPA.messages.tabs.hbac ,
-             entity:'hbacrule', children:[
-                {name:'hbacsvc', entity:'hbacsvc'},
-                {name:'hbacsvcgroup', entity:'hbacsvcgroup'}
+        {name: 'policy', label: IPA.messages.tabs.policy, children: [
+            {name: 'dnszone', entity: 'dnszone'},
+            {name: 'hbacrule', label: IPA.messages.tabs.hbac, entity: 'hbacrule', children: [
+                {name: 'hbacsvc', entity: 'hbacsvc'},
+                {name: 'hbacsvcgroup', entity: 'hbacsvcgroup'}
             ]},
-            {name:'sudorule', label: IPA.messages.tabs.sudo,
-             entity:'sudorule',children:[
-                {name:'sudocmd', entity:'sudocmd'},
-                {name:'sudocmdgroup', entity:'sudocmdgroup'}
+            {name: 'sudorule', label: IPA.messages.tabs.sudo, entity:'sudorule', children: [
+                {name: 'sudocmd', entity: 'sudocmd'},
+                {name: 'sudocmdgroup', entity: 'sudocmdgroup'}
             ]},
-//            {name:'automount', entity:'automountlocation'},
-            {name:'pwpolicy', entity:'pwpolicy'},
-            {name:'krbtpolicy', entity:'krbtpolicy'}
+//            {name: 'automount', entity: 'automountlocation'},
+            {name: 'pwpolicy', entity: 'pwpolicy'},
+            {name: 'krbtpolicy', entity: 'krbtpolicy'}
         ]},
-        {name:'ipaserver', label: IPA.messages.tabs.ipaserver, children: [
-            {name:'role',entity:'role', label: IPA.messages.tabs.role,
-             children:[
-                {name:'privilege',entity:'privilege' },
-                {name:'permission', entity:'permission'}
+        {name: 'ipaserver', label: IPA.messages.tabs.ipaserver, children: [
+            {name: 'role', entity: 'role', label: IPA.messages.tabs.role, children: [
+                {name: 'privilege',entity: 'privilege' },
+                {name: 'permission', entity: 'permission'}
             ]},
-            {name:'selfservice'  ,entity:'selfservice'},
-            {name:'delegation'  ,entity:'delegation'},
-            {name:'entitle', entity:'entitle'},
-            {name:'config', entity:'config'}
-        ]}];
-
-    if (IPA.dns_enabled){
-        tabset[1].children.unshift(
-            {name:'dnszone', entity:'dnszone'}
-        );
-    }
-
-    return tabset;
-};
+            {name: 'selfservice', entity: 'selfservice'},
+            {name: 'delegation', entity: 'delegation'},
+            {name: 'entitle', entity: 'entitle'},
+            {name: 'config', entity: 'config'}
+        ]}
+    ];
 
-IPA.self_serv_tab_set = function(){
-    return [ { name:'identity',
-               children: [ {name:'user', entity:'user'}]}];
+    return that;
 };
 
+IPA.self_serv_navigation = function(spec) {
+
+    spec = spec || {};
+
+    var that = IPA.navigation(spec);
+
+    that.tab_set = [
+        {name:'identity', children: [
+            {name:'user', entity:'user'}]}
+    ];
+
+    that.update = function() {
+        var pkey = $.bbq.getState('user-pkey');
+        var facet = $.bbq.getState('user-facet');
+
+        if (pkey && facet) {
+            that.navigation_update();
+
+        } else {
+            var state = {
+                'user-pkey': pkey || IPA.whoami_pkey,
+                'user-facet': facet || 'details'
+            };
+            $.bbq.pushState(state);
+        }
+    };
+
+    return that;
+};
 
 IPA.tab_state = function(entity_name){
 
@@ -120,18 +142,29 @@ $(function() {
 
     /* main loop (hashchange event handler) */
     function window_hashchange(evt){
-        IPA.nav.update_tabs();
+        IPA.nav.update();
     }
 
 
-    function should_show_all_ui(){
+    function create_navigation() {
         var whoami = IPA.whoami;
+        var factory;
 
         if (whoami.hasOwnProperty('memberof_group') &&
-            whoami.memberof_group.indexOf('admins')  !== -1) return true;
+            whoami.memberof_group.indexOf('admins')  !== -1) {
+            factory = IPA.admin_navigation;
 
-        return whoami.hasOwnProperty('memberof_rolegroup') &&
-            whoami.memberof_rolegroup.length > 0;
+        } else if (whoami.hasOwnProperty('memberof_rolegroup') &&
+            whoami.memberof_rolegroup.length > 0) {
+            factory = IPA.admin_navigation;
+
+        } else {
+            factory = IPA.self_serv_navigation;
+        }
+
+        return factory({
+            container: $('#navigation')
+        });
     }
 
 
@@ -139,39 +172,36 @@ $(function() {
         $(window).bind('hashchange', window_hashchange);
 
         var whoami = IPA.whoami;
-        IPA.whoami_pkey=whoami.uid[0];
+        IPA.whoami_pkey = whoami.uid[0];
         $('#loggedinas').find('strong').text(whoami.cn[0]);
         $('#loggedinas a').fragment(
             {'user-facet':'details', 'user-pkey':IPA.whoami_pkey},2);
 
-        IPA.start_entities();
+        var navigation = create_navigation();
 
-        var navigation = $('#navigation');
+        IPA.nav = navigation;
+        IPA.tab_set = navigation.tab_set;
 
-        if (should_show_all_ui()){
-            IPA.tab_set = IPA.admin_tab_set();
-            IPA.nav.create(IPA.tab_set, navigation, 'tabs');
-            IPA.nav.update_tabs();
+        var entity_names = navigation.get_entity_names();
 
-        } else {
-            IPA.tab_set = IPA.self_serv_tab_set();
-            IPA.nav.create(IPA.tab_set, navigation, 'tabs');
-
-            var pkey = $.bbq.getState('user-pkey');
-            var facet = $.bbq.getState('user-facet');
-
-            if (pkey && facet) {
-                IPA.nav.update_tabs();
+        var entities_to_create = [];
+        var entities_to_remove = [];
 
+        for (var i=0; i<entity_names.length; i++) {
+            var entity_name = entity_names[i];
+            if (!IPA.metadata.objects[entity_name] ||
+                entity_name == 'dnszone' && !IPA.dns_enabled) {
+                entities_to_remove.push(entity_name);
             } else {
-                var state = {
-                    'user-pkey': pkey || IPA.whoami_pkey,
-                    'user-facet': facet || 'details'
-                };
-                $.bbq.pushState(state);
+                entities_to_create.push(entity_name);
             }
         }
 
+        IPA.init_entities(entities_to_create);
+
+        navigation.trim(entities_to_remove);
+        navigation.create();
+        navigation.update();
 
         $('#login_header').html(IPA.messages.login.header);
     }
-- 
1.7.4

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to