From 53343dad0b063a9bff15c62c86e23909c1db1815 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" Date: Mon, 5 Jul 2010 22:02:05 +0000 Subject: [PATCH] Bug 514618: Allow restricting the visibility and values of fields by classification. r=mkanat, r=timello, a=mkanat git-svn-id: svn://10.0.0.236/trunk@260630 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/webtools/bugzilla/.bzrrev | 2 +- mozilla/webtools/bugzilla/Bugzilla/Bug.pm | 4 ++++ .../bugzilla/Bugzilla/Classification.pm | 11 ++++++++- .../webtools/bugzilla/Bugzilla/Constants.pm | 1 + mozilla/webtools/bugzilla/Bugzilla/Field.pm | 2 +- .../bugzilla/Bugzilla/Field/Choice.pm | 1 + mozilla/webtools/bugzilla/Bugzilla/Product.pm | 16 +++++++++++++ mozilla/webtools/bugzilla/enter_bug.cgi | 3 ++- mozilla/webtools/bugzilla/js/field.js | 14 +++++++++++ .../template/en/default/bug/edit.html.tmpl | 23 ++++++++++++++++++- .../en/default/bug/field-events.js.tmpl | 3 +++ 11 files changed, 75 insertions(+), 5 deletions(-) diff --git a/mozilla/webtools/bugzilla/.bzrrev b/mozilla/webtools/bugzilla/.bzrrev index a22b24093de..48e216d2141 100644 --- a/mozilla/webtools/bugzilla/.bzrrev +++ b/mozilla/webtools/bugzilla/.bzrrev @@ -1 +1 @@ -7264 \ No newline at end of file +7265 \ No newline at end of file diff --git a/mozilla/webtools/bugzilla/Bugzilla/Bug.pm b/mozilla/webtools/bugzilla/Bugzilla/Bug.pm index ea8e4bc3d14..23a92b080ea 100644 --- a/mozilla/webtools/bugzilla/Bugzilla/Bug.pm +++ b/mozilla/webtools/bugzilla/Bugzilla/Bug.pm @@ -3415,9 +3415,13 @@ sub choices { if (!grep($_->name eq $self->product_obj->name, @products)) { unshift(@products, $self->product_obj); } + my %class_ids = map { $_->classification_id => 1 } @products; + my $classifications = + Bugzilla::Classification->new_from_list([keys %class_ids]); my %choices = ( bug_status => $self->statuses_available, + classification => $classifications, product => \@products, component => $self->product_obj->components, version => $self->product_obj->versions, diff --git a/mozilla/webtools/bugzilla/Bugzilla/Classification.pm b/mozilla/webtools/bugzilla/Bugzilla/Classification.pm index c7cda11be8c..88ec4eb3b55 100644 --- a/mozilla/webtools/bugzilla/Bugzilla/Classification.pm +++ b/mozilla/webtools/bugzilla/Bugzilla/Classification.pm @@ -20,11 +20,12 @@ use strict; package Bugzilla::Classification; use Bugzilla::Constants; +use Bugzilla::Field; use Bugzilla::Util; use Bugzilla::Error; use Bugzilla::Product; -use base qw(Bugzilla::Object); +use base qw(Bugzilla::Field::ChoiceInterface Bugzilla::Object); ############################### #### Initialization #### @@ -111,6 +112,14 @@ sub _check_sortkey { return $sortkey; } +##################################### +# Implement Bugzilla::Field::Choice # +##################################### + +use constant FIELD_NAME => 'classification'; +use constant is_default => 0; +use constant is_active => 1; + ############################### #### Methods #### ############################### diff --git a/mozilla/webtools/bugzilla/Bugzilla/Constants.pm b/mozilla/webtools/bugzilla/Bugzilla/Constants.pm index a003ce73988..9c2a3e353c5 100644 --- a/mozilla/webtools/bugzilla/Bugzilla/Constants.pm +++ b/mozilla/webtools/bugzilla/Bugzilla/Constants.pm @@ -403,6 +403,7 @@ use constant EMPTY_DATETIME_REGEX => qr/^[0\-:\sA-Za-z]+$/; # See the POD for Bugzilla::Field/is_abnormal to see why these are listed # here. use constant ABNORMAL_SELECTS => qw( + classification product component ); diff --git a/mozilla/webtools/bugzilla/Bugzilla/Field.pm b/mozilla/webtools/bugzilla/Bugzilla/Field.pm index 15b49476274..76bb1d41ede 100644 --- a/mozilla/webtools/bugzilla/Bugzilla/Field.pm +++ b/mozilla/webtools/bugzilla/Bugzilla/Field.pm @@ -166,7 +166,7 @@ use constant DEFAULT_FIELDS => ( {name => 'short_desc', desc => 'Summary', in_new_bugmail => 1, is_mandatory => 1, buglist => 1}, {name => 'classification', desc => 'Classification', in_new_bugmail => 1, - buglist => 1}, + type => FIELD_TYPE_SINGLE_SELECT, buglist => 1}, {name => 'product', desc => 'Product', in_new_bugmail => 1, type => FIELD_TYPE_SINGLE_SELECT, buglist => 1}, {name => 'version', desc => 'Version', in_new_bugmail => 1, diff --git a/mozilla/webtools/bugzilla/Bugzilla/Field/Choice.pm b/mozilla/webtools/bugzilla/Bugzilla/Field/Choice.pm index 0c44134ef27..773dbd4ce67 100644 --- a/mozilla/webtools/bugzilla/Bugzilla/Field/Choice.pm +++ b/mozilla/webtools/bugzilla/Bugzilla/Field/Choice.pm @@ -64,6 +64,7 @@ use constant VALIDATORS => { use constant CLASS_MAP => { bug_status => 'Bugzilla::Status', + classification => 'Bugzilla::Classification', component => 'Bugzilla::Component', product => 'Bugzilla::Product', }; diff --git a/mozilla/webtools/bugzilla/Bugzilla/Product.pm b/mozilla/webtools/bugzilla/Bugzilla/Product.pm index 51464976345..80e1752e644 100644 --- a/mozilla/webtools/bugzilla/Bugzilla/Product.pm +++ b/mozilla/webtools/bugzilla/Bugzilla/Product.pm @@ -791,6 +791,13 @@ sub flag_types { return $self->{'flag_types'}; } +sub classification { + my $self = shift; + $self->{'classification'} ||= + new Bugzilla::Classification($self->classification_id); + return $self->{'classification'}; +} + ############################### #### Accessors ###### ############################### @@ -853,6 +860,7 @@ Bugzilla::Product - Bugzilla product class. my $bug_ids = $product->bug_ids(); my $has_access = $product->user_has_access($user); my $flag_types = $product->flag_types(); + my $classification = $product->classification(); my $id = $product->id; my $name = $product->name; @@ -1021,6 +1029,14 @@ a group is valid in a particular product.) Returns: Two references to an array of flagtype objects. +=item C + + Description: Returns the classification the product belongs to. + + Params: none. + + Returns: A Bugzilla::Classification object. + =back =head1 SUBROUTINES diff --git a/mozilla/webtools/bugzilla/enter_bug.cgi b/mozilla/webtools/bugzilla/enter_bug.cgi index 4aa6a29d9a3..64b2396282e 100755 --- a/mozilla/webtools/bugzilla/enter_bug.cgi +++ b/mozilla/webtools/bugzilla/enter_bug.cgi @@ -416,7 +416,8 @@ foreach my $field (@enter_bug_fields) { } # This allows the Field visibility and value controls to work with the -# Product field as a parent. +# Classification and Product fields as a parent. +$default{'classification'} = $product->classification->name; $default{'product'} = $product->name; if ($cloned_bug_id) { diff --git a/mozilla/webtools/bugzilla/js/field.js b/mozilla/webtools/bugzilla/js/field.js index 20485bcc8ca..0ca59918a39 100644 --- a/mozilla/webtools/bugzilla/js/field.js +++ b/mozilla/webtools/bugzilla/js/field.js @@ -374,6 +374,20 @@ function updateCommentTagControl(checkbox, form) { } } +/** + * Reset the value of the classification field and fire an event change + * on it. Called when the product changes, in case the classification + * field (which is hidden) controls the visibility of any other fields. + */ +function setClassification() { + var classification = document.getElementById('classification'); + var product = document.getElementById('product'); + var selected_product = product.value; + var select_classification = all_classifications[selected_product]; + classification.value = select_classification; + bz_fireEvent(classification, 'change'); +} + /** * Says that a field should only be displayed when another field has * a certain value. May only be called after the controller has already diff --git a/mozilla/webtools/bugzilla/template/en/default/bug/edit.html.tmpl b/mozilla/webtools/bugzilla/template/en/default/bug/edit.html.tmpl index 5520e769966..0a558ecc199 100644 --- a/mozilla/webtools/bugzilla/template/en/default/bug/edit.html.tmpl +++ b/mozilla/webtools/bugzilla/template/en/default/bug/edit.html.tmpl @@ -128,6 +128,15 @@ [% END %] + /* Index all classifications so we can keep track of the classification + * for the selected product, which could control field visibility. + */ + var all_classifications = new Array([% bug.choices.product.size %]); + [%- FOREACH product = bug.choices.product %] + all_classifications['[% product.name FILTER js %]'] = ' + [%- product.classification.name FILTER js %]'; + [%- END %] + //--> @@ -319,7 +328,6 @@ [%#############%] [%# PRODUCT #%] [%#############%] - [% INCLUDE bug/field.html.tmpl bug = bug, field = bug_fields.product, @@ -327,6 +335,19 @@ desc_url = 'describecomponents.cgi', value = bug.product editable = bug.check_can_change_field('product', 0, 1) %] + + [%# Classification is here so that it can be used in value controllers + # and visibility controllers. It comes after product because + # it uses some javascript that depends on the existence of the + # product field. + #%] + + [% INCLUDE bug/field.html.tmpl + bug = bug field = bug_fields.classification + override_legal_values = bug.choices.classification + value = bug.classification + editable = bug.check_can_change_field('product', 0, 1) %] + [%###############%] [%# Component #%] [%###############%] diff --git a/mozilla/webtools/bugzilla/template/en/default/bug/field-events.js.tmpl b/mozilla/webtools/bugzilla/template/en/default/bug/field-events.js.tmpl index 763687e06c8..f9e0ea93dc1 100644 --- a/mozilla/webtools/bugzilla/template/en/default/bug/field-events.js.tmpl +++ b/mozilla/webtools/bugzilla/template/en/default/bug/field-events.js.tmpl @@ -39,3 +39,6 @@ [% legal_value.id FILTER js %]); [% END %] [% END %] +[% IF field.name == 'classification' %] + YAHOO.util.Event.on('product', 'change', setClassification); +[% END %]