From 5eb9f088f2c5c902a55aefdf9dd8b2a95e060837 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Thu, 28 Apr 2011 17:38:21 -0500 Subject: Use entity names for tab state. Previously the tab state is represented using numeric index such as navigation=0&identity=1 which is not very user friendly. Now the code has been modified to use entity names such as navigation=identity&identity=group. --- install/ui/navigation.js | 150 ++++++++++++++++++++++++++--------------------- 1 file changed, 84 insertions(+), 66 deletions(-) (limited to 'install/ui/navigation.js') diff --git a/install/ui/navigation.js b/install/ui/navigation.js index 3043b7c43..9b8f649df 100644 --- a/install/ui/navigation.js +++ b/install/ui/navigation.js @@ -30,7 +30,53 @@ IPA.navigation = function(spec) { that.container = spec.container; that.tab_class = spec.tab_class || 'tabs'; - that.tabs = spec.tabs || []; + that.tabs = []; + that.tabs_by_name = {}; + + that.set_tabs = function(tabs) { + that.tabs = tabs; + that.tabs_by_name = {}; + + for (var i=0; i').append($('', { + href: '#'+tab.name, + title: tab.name, + html: label + })).appendTo(ul); - var div = that.create_tab_div(tab.name); - container.append(div); + tab.content = $('
', { + id: tab.name + }).appendTo(container); if (tab.entity) { - div.addClass('entity-container'); + tab.content.addClass('entity-container'); } if (tab.children && tab.children.length) { - that._create(tab.children, div, depth+1); + that._create(tab.children, tab.content, depth+1); } } }; - that.create_tab_li = function(id, name) { - return $('
  • ').append($('', { - href: '#'+id, - title: id, - html: name - })); - }; - - that.create_tab_div = function(id) { - return $('
    ', { - id: id - }); - }; - that.update = function() { that._update(that.tabs, that.container, 1); }; that._update = function(tabs, container, depth) { - var id = container.attr('id'); - var index = that.get_state(id); - if (!index || index >= tabs.length) index = 0; + var parent_name = container.attr('id'); + var tab_name = that.get_state(parent_name); + + var index = 0; + while (index < tabs.length && tabs[index].name != tab_name) index++; + if (index >= tabs.length) index = 0; container.tabs('select', index); var tab = tabs[index]; - var container2 = $('#' + tab.name); if (tab.children && tab.children.length) { - that._update(tab.children, container2, depth+1); + that._update(tab.children, tab.content, depth+1); } else if (tab.entity) { - tab.entity.setup(container2); + tab.entity.setup(tab.content); } }; // methods that should be invoked by subclasses that.navigation_update = that.update; - return that; -}; + that.set_tabs(spec.tabs); -IPA.tab_state = function(entity_name,tab){ - var state; - var i; - var children; - var tab_name; - - if (!tab){ - children = IPA.nav.tabs; - tab_name = 'navigation'; - }else if (tab.children){ - children = tab.children; - tab_name = tab.name; - }else if (tab.entity){ - if (tab.entity.name === entity_name){ - state = {}; - state[entity_name] = 0; - } - return state; - } - - for (i = 0; i < children.length; i +=1){ - state = IPA.tab_state(entity_name,children[i]); - if (state){ - state[tab_name] = i; - return state; - } - } - return null; + return that; }; -- cgit