/*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.name = spec.name; that.container = spec.container; that.content = spec.content; that.tab_class = spec.tab_class || 'tabs'; that.max_depth = spec.max_depth || 3; that.tabs = []; that.tabs_by_name = {}; that.set_tabs = function(tabs) { that.tabs = tabs; that.tabs_by_name = {}; for (var i=0; i -1)){ url_state[key2] = state[key2]; } } /* Trace back up the nested entities for their pkeys as well */ var current_entity = IPA.get_entity(entity); while(current_entity !== null){ var key_names = current_entity.get_key_names(); for (var j = 0; j < key_names.length; j+= 1){ var key_name = key_names[j]; if (state[key_name]){ url_state[key_name] = state[key_name]; } } current_entity = current_entity.containing_entity; } $.bbq.pushState(url_state,2); return true; }; that.get_state = function(key) { var url_state = $.bbq.getState(key); if (!url_state){ url_state = state[key]; } return url_state; }; that.remove_state = function(key) { delete state[key]; $.bbq.removeState(key); }; that.show_page = function(entity_name, facet_name, pkey) { var state = that.get_path_state(entity_name); if (facet_name) { state[entity_name + '-facet'] = facet_name; } if (pkey) { state[entity_name + '-pkey'] = pkey; } that.push_state(state); }; /*like show page, but works for nested entities */ that.show_entity_page = function(entity, facet_name, pkeys) { var state = that.get_path_state(entity.name); if (facet_name) { state[entity.name + '-facet'] = facet_name; } if (pkeys) { var current_entity = entity; while (current_entity){ state[current_entity.name + '-pkey'] = pkeys.pop(); current_entity = current_entity.containing_entity; } } that.push_state(state); }; that.create = function() { var container = $('
', { name: 'navigation' }).appendTo(that.container); that._create(that.tabs, container, 1); var tabs = $('.' + that.tab_class, that.container); tabs.tabs({ select: function(event, ui) { var panel = $(ui.panel); var name = panel.attr('name'); return that.show_page(name); } }); }; that._create = function(tabs, container, depth) { container.addClass(that.tab_class); container.addClass('tabs'+depth); var ul = $('