/* Authors:
* Adam Young <ayoung@redhat.com>
* Petr Vobornik <pvoborni@redhat.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
define([
'./ipa',
'./jquery',
'./net',
'./navigation',
'./menu',
'./phases',
'./reg',
'./text',
'./details',
'./search',
'./association',
'./entity'],
function(IPA, $, NET, navigation, menu, phases, reg, text) {
IPA.dns = {
zone_permission_name: 'Manage DNS zone ${dnszone}'
};
IPA.dns.config_entity = function(spec) {
spec = spec || {};
spec.defines_key = false;
var that = IPA.entity(spec);
that.init = function() {
if (!IPA.dns_enabled) {
throw {
expected: true
};
}
that.entity_init();
that.builder.details_facet({
title: IPA.metadata.objects.config.label,
sections: [
{
name: 'options',
label: '@i18n:objects.dnsconfig.options',
fields: [
{
$type: 'checkbox',
name: 'idnsallowsyncptr'
},
{
$type: 'multivalued',
name: 'idnsforwarders',
validators: [ 'dnsforwarder']
},
{
$type: 'radio',
name: 'idnsforwardpolicy',
default_value: 'first',
options: [
{
value: 'first',
label: '@i18n:objects.dnsconfig.forward_first'
},
{
value: 'only',
label: '@i18n:objects.dnsconfig.forward_only'
},
{
value: 'none',
label: '@i18n:objects.dnsconfig.forward_none'
}
]
},
'idnszonerefresh'
]
}
],
needs_update: true
});
};
return that;
};
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: '@i18n:status.label',
formatter: 'boolean_status'
}
],
actions: [
'batch_disable',
'batch_enable'
],
control_buttons: [
{
name: 'disable',
label: '@i18n:buttons.disable',
icon: 'disabled-icon'
},
{
name: 'enable',
label: '@i18n:buttons.enable',
icon: 'enabled-icon'
}
]
}).
details_facet({
$factory: IPA.dnszone_details_facet,
command_mode: 'info',
sections: [
{
name: 'identity',
fields: [
'idnsname',
'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: '@i18n:true' },
{ value: 'FALSE', label: '@i18n:false' }
]
},
{
$type: 'textarea',
name: 'idnsupdatepolicy'
},
{
$type: 'netaddr',
name: 'idnsallowquery',
validators: [
{
$type: 'network',
specials: ['any', 'none', 'localhost', 'localnets'],
allow_negation: true,
allow_host_address: true
}]
},
{
$type: 'netaddr',
name: 'idnsallowtransfer',
validators: [
{
$type: 'network',
specials: ['any', 'none', 'localhost', 'localnets'],
allow_negation: true,
allow_host_address: true
}]
},
{
$type: 'multivalued',
name: 'idnsforwarders',
validators: [ 'dnsforwarder']
},
{
$type: 'radio',
name: 'idnsforwardpolicy',
default_value: 'first',
options: [
{
value: 'first',
label: '@i18n:objects.dnsconfig.forward_first'
},
{
value: 'only',
label: '@i18n:objects.dnsconfig.forward_only'
},
{
value: 'none',
label: '@i18n:objects.dnsconfig.forward_none'
}
]
},
{
$type: 'checkbox',
name: 'idnsallowsyncptr'
}
]
}],
actions: [
'select',
'enable',
'disable',
'delete',
'dns_add_permission',
'dns_remove_permission'
],
header_actions: ['select_action', 'enable', 'disable', 'delete',
'add_permission', 'remove_permission'],
state: {
evaluators: [
{
$factory: IPA.enable_state_evaluator,
field: 'idnszoneactive'
},
{
$factory: IPA.acl_state_evaluator,
attribute: 'managedby'
},
IPA.dns.zone_has_permission_evaluator
],
summary_conditions: [
IPA.enabled_summary_cond,
IPA.disabled_summary_cond
]
}
}).
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,
tab_label: IPA.metadata.objects.dnsrecord.label,
columns: [
{
name: 'idnsname',
label: '@mo-param:dnsrecord:idnsname:label',
primary_key: true
},
{
name: 'type',
label: '@i18n:objects.dnsrecord.type'
},
{
name: 'data',
label: '@i18n: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',
validators: ['network']
}
]
},
{
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, no_init) {
spec = spec || {};
var that = IPA.details_facet(spec, true);
that.permission_load = IPA.observer();
that.permission_status = 'unknown'; // [unknown, set, none]
that.refresh_on_success = function(data, text_status, xhr) {
// do not load data from batch
that.show_content();
};
that.create_refresh_command = function() {
var pkey = that.get_pkey();
var batch = IPA.batch_command({
name: 'dnszone_details_refresh'
});
var dnszone_command = that.details_facet_create_refresh_command();
dnszone_command.on_success = function(data, text_status, xhr) {
// create data that mimics dnszone-show output
var dnszone_data = {};
dnszone_data.result = data;
that.load(dnszone_data);
};
batch.add_command(dnszone_command);
var permission_name = IPA.dns.zone_permission_name.replace('${dnszone}', pkey);
var permission_command = IPA.command({
entity: 'permission',
method: 'show',
args: [permission_name],
options: {},
retry: false
});
permission_command.on_success = function(data, text_status, xhr) {
that.permission_status = 'set';
that.permission_load.notify([that.permission_status], that);
};
permission_command.on_error = function(xhr, text_status, error_thrown) {
if (error_thrown && error_thrown.code === 4001) {
//NotFound error
that.permission_status = 'none';
} else {
that.permission_status = 'unknown';
}
that.permission_load.notify([that.permission_status], that);
};
batch.add_command(permission_command);
return batch;
};
that.update_on_success = function(data, text_status, xhr) {
that.refresh();
that.on_update.notify();
|