From 74857a8ee465819b262c3445ea22119196e92c5e Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Mon, 9 Jan 2012 10:56:24 +0100 Subject: 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 --- install/ui/dns.js | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 6 deletions(-) (limited to 'install/ui/dns.js') diff --git a/install/ui/dns.js b/install/ui/dns.js index a5c9aec3..9873c139 100644 --- a/install/ui/dns.js +++ b/install/ui/dns.js @@ -659,17 +659,39 @@ IPA.dns.record_entity = function(spec) { adder_dialog({ factory: IPA.dns.record_adder_dialog, fields: [ - 'idnsname', { - factory: IPA.dnsrecord_type_widget, + name: 'idnsname', + widget: 'general.idnsname' + }, + { name: 'record_type', - label: IPA.messages.objects.dnsrecord.type + widget: 'general.record_type' }, { - type: 'text', + type: 'dnsrecord', 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 that; }; @@ -781,6 +804,55 @@ IPA.dnsrecord_type_widget = function(spec) { 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) { var metadata = IPA.get_command_option('dnszone_add', spec.name); spec.label = metadata.label; @@ -830,6 +902,7 @@ IPA.dnsrecord_get_delete_values = function() { IPA.ip_address_validator = function(spec) { + spec = spec || {}; var that = IPA.validator(spec); that.address_type = spec.address_type; -- cgit