/*jsl:import ipa.js */ /*jsl:import search.js */ /*jsl:import net.js */ /* Authors: * Adam Young * 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: ipa.js, details.js, search.js, add.js, facet.js, entity.js, * net.js, widget.js */ IPA.dns = {}; IPA.dns.zone_entity = function(spec) { var that = IPA.entity(spec); that.init = function() { if (!IPA.dns_enabled) { throw { expected: true }; } that.entity_init(); that.builder.facet_groups([ 'dnsrecord', 'settings' ]). search_facet({ row_enabled_attribute: 'idnszoneactive', title: IPA.metadata.objects.dnszone.label, columns: [ 'idnsname', { name: 'idnszoneactive', label: IPA.messages.status.label, format: IPA.boolean_status_format() } ] }). details_facet({ factory: IPA.dnszone_details_facet, sections: [{ name: 'identity', fields: [ 'idnsname', { type: 'radio', name: 'idnszoneactive', label: IPA.messages.status.label, options: [ { value: 'TRUE', label: IPA.messages.status.enabled }, { value: 'FALSE', label: IPA.messages.status.disabled } ] }, 'idnssoamname', 'idnssoarname', 'idnssoaserial', 'idnssoarefresh', 'idnssoaretry', 'idnssoaexpire', 'idnssoaminimum', 'dnsttl', { type: 'combobox', name: 'dnsclass', options: [ 'IN', 'CS', 'CH', 'HS' ] }, { type: 'radio', name: 'idnsallowdynupdate', options: [ { value: 'TRUE', label: IPA.get_message('true') }, { value: 'FALSE', label: IPA.get_message('false') } ] }, { type: 'textarea', name: 'idnsupdatepolicy' } ] }] }). nested_search_facet({ factory: IPA.dns.record_search_facet, facet_group: 'dnsrecord', nested_entity : 'dnsrecord', name: 'records', deleter_dialog: IPA.dns.record_search_deleter_dialog, title: IPA.metadata.objects.dnszone.label_singular, label: IPA.metadata.objects.dnsrecord.label, columns: [ { name: 'idnsname', label: IPA.get_entity_param('dnsrecord', 'idnsname').label, primary_key: true }, { name: 'type', label: IPA.messages.objects.dnsrecord.type }, { name: 'data', label: IPA.messages.objects.dnsrecord.data } ] }). standard_association_facets(). adder_dialog({ factory: IPA.dnszone_adder_dialog, height: 300, sections: [ { factory: IPA.dnszone_name_section, name: 'name', fields: [ { type: 'dnszone_name', name: 'idnsname', required: false, radio_name: 'dnszone_name_type' }, { type: 'dnszone_name', name: 'name_from_ip', radio_name: 'dnszone_name_type' } ] }, { name: 'other', fields: [ 'idnssoamname', { name: 'idnssoarname', required: false }, { type: 'force_dnszone_add_checkbox', name: 'force', metadata: IPA.get_command_option('dnszone_add', 'force') } ] } ], policies: [ IPA.add_dns_zone_name_policy() ] }); }; return that; }; IPA.dnszone_details_facet = function(spec) { spec = spec || {}; var that = IPA.details_facet(spec); that.update = function(on_success, on_error) { var args = that.get_primary_key(); var modify_operation = { execute: false, command: IPA.command({ entity: that.entity.name, method: 'mod', args: args, options: { all: true, rights: true } }) }; var enable_operation = { execute: false, command: IPA.command({ entity: that.entity.name, method: 'enable', args: args, options: { all: true, rights: true } }) }; var record = {}; that.save(record); 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 table = $('', { 'class': 'section-table' }).appendTo(that.container); var idnsname = that.widgets.get_widget('idnsname'); var tr = $('').appendTo(table); var td = $('').appendTo(table); td = $('
', { 'class': 'section-cell-label', title: idnsname.label }).appendTo(tr); var label = $('', { 'class': 'section-cell-field', title: idnsname.label }).appendTo(tr); var span = $('', { name: 'idnsname', 'class': 'field' }).appendTo(td); idnsname.create(span); var idnsname_input = $('input', span); var name_from_ip = that.widgets.get_widget('name_from_ip'); tr = $('
', { 'class': 'section-cell-label', title: name_from_ip.label }).appendTo(tr); label = $('', { 'class': 'section-cell-field', title: name_from_ip.label }).appendTo(tr); span = $('', { name: 'name_from_ip', 'class': 'field' }).appendTo(td); name_from_ip.create(span); idnsname.radio.click(); }; return that; }; IPA.add_dns_zone_name_policy = function() { var that = IPA.facet_policy(); that.init = function() { var idnsname_w = this.container.widgets.get_widget('name.idnsname'); var name_from_ip_w = this.container.widgets.get_widget('name.name_from_ip'); var idnsname_f = this.container.fields.get_field('idnsname'); var name_from_ip_f = this.container.fields.get_field('name_from_ip'); idnsname_w.radio_clicked.attach(function() { idnsname_w.input.attr('disabled', false); name_from_ip_w.input.attr('disabled', true); idnsname_f.set_required(true); name_from_ip_f.set_required(false); name_from_ip_f.reset(); }); name_from_ip_w.radio_clicked.attach(function() { idnsname_w.input.attr('disabled', true); name_from_ip_w.input.attr('disabled', false); idnsname_f.set_required(false); name_from_ip_f.set_required(true); idnsname_f.reset(); }); }; return that; }; IPA.dnszone_name_widget = function(spec) { spec = spec || {}; var that = IPA.text_widget(spec); that.radio_name = spec.radio_name; that.radio_clicked = IPA.observer(); that.text_save = that.save; that.radio_id = IPA.html_util.get_next_id(that.radio_name); that.save = function() { var values = []; if (that.radio.is(':checked')) { values = that.text_save(); } return values; }; that.create_radio = function(container) { that.radio = $('', { type: 'radio', id: that.radio_id, name: that.radio_name, value: that.name, click: function() { that.radio_clicked.notify([], that); } }).appendTo(container); }; return that; }; IPA.widget_factories['dnszone_name'] = IPA.dnszone_name_widget; IPA.force_dnszone_add_checkbox_widget = function(spec) { var metadata = IPA.get_command_option('dnszone_add', spec.name); spec.label = metadata.label; spec.tooltip = metadata.doc; return IPA.checkbox_widget(spec); }; IPA.widget_factories['force_dnszone_add_checkbox'] = IPA.force_dnszone_add_checkbox_widget; IPA.field_factories['force_dnszone_add_checkbox'] = IPA.checkbox_field; IPA.dnszone_adder_dialog = function(spec) { spec = spec || {}; var that = IPA.entity_adder_dialog(spec); that.create = function() { that.entity_adder_dialog_create(); that.container.addClass('dnszone-adder-dialog'); }; return that; }; IPA.dns.record_search_facet = function(spec) { var that = IPA.nested_search_facet(spec); that.get_records = function(pkeys, on_success, on_error) { var batch = IPA.batch_command({ name: that.get_records_command_name(), on_success: on_success, on_error: on_error }); var zone = IPA.nav.get_state('dnszone-pkey'); for (var i=0; i 0) { $('input[name="'+that.table.name+'"]', tr).remove(); } } }; return that; }; IPA.dns.record_search_deleter_dialog = function(spec) { spec = spec || {}; var that = IPA.search_deleter_dialog(spec); that.create_command = function() { var batch = that.search_deleter_dialog_create_command(); for (var i=0; i', { 'text': IPA.messages.objects.dnsrecord.deleted_no_data }).appendTo(that.container); $('

', { 'text': IPA.messages.objects.dnsrecord.redirection_dnszone }).appendTo(that.container); }; that.create_button({ name: 'ok', label: IPA.messages.buttons.ok, click: function() { that.close(); IPA.nav.show_page('dnszone','default'); } }); return that; }; /* * Spec preparation methods */ IPA.dns.record_prepare_spec = function(spec, type_prepare_method) { var metadata = IPA.dns.get_record_metadata(); var fields = []; var widgets = []; for (var i=0; i -1) { IPA.dns.record_prepare_details_for_type(type, fields, standard_record_section); } else { IPA.dns.record_prepare_details_for_type(type, fields, other_record_section); } } IPA.dns.extend_spec(spec, fields, widgets); }; IPA.dns.record_prepare_details_for_type = function(type, fields, container) { var index = type.name.search('record$'); var dnstype = type.name.substring(0, index).toUpperCase(); var type_widget = { name: type.name, type: 'dnsrecord_type_table', record_type: type.name, value_attribute: 'dnsdata', dnstype: dnstype, columns: type.columns }; container.widgets.push(type_widget); var field = { name: type.name, type: 'dnsrecord_type_table', dnstype: dnstype, label: dnstype, widget: container.name+'.'+type.name }; fields.push(field); }; /* * Widgets and policies */ IPA.dnsrecord_host_link_field = function(spec) { var that = IPA.link_field(spec); that.other_pkeys = function() { var pkey = that.entity.get_primary_key(); return [pkey[0]+'.'+pkey[1]]; }; return that; }; IPA.field_factories['dnsrecord_host_link'] = IPA.dnsrecord_host_link_field; IPA.widget_factories['dnsrecord_host_link'] = IPA.link_widget; IPA.dns_record_types = function() { //only supported var attrs = ['A', 'AAAA', 'A6', 'AFSDB', 'CERT', 'CNAME', 'DNAME', 'DS','KEY', 'KX', 'LOC', 'MX', 'NAPTR', 'NS', 'NSEC', 'PTR', 'RRSIG', 'SRV', 'SIG', 'SSHFP', 'TXT']; var record_types = []; for (var i=0; i -1) { label = label.substring(label.indexOf(' ')); } return label; }; IPA.dnsrecord_type_field = function(spec) { spec = spec || {}; var that = IPA.field(spec); that.type_changed = IPA.observer(); that.get_type = function() { return that.widget.save()[0]; }; that.on_type_change = function() { that.type_changed.notify([], that); }; that.widgets_created = function() { that.field_widgets_created(); that.widget.value_changed.attach(that.on_type_change); }; that.reset = function() { that.field_reset(); that.on_type_change(); }; return that; }; IPA.field_factories['dnsrecord_type'] = IPA.dnsrecord_type_field; IPA.dnsrecord_type_widget = function(spec) { spec.options = IPA.dns_record_types(); var that = IPA.select_widget(spec); return that; }; IPA.widget_factories['dnsrecord_type'] = IPA.dnsrecord_type_widget; IPA.dnsrecord_adder_dialog_type_policy = function(spec) { spec = spec || {}; var that = IPA.facet_policy(spec); that.type_field_name = spec.type_field; that.post_create = function() { that.type_field = that.container.fields.get_field(that.type_field_name); that.type_field.type_changed.attach(that.on_type_change); that.on_type_change(); }; that.on_type_change = function() { var type = that.type_field.get_type(); that.allow_fields_for_type(type); that.show_widgets_for_type(type); }; that.allow_fields_for_type = function(type) { type = type.substring(0, type.indexOf('record')); var fields = that.container.fields.get_fields(); for (var i=0; i -1) { fieldtype = field.name.substring(0, index); } else { fieldtype = field.name.substring(0, field.name.indexOf('record')); } field.enabled = (field.name === 'idnsname' || field.name === that.type_field_name || fieldtype === type); } }; that.show_widgets_for_type = function(type) { var widgets = that.container.widgets.get_widgets(); for (var i=0; i', { href: '#'+that.text, text: that.text, style: 'float: right;', click: function() { return that.link_handler(value); } }).appendTo(container); }; return that; }; IPA.ip_address_validator = function(spec) { spec = spec || {}; var that = IPA.validator(spec); that.address_type = spec.address_type; that.message = spec.message || IPA.messages.widget.validation.ip_address; that.validate = function(value) { var address = NET.ip_address(value); if (!address.valid || !that.is_type_match(address.type)) { return { valid: false, message: that.message }; } return { valid: true }; }; that.is_type_match = function(net_type) { return (!that.address_type || (that.address_type === 'IPv4' && (net_type === 'v4-quads' || net_type === 'v4-int')) || (that.address_type === 'IPv6' && net_type === 'v6')); }; return that; }; IPA.ip_v4_address_validator = function(spec) { spec = spec || {}; spec.address_type = 'IPv4'; spec.message = IPA.messages.widget.validation.ip_v4_address; return IPA.ip_address_validator(spec); }; IPA.ip_v6_address_validator = function(spec) { spec = spec || {}; spec.address_type = 'IPv6'; spec.message = IPA.messages.widget.validation.ip_v6_address; return IPA.ip_address_validator(spec); }; IPA.register('dnszone', IPA.dns.zone_entity); IPA.register('dnsrecord', IPA.dns.record_entity);