/*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.name = spec.name; that.label = spec.label; that.title = spec.title || that.label; that.display_class = spec.display_class; that.disable_breadcrumb = spec.disable_breadcrumb; that.disable_facet_tabs = spec.disable_facet_tabs; that.back_link_text = spec.back_link_text || IPA.messages.buttons.back_to_list; that.header = spec.header || IPA.facet_header({ facet: that }); that._entity_name = spec.entity_name; that.dialogs = $.ordered_map(); // facet group 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.get(name); }; that.dialog = function(dialog) { that.dialogs.put(dialog.name, dialog); return that; }; that.init = function() { var dialogs = that.dialogs.values; for (var i=0; i', { 'class': 'facet-header' }).appendTo(container); that.create_header(that.header_container); that.content = $('
', { 'class': 'facet-content' }).appendTo(container); that.create_content(that.content); }; that.create_header = function(container) { that.header.create(container); that.controls = $('
', { 'class': 'facet-controls' }).appendTo(container); }; that.create_content = function(container) { }; that.set_title = function(container, title) { var element = $('h1', that.title_container); element.html(title); }; that.setup = function(container) { that.container = container; }; that.show = function() { that.container.css('display', 'block'); }; 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); }; that.report_error = function(error_thrown){ var details = $('.details', that.container).empty(); details.append('

Error: '+error_thrown.name+'

'); details.append('

'+error_thrown.message+'

'); }; that.redirect_on_error = function(){ var current_entity = that.entity; while (current_entity.containing_entity){ current_entity = current_entity.containing_entity; } IPA.nav.show_page( current_entity.name, that.entity.redirect_facet); }; var redirect_errors = ["IPA Error 4001"]; that.on_error = function(xhr, text_status, error_thrown) { /*If the error is in talking to the server, don't attempt to redirect, as there is nothing any other facet can do either. */ if (that.entity.redirect_facet ) { for (var i =0; i < redirect_errors.length; i += 1){ if (error_thrown.name === redirect_errors[i]){ that.redirect_on_error(); return; } } } that.report_error(error_thrown); }; // methods that should be invoked by subclasses that.facet_init = that.init; that.facet_create = that.create; 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.facet_header = function(spec) { spec = spec || {}; var that = {}; that.facet = spec.facet; that.select_tab = function() { if (that.facet.disable_facet_tabs) return; $(that.facet_tabs).find('a').removeClass('selected'); var facet_name = $.bbq.getState(that.facet.entity.name+'-facet'); 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) return; if (!that.facet.disable_breadcrumb) { var breadcrumb = []; var entity = that.facet.entity.containing_entity; while (entity) { breadcrumb.unshift($('', { text: $.bbq.getState(entity.name+'-pkey'), title: entity.name, click: function(entity) { return function() { IPA.nav.show_page(entity.name, 'default'); return false; }; }(entity) })); entity = entity.containing_entity; } that.path.empty(); for (var i=0; i').appendTo(that.title_container); h3.append(that.facet.entity.title); h3.append(': '); $('', { 'class': 'facet-pkey', text: value }).appendTo(h3); }; that.create_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.facet.entity.name+'-pkey'); IPA.nav.show_page(that.facet.entity.name, other_facet.name, pkey); return false; } }).appendTo(container); $('', { text: other_facet.label, id: other_facet.name }).appendTo(li); }; that.create_facet_group = function(container, facet_group) { var section = $('', { 'class': 'facet-group' }).appendTo(container); $('
    ', { 'class': 'facet-group-name', text: facet_group.label }).appendTo(section); var ul = $('