/*jsl:import ipa.js */ /*jsl:import search.js */ /* Authors: * Adam Young * * 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, entity.js, widget.js */ /* DNS */ IPA.entity_factories.dnszone = function() { if (!IPA.dns_enabled) { throw "DNS not enabled on server"; } return IPA.entity_builder(). entity('dnszone'). search_facet({ title: IPA.metadata.objects.dnszone.label, columns:['idnsname'] }). details_facet({ sections:[{ name:'identity', fields:[ 'idnsname', 'idnszoneactive', 'idnssoamname', 'idnssoarname', 'idnssoaserial', 'idnssoarefresh', 'idnssoaretry', 'idnssoaexpire', 'idnssoaminimum', 'dnsttl', 'dnsclass', 'idnsallowdynupdate', 'idnsupdatepolicy']}] }). nested_search_facet({ facet_group: 'member', nested_entity : 'dnsrecord', name: 'records', title: IPA.metadata.objects.dnszone.label_singular, label: IPA.metadata.objects.dnsrecord.label, load: IPA.dns_record_search_load, get_values: IPA.dnsrecord_get_delete_values, 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, width: 500, height: 300, fields: [ 'idnsname', { factory: IPA.checkbox_widget, name: 'name_from_ip', undo: false }, 'idnssoamname', 'idnssoarname', { factory: IPA.force_dnszone_add_checkbox_widget } ] }). build(); }; IPA.dnszone_adder_dialog = function(spec) { spec = spec || {}; var that = IPA.add_dialog(spec); that.create = function() { var table = $('').appendTo(that.container); var field = that.fields.get('idnsname'); var tr = $('').appendTo(table); var td = $('').appendTo(table); td = $('').appendTo(table); td = $('
', { style: 'vertical-align: top;', title: field.label }).appendTo(tr); td.append($('', { style: 'vertical-align: top;' }).appendTo(tr); var span = $('', { name: field.name }).appendTo(td); field.create(span); field.field_span = span; field = that.fields.get('name_from_ip'); tr = $('
', { style: 'vertical-align: top;', title: field.label }).appendTo(tr); td = $('', { style: 'vertical-align: top;' }).appendTo(tr); span = $('', { name: field.name }).appendTo(td); td.append($('
', { colspan: 2, html: ' ' }).appendTo(tr); var fields = that.fields.values; for (var i=0; i').appendTo(table); td = $('', { style: 'vertical-align: top;', title: field.label }).appendTo(tr); td.append($('', { style: 'vertical-align: top;' }).appendTo(tr); span = $('', { name: field.name }).appendTo(td); field.create(span); field.field_span = span; } }; that.save = function(record) { var idnsname; var name_from_ip; var fields = that.fields.values; for (var i=0; i -1){ var rec_type = { label: attr.substring(0,index).toUpperCase(), value: attr }; record_types.push(rec_type); } } return record_types; }; IPA.dnsrecord_type_widget = function (spec){ spec.options = IPA.dns_record_types(); var that = IPA.select_widget(spec); return that; }; IPA.force_dnszone_add_checkbox_widget = function(spec) { var param_info = IPA.get_method_option('dnszone_add', 'force'); spec.name = 'force'; spec.label = param_info.label; spec.tooltip = param_info.doc; spec.undo = false; return IPA.checkbox_widget(spec); }; IPA.dnsrecord_get_delete_values = function(){ var records = {}; var value; var record_type; $('input[name="select"]:checked', this.table.tbody).each(function() { $('span',$(this).parent().parent()).each(function(){ var name = this.attributes['name'].value; if (name === 'idnsname'){ value = records[$(this).text()]; if (!value){ value = {pkey:$(this).text()}; records[$(this).text()] = value; } }else if (name === 'type'){ record_type = $(this).text(); }else if (name === 'data'){ if (!value[record_type]){ value[record_type] = $(this).text(); }else{ value[record_type] += "," + $(this).text(); } } }); }); var value_array = []; for (var key in records){ value_array.push(records[key]); } return value_array; };