/*jsl:import ipa.js */ /* Authors: * Pavel Zuna * Adam Young * Endi S. Dewata * * 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 */ IPA.search_facet = function(spec) { spec = spec || {}; spec.name = spec.name || 'search'; spec.managed_entity_name = spec.managed_entity_name || spec.entity_name; spec.disable_breadcrumb = spec.disable_breadcrumb === undefined ? true : spec.disable_breadcrumb; spec.disable_facet_tabs = spec.disable_facet_tabs === undefined ? true : spec.disable_facet_tabs; var that = IPA.table_facet(spec); that.search_all = spec.search_all || false; that.selectable = spec.selectable; function get_values() { return that.table.get_selected_values(); } that.get_values = spec.get_values || get_values; that.init = function() { that.facet_init(); that.managed_entity = IPA.get_entity(that.managed_entity_name); that.init_table(that.managed_entity); }; that.init_table = function(entity){ that.table = IPA.table_widget({ 'class': 'content-table', name: 'search', label: entity.metadata.label, entity_name: entity.name, search_all: that.search_all, scrollable: true, selectable: that.selectable }); var columns = that.columns.values; for (var i=0; i', { 'class': 'right-aligned-facet-controls' }).appendTo(that.controls); that.filter = $('', { type: 'text', 'class': 'search-filter', name: 'filter' }).appendTo(span); that.filter.keypress(function(e) { /* if the key pressed is the enter key */ if (e.which == 13) { that.find(); } }); that.find_button = IPA.action_button({ name: 'find', icon: 'search-icon', click: function() { that.find(); return false; } }).appendTo(span); span.append(IPA.create_network_spinner()); that.remove_button = IPA.action_button({ name: 'remove', label: IPA.messages.buttons.remove, icon: 'remove-icon', click: function() { if (that.remove_button.hasClass('input_link_disabled')) return false; that.remove(); return false; } }).appendTo(that.controls); that.add_button = IPA.action_button({ name: 'add', label: IPA.messages.buttons.add, icon: 'add-icon', click: function() { that.add(); return false; } }).appendTo(that.controls); }; that.create_content = function(container) { that.table.create(container); that.table.setup(container); }; that.show = function() { that.facet_show(); if (that.filter) { var filter = IPA.nav.get_state(that.entity_name+'-filter'); that.filter.val(filter); } }; that.select_changed = function() { var values = that.table.get_selected_values(); if (that.remove_button) { if (values.length === 0) { that.remove_button.addClass('input_link_disabled'); } else { that.remove_button.removeClass('input_link_disabled'); } } }; that.add = function() { var dialog = that.managed_entity.get_dialog('add'); dialog.open(that.container); }; that.remove = function() { that.remove_instances(that.managed_entity); }; that.remove_instances = function(entity) { var values = that.get_values(); var label = entity.metadata.label; var title; if (!values.length) { title = IPA.messages.dialogs.remove_empty; title = title.replace('${entity}', label); alert(title); return; } title = IPA.messages.dialogs.remove_title; title = title.replace('${entity}', label); var dialog = IPA.deleter_dialog({ 'title': title, 'parent': that.container, 'values': values, entity_name: entity.name }); dialog.execute = function() { var batch = IPA.batch_command({ 'on_success': function() { that.refresh(); dialog.close(); }, 'on_error': function() { that.refresh(); dialog.close(); } }); var pkeys = entity.get_primary_key_prefix(); for (var i=0; i