/*jsl:import ipa.js */ /* Authors: * Pavel Zuna * Endi Sukma Dewata * Adam Young * Petr Vobornik * * 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, no_init) { spec = spec || {}; spec.state = spec.state || {}; $.extend(spec.state, { factory: IPA.state }); var that = {}; that.entity = IPA.get_entity(spec.entity); that.name = spec.name; that.label = spec.label; that.title = spec.title || that.label; that.tab_label = spec.tab_label || that.label; that.display_class = spec.display_class; that.disable_breadcrumb = spec.disable_breadcrumb; that.disable_facet_tabs = spec.disable_facet_tabs; that.action_state = IPA.build(spec.state); that.actions = IPA.build({ actions: spec.actions }, IPA.action_holder_builder); that.header_actions = spec.header_actions; that.header = spec.header || IPA.facet_header({ facet: that }); that._needs_update = spec.needs_update; that.expired_flag = true; that.last_updated = null; that.expire_timeout = spec.expire_timeout || 600; //[seconds] that.on_update = IPA.observer(); that.post_load = IPA.observer(); that.dialogs = $.ordered_map(); // facet group name that.facet_group = spec.facet_group; that.redirect_info = spec.redirect_info; that.state = {}; that.get_dialog = function(name) { return that.dialogs.get(name); }; that.dialog = function(dialog) { that.dialogs.put(dialog.name, dialog); return that; }; that.create = function(container) { that.container = container; if (that.disable_facet_tabs) that.container.addClass('no-facet-tabs'); that.container.addClass(that.display_class); that.header_container = $('
', { 'class': 'facet-header' }).appendTo(container); that.create_header(that.header_container); that.content = $('
', { 'class': 'facet-content' }).appendTo(container); that.error_container = $('
', { 'class': 'facet-content facet-error' }).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.create_control_buttons = function(container) { if (that.control_buttons) { that.control_buttons.create(container); } }; that.set_title = function(container, title) { var element = $('h1', that.title_container); element.html(title); }; that.show = function() { that.container.css('display', 'block'); that.show_content(); }; that.show_content = function() { that.content.css('display', 'block'); that.error_container.css('display', 'none'); }; that.show_error = function() { that.content.css('display', 'none'); that.error_container.css('display', 'block'); }; that.error_displayed = function() { return that.error_container && that.error_container.css('display') === 'block'; }; that.hide = function() { that.container.css('display', 'none'); }; that.load = function(data) { that.data = data; that.header.load(data); }; that.refresh = function() { }; that.clear = function() { }; that.needs_update = function() { if (that._needs_update !== undefined) return that._needs_update; var needs_update = false; if (that.expire_timeout && that.expire_timeout > 0) { if (!that.last_updated) { needs_update = true; } else { var now = Date.now(); needs_update = (now - that.last_updated) > that.expire_timeout * 1000; } } needs_update = needs_update || that.expired_flag; needs_update = needs_update || that.error_displayed(); return needs_update; }; that.set_expired_flag = function() { that.expired_flag = true; }; that.clear_expired_flag = function() { that.expired_flag = false; that.last_updated = Date.now(); }; that.is_dirty = function() { return false; }; that.report_error = function(error_thrown) { var add_option = function(ul, text, handler) { var li = $('
  • ').appendTo(ul); $('', { href: '#', text: text, click: function() { handler(); return false; } }).appendTo(li); }; var title = IPA.messages.error_report.title; title = title.replace('${error}', error_thrown.name); that.error_container.empty(); that.error_container.append('

    '+title+'

    '); var details = $('
    ', { 'class': 'error-details' }).appendTo(that.error_container); details.append('

    '+error_thrown.message+'

    '); $('
    ', { text: IPA.messages.error_report.options }).appendTo(that.error_container); var options_list = $('