/*jsl:import ipa.js */ /* Authors: * Endi Sukma Dewata * Petr Vobornik * * 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: widget.js, details.js */ IPA.dialog_button = function(spec) { spec = spec || {}; var that = {}; that.name = spec.name; that.label = spec.label || spec.name; that.click = spec.click || click; that.visible = spec.visible !== undefined ? spec.visible : true; function click() { } that.set_enabled = function(enabled) { if (enabled) { that.element.removeClass('ui-state-disabled'); } else { that.element.addClass('ui-state-disabled'); } }; that.is_enabled = function() { return !that.element.hasClass('ui-state-disabled'); }; return that; }; /** * This is a base class for dialog boxes. */ IPA.dialog = function(spec) { spec = spec || {}; var that = {}; that.entity = IPA.get_entity(spec.entity); that.name = spec.name; that.id = spec.id; that.title = spec.title; that.width = spec.width || 500; that.height = spec.height; that.close_on_escape = spec.close_on_escape !== undefined ? spec.close_on_escape : true; that.widgets = IPA.widget_container(); that.fields = IPA.field_container({ container: that }); that.buttons = $.ordered_map(); that.policies = IPA.facet_policies({ container: that, policies: spec.policies }); that.create_button = function(spec) { var factory = spec.factory || IPA.dialog_button; var button = factory(spec); that.add_button(button); return button; }; that.add_button = function(button) { that.buttons.put(button.name, button); }; that.get_button = function(name) { return that.buttons.get(name); }; that.field = function(field) { that.fields.add_field(field); return that; }; that.validate = function() { var valid = true; var fields = that.fields.get_fields(); for (var i=0; i', { style: 'display: none', 'class': 'dialog-message ui-state-highlight ui-corner-all' }).appendTo(that.container); var widgets = that.widgets.get_widgets(); for (var i=0; i', { name: widget.name, 'class': 'dialog-section' }).appendTo(that.container); widget.create(div); } that.policies.post_create(); }; that.show_message = function(message) { that.message_container.text(message); that.message_container.css('display', ''); }; that.hide_message = function() { that.message_container.css('display', 'none'); }; /** * Open dialog */ that.open = function(container) { that.container = $('
', { id : that.id }); if (container) { container.append(that.container); } that.create(); that.reset(); that.container.dialog({ title: that.title, modal: true, closeOnEscape: that.close_on_escape, width: that.width, minWidth: that.width, height: that.height, minHeight: that.height, close: function(event, ui) { that.close(); } }); that.set_buttons(); }; that.option = function(name, value) { that.container.dialog('option', name, value); }; that.set_buttons = function() { // create a map of button labels and handlers var dialog_buttons = {}; for (var i=0; i -1; } that.set_buttons(); }; that.save = function(record) { var fields = that.fields.get_fields(); for (var i=0; i', { 'class': 'adder-dialog' }).appendTo(that.container); var top_panel = $('
', { 'class': 'adder-dialog-top' }).appendTo(container); $('', { type: 'text', name: 'filter' }).appendTo(top_panel); top_panel.append(' '); that.find_button = IPA.button({ name: 'find', label: IPA.messages.buttons.find, click: function() { that.search(); return false; } }).appendTo(top_panel); top_panel.append(IPA.create_network_spinner()); var left_panel = $('
', { 'class': 'adder-dialog-left' }).appendTo(container); var available_panel = $('
', { name: 'available', 'class': 'adder-dialog-available' }).appendTo(left_panel); $('
', { html: IPA.messages.dialogs.available, 'class': 'adder-dialog-header ui-widget-header' }).appendTo(available_panel); var available_content = $('
', { 'class': 'adder-dialog-content' }).appendTo(available_panel); that.available_table.create(available_content); var right_panel = $('
', { 'class': 'adder-dialog-right' }).appendTo(container); var selected_panel = $('
', { name: 'selected', 'class': 'adder-dialog-selected' }).appendTo(right_panel); $('
', { html: IPA.messages.dialogs.prospective, 'class': 'adder-dialog-header ui-widget-header' }).appendTo(selected_panel); var selected_content = $('
', { 'class': 'adder-dialog-content' }).appendTo(selected_panel); that.selected_table.create(selected_content); var buttons_panel = $('
', { name: 'buttons', 'class': 'adder-dialog-buttons' }).appendTo(container); var div = $('
').appendTo(buttons_panel); IPA.button({ name: 'add', label: '>>', click: function() { that.add(); that.update_buttons(); return false; } }).appendTo(div); div = $('
').appendTo(buttons_panel); IPA.button({ name: 'remove', label: '<<', click: function() { that.remove(); that.update_buttons(); return false; } }).appendTo(div); that.filter_field = $('input[name=filter]', that.container); if (that.external) { container.addClass('adder-dialog-with-external'); var external_panel = $('
', { name: 'external', 'class': 'adder-dialog-external' }).appendTo(left_panel); $('
', { html: IPA.messages.objects.sudorule.external, 'class': 'adder-dialog-header ui-widget-header' }).appendTo(external_panel); var external_content = $('
', { 'class': 'adder-dialog-content' }).appendTo(external_panel); that.external_field = $('', { type: 'text', name: 'external' }).appendTo(external_content); } that.search(); }; that.open = function(container) { var add_button = that.create_button({ name: 'add', label: IPA.messages.buttons.add, click: function() { if (!add_button.is_enabled()) return; that.execute(); } }); that.create_button({ name: 'cancel', label: IPA.messages.buttons.cancel, click: function() { that.close(); } }); that.dialog_open(container); that.update_buttons(); }; that.add = function() { var rows = that.available_table.remove_selected_rows(); that.selected_table.add_rows(rows); }; that.remove = function() { var rows = that.selected_table.remove_selected_rows(); that.available_table.add_rows(rows); }; that.update_buttons = function() { var values = that.selected_table.save(); var button = that.get_button('add'); button.set_enabled(values && values.length); }; that.get_filter = function() { return that.filter_field.val(); }; that.clear_available_values = function() { that.available_table.empty(); }; that.clear_selected_values = function() { that.selected_table.empty(); }; that.add_available_value = function(record) { that.available_table.add_record(record); }; that.get_selected_values = function() { return that.selected_table.save(); }; that.execute = function() { }; init(); that.adder_dialog_create = that.create; return that; }; /** * This dialog displays the values to be deleted. */ IPA.deleter_dialog = function (spec) { spec = spec || {}; var that = IPA.dialog(spec); that.title = spec.title || IPA.messages.buttons.remove; that.values = spec.values || []; that.add_value = function(value) { that.values.push(value); }; that.set_values = function(values) { that.values = values; }; that.create = function() { $('

', { 'text': IPA.messages.search.delete_confirm }).appendTo(that.container); var div = $('

', { style: 'overflow:auto; max-height: 100px' }).appendTo(that.container); var ul = $('
    '); ul.appendTo(div); for (var i=0; i',{ 'text': value }).appendTo(ul); } }; that.open = function(container) { that.create_button({ name: 'remove', label: IPA.messages.buttons.remove, click: function() { that.execute(); } }); that.create_button({ name: 'cancel', label: IPA.messages.buttons.cancel, click: function() { that.close(); } }); that.dialog_open(container); }; that.execute = function() { }; that.deleter_dialog_create = that.create; return that; }; IPA.message_dialog = function(spec) { var that = IPA.dialog(spec); var init = function() { spec = spec || {}; that.message = spec.message || ''; that.on_ok = spec.on_ok; }; that.create = function() { $('

    ', { 'text': that.message }).appendTo(that.container); }; that.create_button({ name: 'ok', label: IPA.messages.buttons.ok, click: function() { that.close(); if(that.on_ok) { that.on_ok(); } } }); init(); that.message_dialog_create = that.create; return that; };