From 238da3dffd99f3ea91318eb2dd0fe77860aff345 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Wed, 20 Apr 2011 19:11:10 -0500 Subject: 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. --- install/ui/entity.js | 15 ++-- install/ui/ipa.js | 42 ++++----- install/ui/navigation.js | 112 ++++++++++++----------- install/ui/test/navigation_tests.js | 136 ++++++++++++++-------------- install/ui/webui.js | 173 +++++++++++++++++++----------------- 5 files changed, 239 insertions(+), 239 deletions(-) diff --git a/install/ui/entity.js b/install/ui/entity.js index 9a9f05f23..e6e63cd32 100644 --- a/install/ui/entity.js +++ b/install/ui/entity.js @@ -333,7 +333,7 @@ IPA.get_nested_tab_label = function(entity_name){ any nested tabs underneath it or its parent tab and the others nested at the same level*/ -IPA.nested_tabs = function(entity_name){ +IPA.nested_tabs = function(entity_name) { var siblings = []; var i; @@ -349,14 +349,14 @@ IPA.nested_tabs = function(entity_name){ } - if (!IPA.tab_set) { + if (!IPA.nav.tabs) { siblings.push(entity_name); return siblings; } - for (var top_i = 0; top_i < IPA.tab_set.length; top_i += 1){ - var top_tab = IPA.tab_set[top_i]; - for (sub_i = 0; sub_i < top_tab.children.length; sub_i += 1){ + for (var top_i = 0; top_i < IPA.nav.tabs.length; top_i++) { + var top_tab = IPA.nav.tabs[top_i]; + for (sub_i = 0; sub_i < top_tab.children.length; sub_i++) { sub_tab = top_tab.children[sub_i]; nested_entities = sub_tab.children; if (sub_tab.name === entity_name){ @@ -379,6 +379,7 @@ IPA.nested_tabs = function(entity_name){ } } } + return siblings; }; @@ -454,7 +455,7 @@ IPA.entity_header = function(spec){ return false; } - IPA.switch_and_show_page(entity.name, 'search'); + IPA.show_page(entity.name, 'search'); $(that.facet_tabs).find('a').removeClass('selected'); return false; @@ -482,7 +483,7 @@ IPA.entity_header = function(spec){ return false; } var this_pkey = that.pkey_field.val(); - IPA.switch_and_show_page( + IPA.show_page( entity_name, other_facet_name, this_pkey); $(that.facet_tabs).find('a').removeClass('selected'); diff --git a/install/ui/ipa.js b/install/ui/ipa.js index f551fc64b..db60326e4 100644 --- a/install/ui/ipa.js +++ b/install/ui/ipa.js @@ -134,22 +134,22 @@ 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(){ + that.start_entities = function() { var factory; - var name ; - for (name in that.entity_factories){ + var name; + for (name in that.entity_factories) { factory = that.entity_factories[name]; - try{ + try { var entity = factory(); - add_entity(entity); + that.add_entity(entity); entity.init(); - }catch(e){ - /*exceptions thrown by builder just mean that entities + } catch (e) { + /*exceptions thrown by builder just mean that entities are not to be registered. */ } } @@ -185,31 +185,19 @@ var IPA = ( function () { return true; }; - that.show_page = function (entity_name, facet_name) { - if (!IPA.test_dirty()){ - return false; + that.show_page = function(entity_name, facet_name, pkey) { + if (!IPA.test_dirty()) { + return; } var state = {}; - 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) { + state[entity_name + '-pkey'] = pkey; } - if (!pkey){ - that.show_page(this_entity, facet_name); - return false; - } - var state = {}; - state[this_entity+'-pkey'] = pkey; - state[this_entity + '-facet'] = facet_name; + state[entity_name + '-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 786a5a972..3043b7c43 100644 --- a/install/ui/navigation.js +++ b/install/ui/navigation.js @@ -2,6 +2,7 @@ /* Authors: * Pavel Zuna + * Endi S. Dewata * * Copyright (C) 2010 Red Hat * see file 'COPYING' for use and warranty information @@ -20,39 +21,38 @@ * along with this program. If not, see . */ -IPA.nav = { - tabs_lists : {}, - nav_container : {}, +IPA.navigation = function(spec) { - push_state : function (params) { - if (!IPA.test_dirty()){ + spec = spec || {}; + + var that = {}; + + that.container = spec.container; + that.tab_class = spec.tab_class || 'tabs'; + + that.tabs = spec.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'; - } - IPA.nav.tabs_lists = nls; - IPA.nav.nav_container = container; + that.create = function() { - IPA.nav.generate_tabs(nls, container, tabclass, 1); + that._create(that.tabs, that.container, 1); - var tabs = $('.' + tabclass); + var tabs = $('.' + that.tab_class); tabs.tabs({ select: function(event, ui) { var panel = $(ui.panel); @@ -60,21 +60,22 @@ IPA.nav = { var id = parent.attr('id'); var state = {}; state[id] = ui.index; - return IPA.nav.push_state(state); + return that.push_state(state); } }); - }, + }; + + that._create = function(tabs, container, depth) { - generate_tabs : function (nls, container, tabclass, depth) { - container.addClass(tabclass); + container.addClass(that.tab_class); container.addClass('tabs'+depth); - var ul = $('