/*jsl:import ipa.js */ /* Authors: * Endi Sukma 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: widget.js */ /** * This is a base class for dialog boxes. */ IPA.dialog = function(spec) { spec = spec || {}; var that = {}; that.entity = spec.entity; that.name = spec.name; that.id = spec.id; that.title = spec.title; that.width = spec.width || 400; that.height = spec.height; that.buttons = {}; that.fields = $.ordered_map(); that.sections = $.ordered_map(); that.conditional_fields = []; that.enable_conditional_fields = function(){ for (var i =0; i < that.conditional_fields.length; i+=1) { $('label[id='+ that.conditional_fields[i] +'-label]', that.container).css('visibility','visible'); $('input[name='+ that.conditional_fields[i] + ']',that.container).css('visibility','visible'); } }; that.disable_conditional_fields = function(){ for (var i =0; i < that.conditional_fields.length; i+=1) { $('label[id='+ that.conditional_fields[i] +'-label]', that.container).css('visibility','hidden'); $('input[name='+ that.conditional_fields[i] + ']',that.container).css('visibility','hidden'); } }; that.add_button = function(name, handler) { that.buttons[name] = handler; }; that.get_field = function(name) { return that.fields.get(name); }; that.add_field = function(field) { field.dialog = that; that.fields.put(field.name, field); if (field.conditional){ that.conditional_fields.push(field.name); } return field; }; that.field = function(field) { that.add_field(field); return that; }; that.is_valid = function() { var fields = that.fields.values; for (var i=0; i').appendTo(that.container); var fields = that.fields.values; for (var i=0; i').appendTo(table); var td = $('', { style: 'vertical-align: top;', title: field.label }).appendTo(tr); var label_text = field.label; if (label_text !== null){ label_text += ': '; }else{ label_text = ''; } td.append($('