/*jsl:import ipa.js */ /*jsl:import navigation.js */ /* Authors: * Pavel Zuna * Endi S. Dewata * Adam Young * * 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 . */ /* 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.init = spec.init || init; that.create = spec.create || create; that.setup = spec.setup || setup; that.load = spec.load || load; that.dialogs = []; that.dialogs_by_name = {}; that.__defineGetter__('entity_name', function() { return that._entity_name; }); that.__defineSetter__('entity_name', function(entity_name) { that._entity_name = entity_name; }); that.create_action_panel = IPA.facet_create_action_panel; 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; }; function init() { for (var i=0; i', { "class" : other_facet.display_class, title: other_facet.name, text: label, click: function(entity_name, other_facet_name) { return function() { if($(this).hasClass('entity-facet-disabled')){ return false; } var this_pkey = $('input[id=pkey]', action_panel).val(); IPA.switch_and_show_page( entity_name, other_facet_name, this_pkey); return false; }; }(entity_name, other_facet_name) }); return li; } var that = this; var entity_name = that.entity_name; var panel_title = IPA.metadata.objects[entity_name].label; var nested_tabs = IPA.nested_tabs(entity_name); if (nested_tabs.length > 1){ panel_title = IPA.get_nested_tab_label(entity_name); } var action_panel = $('
', { "class": "action-panel", html: $('

',{ text: panel_title }) }).appendTo(container); /*Note, for debugging purposes, it is useful to set var pkey_type = 'text';*/ var pkey_type = 'hidden'; $('', { 'type': pkey_type, id:'pkey', name:'pkey' }).appendTo(action_panel); var ul = $('
    ', {'class': 'action'}).appendTo(action_panel); var entity = IPA.get_entity(entity_name); var facet_name = IPA.current_facet(entity); var other_facet = entity.facets[0]; var other_facet_name = other_facet.name; var main_facet = build_link(other_facet,other_facet.label); for (var nested_index = 0 ; nested_index < nested_tabs.length; nested_index += 1){ if (nested_tabs[nested_index] === entity_name){ /*assume for now that entities with only a single facet do not have search*/ if (entity.facets.length > 0 ){ if ( entity.facets[0].name === IPA.current_facet( entity)){ if (nested_tabs.length > 1 ){ main_facet.html(IPA.selected_icon + IPA.metadata.objects[nested_tabs[nested_index]].label); main_facet.addClass('entity-facet-selected'); main_facet.appendTo(ul); } ul.append($('
  • ')); } else { main_facet.html( $('',{ "class":"input_link" }). append(IPA.back_icon + ' '+IPA.messages.buttons.back_to_list+' ')); main_facet.addClass('back-to-search'); main_facet.appendTo(ul); } ul.append($('

  • ')); } var facet_groups = {}; var li; for (var i=1; i', { 'class': 'entity-facet entity-facet-relation-label', 'text': other_facet.facet_group, 'title': other_facet.facet_group }); ul.append(li); facet_groups[facet_group] = li; } li = facet_groups[facet_group]; var link = build_link(other_facet, other_facet.label); link.addClass('facet-group-member'); li.after(link ); /* If we are on the current facet, we make the text black, non-clickable, add an icon and make sure the action controls are positioned underneath it. */ if ( other_facet.name === IPA.current_facet( entity)){ var text = link.text(); link.text(''); link.append($('
      '). append($('
    • ',{ 'class': 'association-facet-selected', html: IPA.selected_icon + text })). append($('
    • ',{ html:$('',{ 'class':"action-controls" }) }))); } facet_groups[facet_group] = li.next(); } else { var innerlist = $('
        ').appendTo(ul); var facet_link = build_link(other_facet, other_facet.label); innerlist.append(facet_link); if ( other_facet.name === IPA.current_facet( entity)){ text = facet_link.text(); facet_link.html(IPA.selected_icon + text); facet_link.addClass('entity-facet-selected'); innerlist.append($('
      • ')); } } } }else{ $('
      • ', { title: nested_tabs[nested_index], text: IPA.metadata.objects[nested_tabs[nested_index]].label, "class": "search-facet", click: function() { var state = {}; state[nested_tabs[0]+'-entity'] = this.title; IPA.nav.push_state(state); return false; } }).appendTo(ul); } } /*When we land on the search page, disable all facets that require a pkey until one is selected*/ if (facet_name === 'search'){ $('.entity-facet', action_panel).addClass('entity-facet-disabled'); } return action_panel; };