From: mkanat%bugzilla.org <> Date: Sun, 21 Jun 2009 19:34:33 +0000 (+0000) Subject: Bug 463598: Improve the performance of the JavaScript that adjusts field values X-Git-Tag: bugzilla-3.4rc1~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8ead5b6cafc46f7ddbe22cf3557e3c75e625c70;p=thirdparty%2Fbugzilla.git Bug 463598: Improve the performance of the JavaScript that adjusts field values based on the value of another field Patch by Max Kanat-Alexander r=wicked, a=mkanat --- diff --git a/Bugzilla/Field/Choice.pm b/Bugzilla/Field/Choice.pm index fe5c7bdcbb..f23b0c46d4 100644 --- a/Bugzilla/Field/Choice.pm +++ b/Bugzilla/Field/Choice.pm @@ -199,7 +199,7 @@ sub _check_if_controller { my $self = shift; my $vis_fields = $self->controls_visibility_of_fields; my $values = $self->controlled_values; - if (@$vis_fields || @$values) { + if (@$vis_fields || scalar(keys %$values)) { ThrowUserError('fieldvalue_is_controller', { value => $self, fields => [map($_->name, @$vis_fields)], vals => $values }); @@ -287,13 +287,13 @@ sub controlled_values { my $self = shift; return $self->{controlled_values} if defined $self->{controlled_values}; my $fields = $self->field->controls_values_of; - my @controlled_values; + my %controlled_values; foreach my $field (@$fields) { - my $controlled = Bugzilla::Field::Choice->type($field) - ->match({ visibility_value_id => $self->id }); - push(@controlled_values, @$controlled); + $controlled_values{$field->name} = + Bugzilla::Field::Choice->type($field) + ->match({ visibility_value_id => $self->id }); } - $self->{controlled_values} = \@controlled_values; + $self->{controlled_values} = \%controlled_values; return $self->{controlled_values}; } @@ -431,4 +431,14 @@ The key that determines the sort order of this item. The L object that this field value belongs to. +=item C + +Tells you which values in B fields appear (become visible) when this +value is set in its field. + +Returns a hashref of arrayrefs. The hash keys are the names of fields, +and the values are arrays of C objects, +representing values that this value controls the visibility of, for +that field. + =back diff --git a/js/field.js b/js/field.js index 629fb8a23b..700c1de8dc 100644 --- a/js/field.js +++ b/js/field.js @@ -389,40 +389,52 @@ function handleVisControllerValueChange(e, args) { } } -function showValueWhen(controlled_field_id, controlled_value, - controller_field_id, controller_value) +function showValueWhen(controlled_field_id, controlled_value_ids, + controller_field_id, controller_value_id) { var controller_field = document.getElementById(controller_field_id); // Note that we don't get an object for the controlled field here, // because it might not yet exist in the DOM. We just pass along its id. YAHOO.util.Event.addListener(controller_field, 'change', - handleValControllerChange, [controlled_field_id, controlled_value, - controller_field, controller_value]); + handleValControllerChange, [controlled_field_id, controlled_value_ids, + controller_field, controller_value_id]); } function handleValControllerChange(e, args) { var controlled_field = document.getElementById(args[0]); - var controlled_value = args[1]; + var controlled_value_ids = args[1]; var controller_field = args[2]; - var controller_value = args[3]; - - var item = getPossiblyHiddenOption(controlled_field, controlled_value); - if (bz_valueSelected(controller_field, controller_value)) { - showOptionInIE(item, controlled_field); - YAHOO.util.Dom.removeClass(item, 'bz_hidden_option'); - item.disabled = false; - } - else if (!item.disabled) { - YAHOO.util.Dom.addClass(item, 'bz_hidden_option'); - if (item.selected) { - item.selected = false; - bz_fireEvent(controlled_field, 'change'); + var controller_value_id = args[3]; + + var controller_item = document.getElementById( + _value_id(controller_field.id, controller_value_id)); + + for (var i = 0; i < controlled_value_ids.length; i++) { + var item = getPossiblyHiddenOption(controlled_field, + controlled_value_ids[i]); + if (item.disabled && controller_item && controller_item.selected) { + item = showOptionInIE(item, controlled_field); + YAHOO.util.Dom.removeClass(item, 'bz_hidden_option'); + item.disabled = false; + } + else if (!item.disabled) { + YAHOO.util.Dom.addClass(item, 'bz_hidden_option'); + if (item.selected) { + item.selected = false; + bz_fireEvent(controlled_field, 'change'); + } + item.disabled = true; + hideOptionInIE(item, controlled_field); } - item.disabled = true; - hideOptionInIE(item, controlled_field); } } +// A convenience function to generate the "id" tag of an