diff options
author | Endi S. Dewata <edewata@redhat.com> | 2011-04-20 19:11:10 -0500 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2011-05-05 12:14:25 -0500 |
commit | 238da3dffd99f3ea91318eb2dd0fe77860aff345 (patch) | |
tree | f34373c69926b52264f6adc8597044a1e6c9f719 /install/ui/webui.js | |
parent | e64c1995d43ae6b42c81ac08e79d6d016344b39c (diff) | |
download | freeipa-238da3dffd99f3ea91318eb2dd0fe77860aff345.tar.gz freeipa-238da3dffd99f3ea91318eb2dd0fe77860aff345.tar.xz freeipa-238da3dffd99f3ea91318eb2dd0fe77860aff345.zip |
Refactored navigation.
The singular object IPA.nav has been converted into an IPA.navigation
class. The admin and self-service navigation tabs have been converted
into subclasses of IPA.navigation and will be instantiated according
to user authorization.
Diffstat (limited to 'install/ui/webui.js')
-rw-r--r-- | install/ui/webui.js | 173 |
1 files changed, 90 insertions, 83 deletions
diff --git a/install/ui/webui.js b/install/ui/webui.js index 02fe918a0..84a4f3331 100644 --- a/install/ui/webui.js +++ b/install/ui/webui.js @@ -3,6 +3,7 @@ /* Authors: * Pavel Zuna <pzuna@redhat.com> + * Endi S. Dewata <edewata@redhat.com> * * Copyright (C) 2010 Red Hat * see file 'COPYING' for use and warranty information @@ -25,82 +26,111 @@ /* 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:[ - {entity:'user'}, - {entity:'group'}, - {entity:'host'}, - {entity:'hostgroup'}, - {entity:'netgroup'}, - {entity:'service'} + spec = spec || {}; + + spec.tabs = [ + {name: 'identity', label: IPA.messages.tabs.identity, children: [ + {entity: 'user'}, + {entity: 'group'}, + {entity: 'host'}, + {entity: 'hostgroup'}, + {entity: 'netgroup'}, + {entity: 'service'} ]}, - {name:'policy', label: IPA.messages.tabs.policy, children:[ - {entity:'dnszone'}, - {name:'hbac', label: IPA.messages.tabs.hbac , - children:[ - {entity:'hbacrule'}, - {entity:'hbacsvc'}, - {entity:'hbacsvcgroup'} + {name: 'policy', label: IPA.messages.tabs.policy, children: [ + {entity: 'dnszone'}, + {name: 'hbac', label: IPA.messages.tabs.hbac, children: [ + {entity: 'hbacrule'}, + {entity: 'hbacsvc'}, + {entity: 'hbacsvcgroup'} ]}, - {name:'sudo', label: IPA.messages.tabs.sudo, - children:[ - {entity:'sudorule'}, - {entity:'sudocmd'}, - {entity:'sudocmdgroup'} + {name: 'sudo', label: IPA.messages.tabs.sudo, children: [ + {entity: 'sudorule'}, + {entity: 'sudocmd'}, + {entity: 'sudocmdgroup'} ]}, -// {entity:'automountlocation'}, - {entity:'pwpolicy'}, - {entity:'krbtpolicy'} +// {entity: 'automountlocation'}, + {entity: 'pwpolicy'}, + {entity: 'krbtpolicy'} ]}, - {name:'ipaserver', label: IPA.messages.tabs.ipaserver, children: [ - {name:'rolebased', label: IPA.messages.tabs.role, - children:[ - {entity:'role'}, - {entity:'privilege'}, - {entity:'permission'} + {name: 'ipaserver', label: IPA.messages.tabs.ipaserver, children: [ + {name: 'rolebased', label: IPA.messages.tabs.role, children: [ + {entity: 'role'}, + {entity: 'privilege'}, + {entity: 'permission'} ]}, - {entity:'selfservice'}, - {entity:'delegation'}, - {entity:'entitle'}, - {entity:'config'} + {entity: 'selfservice'}, + {entity: 'delegation'}, + {entity: 'entitle'}, + {entity: 'config'} ]}]; - return tabset; -}; + var that = IPA.navigation(spec); -IPA.self_serv_tab_set = function(){ - return [ { name:'identity', - children: - [ - {entity:'user'}, - {entity:'group'} - ] - } - ]; + return that; }; +IPA.self_serv_navigation = function(spec) { + + spec = spec || {}; + + spec.tabs = [ + {name: 'identity', children: [ + {entity: 'user'}, + {entity: 'group'} + ]}]; + + var that = IPA.navigation(spec); + + 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; +}; /* main (document onready event handler) */ $(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; + + } else if (whoami.hasOwnProperty('memberof_rolegroup') && + whoami.memberof_rolegroup.length > 0) { + factory = IPA.admin_navigation; + + } else { + factory = IPA.self_serv_navigation; + } - return whoami.hasOwnProperty('memberof_rolegroup') && - whoami.memberof_rolegroup.length > 0; + return factory({ + container: $('#navigation') + }); } @@ -108,49 +138,26 @@ $(function() { $(window).bind('hashchange', window_hashchange); var whoami = IPA.whoami; - IPA.whoami_pkey=whoami.uid[0]; - $('#loggedinas').find('strong').text(whoami.cn[0]); + IPA.whoami_pkey = whoami.uid[0]; + $('#loggedinas strong').text(whoami.cn[0]); $('#loggedinas a').fragment( - {'user-facet':'details', 'user-pkey':IPA.whoami_pkey},2); + {'user-facet': 'details', 'user-pkey': IPA.whoami_pkey}, 2); IPA.start_entities(); - var navigation = $('#navigation'); - - if (should_show_all_ui()){ - IPA.tab_set = IPA.admin_tab_set(); - IPA.nav.create(IPA.tab_set, navigation, 'tabs'); - IPA.nav.update_tabs(); - - } 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(); - - } else { - var state = { - 'user-pkey': pkey || IPA.whoami_pkey, - 'user-facet': facet || 'details' - }; - $.bbq.pushState(state); - } - } - + IPA.nav = create_navigation(); + IPA.nav.create(); + IPA.nav.update(); $('#login_header').html(IPA.messages.login.header); } function init_on_error(xhr, text_status, error_thrown) { - var navigation = $('#navigation').empty(); - navigation.append('<p>Error: '+error_thrown.name+'</p>'); - navigation.append('<p>'+error_thrown.title+'</p>'); - navigation.append('<p>'+error_thrown.message+'</p>'); + var container = $('#navigation').empty(); + container.append('<p>Error: '+error_thrown.name+'</p>'); + container.append('<p>'+error_thrown.title+'</p>'); + container.append('<p>'+error_thrown.message+'</p>'); } IPA.init(null, null, init_on_win, init_on_error); |