mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Added IP address validator to Host and DNS record adder dialog
Also fixed minor issues reagarding IP addresses or multivalued field: - removed unnecessary method overrides from multivalued_field - fixed extract_child_value method in multivalued_widget to return '' instead of empty arrays when value array is empty - net.js - changed method name and error message from 'trailing zeros' to 'leading zeros' https://fedorahosted.org/freeipa/ticket/1466
This commit is contained in:
committed by
Endi S. Dewata
parent
05345ce8c8
commit
74857a8ee4
@@ -659,17 +659,39 @@ IPA.dns.record_entity = function(spec) {
|
|||||||
adder_dialog({
|
adder_dialog({
|
||||||
factory: IPA.dns.record_adder_dialog,
|
factory: IPA.dns.record_adder_dialog,
|
||||||
fields: [
|
fields: [
|
||||||
'idnsname',
|
|
||||||
{
|
{
|
||||||
factory: IPA.dnsrecord_type_widget,
|
name: 'idnsname',
|
||||||
name: 'record_type',
|
widget: 'general.idnsname'
|
||||||
label: IPA.messages.objects.dnsrecord.type
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'text',
|
name: 'record_type',
|
||||||
|
widget: 'general.record_type'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'dnsrecord',
|
||||||
name: 'record_data',
|
name: 'record_data',
|
||||||
label: IPA.messages.objects.dnsrecord.data,
|
required: true,
|
||||||
required: true
|
widget: 'general.record_data',
|
||||||
|
type_widget: 'general.record_type'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
widgets: [
|
||||||
|
{
|
||||||
|
name: 'general',
|
||||||
|
type: 'details_table_section_nc',
|
||||||
|
widgets: [
|
||||||
|
'idnsname',
|
||||||
|
{
|
||||||
|
type: 'dnsrecord_type',
|
||||||
|
name: 'record_type',
|
||||||
|
label: IPA.messages.objects.dnsrecord.type
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
name: 'record_data',
|
||||||
|
label: IPA.messages.objects.dnsrecord.data
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@@ -697,6 +719,7 @@ IPA.dns.record_adder_dialog = function(spec) {
|
|||||||
return command;
|
return command;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -781,6 +804,55 @@ IPA.dnsrecord_type_widget = function(spec) {
|
|||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
IPA.widget_factories['dnsrecord_type'] = IPA.dnsrecord_type_widget;
|
||||||
|
|
||||||
|
IPA.dnsrecord_field = function(spec) {
|
||||||
|
|
||||||
|
spec = spec || {};
|
||||||
|
var that = IPA.field(spec);
|
||||||
|
|
||||||
|
that.type_widget_name = spec.type_widget || '';
|
||||||
|
|
||||||
|
that.normal_validators = [];
|
||||||
|
that.a_record_validators = [
|
||||||
|
IPA.ip_v4_address_validator()
|
||||||
|
];
|
||||||
|
that.aaaa_record_validators = [
|
||||||
|
IPA.ip_v6_address_validator()
|
||||||
|
];
|
||||||
|
|
||||||
|
that.on_type_change = function() {
|
||||||
|
|
||||||
|
var type = that.type_widget.save()[0];
|
||||||
|
|
||||||
|
if (type === 'arecord') {
|
||||||
|
that.validators = that.a_record_validators;
|
||||||
|
} else if (type === 'aaaarecord') {
|
||||||
|
that.validators = that.aaaa_record_validators;
|
||||||
|
} else {
|
||||||
|
that.validators = that.normal_validators;
|
||||||
|
}
|
||||||
|
|
||||||
|
that.validate();
|
||||||
|
};
|
||||||
|
|
||||||
|
that.widgets_created = function() {
|
||||||
|
|
||||||
|
that.field_widgets_created();
|
||||||
|
that.type_widget = that.container.widgets.get_widget(that.type_widget_name);
|
||||||
|
that.type_widget.value_changed.attach(that.on_type_change);
|
||||||
|
};
|
||||||
|
|
||||||
|
that.reset = function() {
|
||||||
|
that.field_reset();
|
||||||
|
that.on_type_change();
|
||||||
|
};
|
||||||
|
|
||||||
|
return that;
|
||||||
|
};
|
||||||
|
|
||||||
|
IPA.field_factories['dnsrecord'] = IPA.dnsrecord_field;
|
||||||
|
|
||||||
IPA.force_dnszone_add_checkbox_widget = function(spec) {
|
IPA.force_dnszone_add_checkbox_widget = function(spec) {
|
||||||
var metadata = IPA.get_command_option('dnszone_add', spec.name);
|
var metadata = IPA.get_command_option('dnszone_add', spec.name);
|
||||||
spec.label = metadata.label;
|
spec.label = metadata.label;
|
||||||
@@ -830,6 +902,7 @@ IPA.dnsrecord_get_delete_values = function() {
|
|||||||
|
|
||||||
IPA.ip_address_validator = function(spec) {
|
IPA.ip_address_validator = function(spec) {
|
||||||
|
|
||||||
|
spec = spec || {};
|
||||||
var that = IPA.validator(spec);
|
var that = IPA.validator(spec);
|
||||||
|
|
||||||
that.address_type = spec.address_type;
|
that.address_type = spec.address_type;
|
||||||
|
@@ -504,11 +504,6 @@ IPA.multivalued_field = function(spec) {
|
|||||||
|
|
||||||
var that = IPA.field(spec);
|
var that = IPA.field(spec);
|
||||||
|
|
||||||
that.widgets_created = function() {
|
|
||||||
|
|
||||||
that.field_widgets_created();
|
|
||||||
};
|
|
||||||
|
|
||||||
that.load = function(record) {
|
that.load = function(record) {
|
||||||
|
|
||||||
that.field_load(record);
|
that.field_load(record);
|
||||||
@@ -520,11 +515,6 @@ IPA.multivalued_field = function(spec) {
|
|||||||
return dirty;
|
return dirty;
|
||||||
};
|
};
|
||||||
|
|
||||||
that.widget_value_changed = function() {
|
|
||||||
that.set_dirty(that.test_dirty());
|
|
||||||
that.validate();
|
|
||||||
};
|
|
||||||
|
|
||||||
that.validate = function() {
|
that.validate = function() {
|
||||||
|
|
||||||
that.hide_error();
|
that.hide_error();
|
||||||
|
@@ -146,6 +146,7 @@ IPA.host.entity = function(spec) {
|
|||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: 'ip_address',
|
name: 'ip_address',
|
||||||
|
validators: [ IPA.ip_address_validator() ],
|
||||||
metadata: IPA.get_command_option('host_add', 'ip_address')
|
metadata: IPA.get_command_option('host_add', 'ip_address')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@@ -157,7 +157,7 @@ NET.ip_address = function(spec) {
|
|||||||
|
|
||||||
//add missing zeros for not empty parts
|
//add missing zeros for not empty parts
|
||||||
if (part.length !== 0 && part.length < 4) {
|
if (part.length !== 0 && part.length < 4) {
|
||||||
part = add_trailing_zeros(part, 4 - part.length);
|
part = add_leading_zeros(part, 4 - part.length);
|
||||||
that.parts[i] = part;
|
that.parts[i] = part;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,11 +211,11 @@ NET.ip_address = function(spec) {
|
|||||||
function dec_2_hex(val) {
|
function dec_2_hex(val) {
|
||||||
var dec = parseInt(val, 10);
|
var dec = parseInt(val, 10);
|
||||||
var hex = dec.toString(16);
|
var hex = dec.toString(16);
|
||||||
hex = add_trailing_zeros(hex, 2 - hex.length);
|
hex = add_leading_zeros(hex, 2 - hex.length);
|
||||||
return hex;
|
return hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_trailing_zeros(val, num) {
|
function add_leading_zeros(val, num) {
|
||||||
for (var i=0; i<num; i++) {
|
for (var i=0; i<num; i++) {
|
||||||
val='0'+val;
|
val='0'+val;
|
||||||
}
|
}
|
||||||
@@ -327,7 +327,7 @@ NET.ip_address = function(spec) {
|
|||||||
|
|
||||||
//check for leading zeros
|
//check for leading zeros
|
||||||
if (i === 0 && digit === 0 && number.length > 1) {
|
if (i === 0 && digit === 0 && number.length > 1) {
|
||||||
return that.set_error('invalid format: trailing zeros');
|
return that.set_error('invalid format: leading zeros');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,7 +362,7 @@ NET.ip_address = function(spec) {
|
|||||||
|
|
||||||
var hex_str = integer.toString(16);
|
var hex_str = integer.toString(16);
|
||||||
if (hex_str.length < 8) {
|
if (hex_str.length < 8) {
|
||||||
hex_str = add_trailing_zeros(hex_str, 8 - hex_str.length);
|
hex_str = add_leading_zeros(hex_str, 8 - hex_str.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i=0; i<hex_str.length; i+=2) {
|
for (var i=0; i<hex_str.length; i+=2) {
|
||||||
|
@@ -406,8 +406,15 @@ IPA.multivalued_text_widget = function(spec) {
|
|||||||
|
|
||||||
that.extract_child_value = function(value) {
|
that.extract_child_value = function(value) {
|
||||||
|
|
||||||
if (value.length) return value[0];
|
if (value instanceof Array) {
|
||||||
|
if (value.length > 0) {
|
||||||
|
return value[0];
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
if (value) return value;
|
if (value) return value;
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -851,7 +858,14 @@ IPA.select_widget = function(spec) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
that.save = function() {
|
that.save = function() {
|
||||||
var value = that.select.val() || '';
|
var value;
|
||||||
|
|
||||||
|
if (that.select) {
|
||||||
|
value = that.select.val() || '';
|
||||||
|
} else if (that.options.length > 0) {
|
||||||
|
value = that.options[0].value; //will be default value
|
||||||
|
}
|
||||||
|
|
||||||
return [value];
|
return [value];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user