/*jsl:import ipa.js */ /* Authors: * Pavel Zuna * Endi S. Dewata * * Copyright (C) 2010 Red Hat * see file 'COPYING' for use and warranty information * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ IPA.navigation = function(spec) { spec = spec || {}; var that = {}; that.container = spec.container; that.content = spec.content; that.tab_class = spec.tab_class || 'tabs'; that.tabs = []; that.tabs_by_name = {}; that.set_tabs = function(tabs) { that.tabs = tabs; that.tabs_by_name = {}; for (var i=0; i').appendTo(container); for (var i=0; i').append($('', { href: '#'+tab_id, title: tab.label, html: tab.label })).appendTo(ul); tab.container = $('
', { id: tab_id, name: tab.name }).appendTo(container); if (tab.children && tab.children.length) { that._create(tab.children, tab.container, depth+1); } } }; that.update = function() { $('.entity', that.content).css('display', 'none'); that._update(that.tabs, that.container, 1); }; that._update = function(tabs, container, depth) { var parent_name = container.attr('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]; if (tab.children && tab.children.length) { that._update(tab.children, tab.container, depth+1); } else if (tab.entity) { var entity_container = $('.entity[name="'+tab.entity.name+'"]', that.content); if (!entity_container.length) { tab.content = $('
', { name: tab.name, title: tab.label, 'class': 'entity' }).appendTo(that.content); tab.entity.create(tab.content); } entity_container.css('display', 'inline'); tab.entity.setup(tab.content); } }; // methods that should be invoked by subclasses that.navigation_update = that.update; that.set_tabs(spec.tabs); return that; };