Merge "Help texts and dynamic label change for entering security group rules. ICMP rules have different meanings for the from_port and to_port fields."

This commit is contained in:
Jenkins 2012-02-23 20:19:25 +00:00 committed by Gerrit Code Review
commit a8403c97d5
3 changed files with 42 additions and 9 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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() {