/*jsl:import ipa.js */ /*jsl:import navigation.js */ /* Authors: * Pavel Zuna * Endi S. Dewata * Adam Young * * Copyright (C) 2010-2011 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 . */ /* REQUIRES: ipa.js, details.js, search.js, add.js */ IPA.facet = function (spec) { spec = spec || {}; var that = {}; that.display_class = spec.display_class || 'entity-facet'; that.name = spec.name; that.label = spec.label; that._entity_name = spec.entity_name; that.dialogs = []; that.dialogs_by_name = {}; that.facet_group = spec.facet_group; that.__defineGetter__('entity_name', function() { return that._entity_name; }); that.__defineSetter__('entity_name', function(entity_name) { that._entity_name = entity_name; }); that.get_dialog = function(name) { return that.dialogs_by_name[name]; }; that.dialog = function(dialog) { that.dialogs.push(dialog); that.dialogs_by_name[dialog.name] = dialog; return that; }; that.init = function() { for (var i=0; i', { 'class': 'facet-header' }).appendTo(container); that.create_header(that.header); that.content = $('
', { 'class': 'facet-content' }).appendTo(container); that.create_content(that.content); }; that.create_header = function(container) { that.title = $('
', { 'class': 'facet-title' }).appendTo(container); $('

').append(IPA.create_network_spinner()).appendTo(that.title); that.set_title(container, that.label); that.controls = $('
', { 'class': 'facet-controls' }).appendTo(container); }; that.create_content = function(container) { }; that.set_title = function(container, title) { var element = $('h1', that.title); element.html(title); }; that.setup = function(container) { that.container = container; }; that.show = function() { that.container.css('display', 'inline'); }; that.hide = function() { that.container.css('display', 'none'); }; that.load = function() { }; that.is_dirty = function (){ return false; }; that.get_content = function() { return $('.content', that.container); }; // methods that should be invoked by subclasses that.facet_init = that.init; that.facet_create_header = that.create_header; that.facet_create_content = that.create_content; that.facet_setup = that.setup; that.facet_show = that.show; that.facet_hide = that.hide; return that; }; IPA.table_facet = function(spec) { spec = spec || {}; var that = IPA.facet(spec); that.columns = []; that.columns_by_name = {}; that.__defineGetter__('entity_name', function() { return that._entity_name; }); that.__defineSetter__('entity_name', function(entity_name) { that._entity_name = entity_name; for (var i=0; i', { 'class': 'entity-header' }).appendTo(container); that.header.create(entity_header); that.content = $('
', { 'class': 'entity-content' }).appendTo(container); }; that.setup = function(container) { var prev_facet = that.facet; IPA.current_entity = that; var facet_name = IPA.current_facet(that); that.facet = that.get_facet(facet_name); if (!that.facet) return; if (IPA.entity_name == that.name) { if (that.facet_name == that.facet.name) { if (that.facet.new_key && (!that.facet.new_key())) return; } else { that.facet_name = that.facet.name; } } else { IPA.entity_name = that.name; } if (prev_facet) { prev_facet.hide(); } var facet_container = $('.facet[name="'+that.facet.name+'"]', that.content); if (!facet_container.length) { facet_container = $('
', { name: that.facet.name, 'class': 'facet' }).appendTo(that.content); that.facet.create(facet_container); that.facet.setup(facet_container); } that.facet.show(); that.header.select_tab(); that.facet.refresh(); }; that.entity_init = that.init; return that; }; IPA.current_facet = function (entity){ var facet_name = $.bbq.getState(entity.name + '-facet', true); if (!facet_name && entity.facets.length) { facet_name = entity.facets[0].name; } return facet_name; }; IPA.nested_tab_labels = {}; IPA.get_nested_tab_label = function(entity_name){ if (!IPA.nested_tab_labels[entity_name]){ IPA.nested_tab_labels[entity_name] = "LABEL"; } return IPA.nested_tab_labels[entity_name]; }; /*Returns the entity requested, as well as: any nested tabs underneath it or its parent tab and the others nested at the same level*/ IPA.nested_tabs = function(entity_name) { var siblings = []; var i; var i2; var nested_entities; var sub_i; var sub_tab; var key = entity_name; function push_sibling(sibling){ siblings.push (sibling); IPA.nested_tab_labels[key] = sub_tab; } if (!IPA.nav.tabs) { siblings.push(entity_name); return siblings; } 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){ push_sibling(entity_name); } if (sub_tab.children){ for (i = 0; i < nested_entities.length; i += 1){ if (sub_tab.name === entity_name){ push_sibling(nested_entities[i].name); }else{ if (nested_entities[i].name === entity_name){ push_sibling(sub_tab.name); for (i2 = 0; i2 < nested_entities.length; i2 += 1){ key = nested_entities[i].name; push_sibling(nested_entities[i2].name); } } } } } } } return siblings; }; IPA.selected_icon = ''; IPA.back_icon = ''; IPA.entity_header = function(spec) { spec = spec || {}; var that = {}; that.entity = spec.entity; that.select_tab = function() { $(that.facet_tabs).find('a').removeClass('selected'); var facet_name = $.bbq.getState(that.entity.name + '-facet', true); if (!facet_name || facet_name === 'default') { that.facet_tabs.find('a:first').addClass('selected'); } else { that.facet_tabs.find('a#' + facet_name ).addClass('selected'); } }; that.set_pkey = function(value) { if (value) { var span = $('.entity-pkey', that.pkey); span.text(value); that.pkey.css('display', 'inline'); } else { that.pkey.css('display', 'none'); } }; that.facet_link = function(container, other_facet) { var li = $('
  • ', { title: other_facet.name, click: function() { if (li.hasClass('entity-facet-disabled')) { return false; } var pkey = $.bbq.getState(that.entity.name+'-pkey', true); IPA.nav.show_page(that.entity.name, other_facet.name, pkey); $('a', that.facet_tabs).removeClass('selected'); $('a', li).addClass('selected'); return false; } }).appendTo(container); $('', { text: other_facet.label, id: other_facet.name }).appendTo(li); }; that.facet_group = function(container, label) { var facets = that.entity.facet_groups[label]; if (facets) { that.tab_section(container, label, facets); } }; that.tab_section = function(container, label, facets) { var section = $('', { 'class': 'facet-tab-group' }).appendTo(container); $('