/*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.init = spec.init || init; that.create_content = spec.create_content || create_content; that.setup = spec.setup || setup; that.load = spec.load || load; 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; }; function init() { that.entity = IPA.get_entity(that.entity_name); for (var i=0; i"); return that.pkey_field; } function select_tab(){ $(that.facet_tabs).find('a').removeClass('selected'); var facet_name = $.bbq.getState(entity.name + '-facet', true); if (!facet_name) return; if (facet_name === 'default'){ that.facet_tabs.find('a:first').addClass('selected'); }else{ that.facet_tabs.find('a#' + facet_name ).addClass('selected'); } } that.select_tab = select_tab; function set_pkey(val){ that.pkey_field.val(val); that.title.empty(); var title = $('

',{ text: entity.metadata.label+": "}); title.append ($('',{text:val})); that.title.append(title); } that.set_pkey = set_pkey; function title(){ that.title = $("
", { 'class':'entity-title' }); var title = $('

',{ text: entity.metadata.label}); that.title.append(title); return that.title; } function buttons(){ that.buttons = $(""); return that.buttons; } function search_bar(){ that.search_bar = $(""); if (entity.facets_by_name.search){ that.search_bar.prepend( $('',{ id:'back_to_search', "class":"input_link", click: function(){ if($(this).hasClass('entity-facet-disabled')){ return false; } IPA.switch_and_show_page(entity.name, 'search'); $(that.facet_tabs).find('a').removeClass('selected'); return false; } }). append(IPA.back_icon + ' ' + IPA.messages.buttons.back_to_list+' ')); } return that.search_bar; } function facet_link(other_facet){ var entity_name = that.entity.name; var other_facet_name = other_facet.name; var li = $('
  • ', { title: other_facet.name, html: $('',{ text: other_facet.label, id: other_facet_name }), click: function(entity_name, other_facet_name) { return function() { if($(this).hasClass('entity-facet-disabled')){ return false; } var this_pkey = that.pkey_field.val(); IPA.switch_and_show_page( entity_name, other_facet_name, this_pkey); $(that.facet_tabs).find('a').removeClass('selected'); $(this).find('a').addClass('selected'); return false; }; }(entity_name, other_facet_name) }); return li; } function facet_group(label){ var facets= entity.facet_groups[label]; if (facets){ that.facet_tabs.append(tab_section(label, facets)); } } function tab_section(label, facets){ var tab_section = $(""). append(""); var ul = $("
      ").appendTo(tab_section); var i; for (i = 0; i < facets.length; i += 1){ var other_facet = facets[i]; ul.append(facet_link(other_facet)); } return tab_section; } function facet_tabs(){ that.facet_tabs = $("
      "); facet_group("Member"); if (entity.facets_by_name.details){ that.facet_tabs.append( tab_section('Settings',[entity.facets_by_name.details])); } facet_group("Member Of"); facet_group("Managed by"); return that.facet_tabs; } function content(){ that.content = $("
      "); return that.content; } function entity_container() { that.entity_container = $("
      ",{ "class":'entity-container', id: 'entity-container-' + entity.name }). append(facet_tabs()). append(content()); return that.entity_container; } function reset(){ that.buttons.empty(); that.content.empty(); } that.reset = reset; that.header = $("
      "). append(title(entity)). append(buttons()). append(pkey()). append(search_bar()). append(entity_container()); container.append(that.header); return that; }; IPA.entity_builder = function(){ var that = {}; var entity = null; var facet = null; function section(spec){ var current_section = null; spec.entity_name = entity.name; if (!spec.label){ var obj_messages = IPA.messages.objects[entity.name]; spec.label = obj_messages[spec.name]; } if (spec.factory){ current_section = spec.factory(spec); }else{ current_section = IPA.details_list_section(spec); } facet.add_section(current_section); var fields = spec.fields; if (fields) { for (var i=0; i