diff --git a/horizon/horizon/dashboards/nova/access_and_security/security_groups/forms.py b/horizon/horizon/dashboards/nova/access_and_security/security_groups/forms.py index 0ba14011a..d67b12a17 100644 --- a/horizon/horizon/dashboards/nova/access_and_security/security_groups/forms.py +++ b/horizon/horizon/dashboards/nova/access_and_security/security_groups/forms.py @@ -53,12 +53,31 @@ class CreateGroup(forms.SelfHandlingForm): class AddRule(forms.SelfHandlingForm): - ip_protocol = forms.ChoiceField(choices=[('tcp', 'tcp'), + ip_protocol = forms.ChoiceField(label=_('IP protocol'), + choices=[('tcp', 'tcp'), ('udp', 'udp'), - ('icmp', 'icmp')]) - from_port = forms.CharField() - to_port = forms.CharField() - cidr = forms.CharField() + ('icmp', 'icmp')], + widget=forms.Select(attrs={'class': + 'switchable'})) + from_port = forms.IntegerField(label=_("From port"), + help_text=_("TCP/UDP: Enter integer value " + "between 1 and 65535. ICMP: " + "enter a value for ICMP type " + "in the range (-1: 255)"), + widget=forms.TextInput( + attrs={'data': _('From port'), + 'data-icmp': _('Type')})) + to_port = forms.IntegerField(label=_("To port"), + help_text=_("TCP/UDP: Enter integer value " + "between 1 and 65535. ICMP: " + "enter a value for ICMP code " + "in the range (-1: 255)"), + widget=forms.TextInput( + attrs={'data': _('To port'), + 'data-icmp': _('Code')})) + cidr = forms.CharField(label=_("CIDR"), + help_text=_("Classless Inter-Domain Routing " + "(i.e. 192.168.0.0/24")) # TODO (anthony) source group support # group_id = forms.CharField() diff --git a/horizon/horizon/dashboards/nova/access_and_security/security_groups/tests.py b/horizon/horizon/dashboards/nova/access_and_security/security_groups/tests.py index 2fd4de008..bfbefb5c1 100644 --- a/horizon/horizon/dashboards/nova/access_and_security/security_groups/tests.py +++ b/horizon/horizon/dashboards/nova/access_and_security/security_groups/tests.py @@ -115,8 +115,8 @@ class SecurityGroupsViewTests(test.TestCase): api.security_group_rule_create(IsA(http.HttpRequest), sec_group.id, rule.ip_protocol, - rule.from_port, - rule.to_port, + int(rule.from_port), + int(rule.to_port), rule.ip_range['cidr']).AndReturn(rule) self.mox.ReplayAll() @@ -139,8 +139,8 @@ class SecurityGroupsViewTests(test.TestCase): api.security_group_rule_create(IsA(http.HttpRequest), sec_group.id, rule.ip_protocol, - rule.from_port, - rule.to_port, + int(rule.from_port), + int(rule.to_port), rule.ip_range['cidr']).AndRaise(exc) self.mox.ReplayAll() diff --git a/openstack-dashboard/dashboard/static/dashboard/js/forms.js b/openstack-dashboard/dashboard/static/dashboard/js/forms.js index 372827668..7017ee258 100644 --- a/openstack-dashboard/dashboard/static/dashboard/js/forms.js +++ b/openstack-dashboard/dashboard/static/dashboard/js/forms.js @@ -42,6 +42,20 @@ horizon.addInitFunction(function () { return response; }); + $('select.switchable').live("change", (function(e){ + var type = $(this).val(); + $(this).closest('fieldset').find('input[type=text]').each(function(index, obj){ + var label_val = ""; + if ($(obj).attr("data-"+type)){ + label_val = $(obj).attr("data-"+type); + } else if ($(obj).attr("data")){ + label_val = $(obj).attr("data"); + } else + return true; + $('label[for='+ $(obj).attr('id') + ']').html(label_val); + }); + })).change(); + /* Twipsy tooltips */ function getTwipsyTitle() {