diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2012-01-09 10:56:24 +0100 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2012-01-11 00:48:44 -0600 |
commit | 74857a8ee465819b262c3445ea22119196e92c5e (patch) | |
tree | 2626c2042c0b3a35a7032f8143ea19075dad1966 /install/ui | |
parent | 05345ce8c8007dd3ef708ae9049423937d543c67 (diff) | |
download | freeipa-74857a8ee465819b262c3445ea22119196e92c5e.tar.gz freeipa-74857a8ee465819b262c3445ea22119196e92c5e.tar.xz freeipa-74857a8ee465819b262c3445ea22119196e92c5e.zip |
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
Diffstat (limited to 'install/ui')
-rw-r--r-- | install/ui/dns.js | 85 | ||||
-rw-r--r-- | install/ui/field.js | 10 | ||||
-rw-r--r-- | install/ui/host.js | 1 | ||||
-rw-r--r-- | install/ui/net.js | 10 | ||||
-rw-r--r-- | install/ui/widget.js | 18 |
5 files changed, 101 insertions, 23 deletions
diff --git a/install/ui/dns.js b/install/ui/dns.js index a5c9aec3a..9873c1395 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; diff --git a/install/ui/field.js b/install/ui/field.js index 09bd6c120..1caab161b 100644 --- a/install/ui/field.js +++ b/install/ui/field.js @@ -504,11 +504,6 @@ IPA.multivalued_field = function(spec) { var that = IPA.field(spec); - that.widgets_created = function() { - - that.field_widgets_created(); - }; - that.load = function(record) { that.field_load(record); @@ -520,11 +515,6 @@ IPA.multivalued_field = function(spec) { return dirty; }; - that.widget_value_changed = function() { - that.set_dirty(that.test_dirty()); - that.validate(); - }; - that.validate = function() { that.hide_error(); diff --git a/install/ui/host.js b/install/ui/host.js index 90e6bde71..88635955c 100644 --- a/install/ui/host.js +++ b/install/ui/host.js @@ -146,6 +146,7 @@ IPA.host.entity = function(spec) { fields: [ { name: 'ip_address', + validators: [ IPA.ip_address_validator() ], metadata: IPA.get_command_option('host_add', 'ip_address') }, { diff --git a/install/ui/net.js b/install/ui/net.js index 9eba6dc7a..b8674919f 100644 --- a/install/ui/net.js +++ b/install/ui/net.js @@ -157,7 +157,7 @@ NET.ip_address = function(spec) { //add missing zeros for not empty parts 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; } } @@ -211,11 +211,11 @@ NET.ip_address = function(spec) { function dec_2_hex(val) { var dec = parseInt(val, 10); var hex = dec.toString(16); - hex = add_trailing_zeros(hex, 2 - hex.length); + hex = add_leading_zeros(hex, 2 - hex.length); return hex; } - function add_trailing_zeros(val, num) { + function add_leading_zeros(val, num) { for (var i=0; i<num; i++) { val='0'+val; } @@ -327,7 +327,7 @@ NET.ip_address = function(spec) { //check for leading zeros 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); 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) { diff --git a/install/ui/widget.js b/install/ui/widget.js index 9ae308ca2..4972372cb 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -406,8 +406,15 @@ IPA.multivalued_text_widget = function(spec) { 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; + return ''; }; @@ -851,7 +858,14 @@ IPA.select_widget = function(spec) { }; 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]; }; |