From a9822ceefb563a54420f13b2395b8c1359833778 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Sat, 25 Oct 2008 04:14:56 +0000 Subject: Bug 458436: Allow standard global select fields to control visibility of custom fields Patch By Max Kanat-Alexander r=bbaetz, a=mkanat --- Bugzilla/Field.pm | 41 ++++++++++++++---- editvalues.cgi | 17 +------- .../en/default/admin/custom_fields/cf-js.js.tmpl | 3 +- .../default/admin/custom_fields/create.html.tmpl | 3 +- .../en/default/admin/custom_fields/edit.html.tmpl | 4 +- template/en/default/bug/create/create.html.tmpl | 48 ++++++++++++++++------ template/en/default/bug/edit.html.tmpl | 31 +++++++++++--- template/en/default/bug/field.html.tmpl | 30 ++++++++++---- template/en/default/bug/knob.html.tmpl | 11 +++++ 9 files changed, 131 insertions(+), 57 deletions(-) diff --git a/Bugzilla/Field.pm b/Bugzilla/Field.pm index 7da8a8bba..a5e380a11 100644 --- a/Bugzilla/Field.pm +++ b/Bugzilla/Field.pm @@ -125,6 +125,8 @@ use constant UPDATE_COLUMNS => qw( enter_bug visibility_field_id visibility_value_id + + type ); # How various field types translate into SQL data definitions. @@ -148,16 +150,22 @@ use constant DEFAULT_FIELDS => ( {name => 'classification', desc => 'Classification', in_new_bugmail => 1}, {name => 'product', desc => 'Product', in_new_bugmail => 1}, {name => 'version', desc => 'Version', in_new_bugmail => 1}, - {name => 'rep_platform', desc => 'Platform', in_new_bugmail => 1}, + {name => 'rep_platform', desc => 'Platform', in_new_bugmail => 1, + type => FIELD_TYPE_SINGLE_SELECT}, {name => 'bug_file_loc', desc => 'URL', in_new_bugmail => 1}, - {name => 'op_sys', desc => 'OS/Version', in_new_bugmail => 1}, - {name => 'bug_status', desc => 'Status', in_new_bugmail => 1}, + {name => 'op_sys', desc => 'OS/Version', in_new_bugmail => 1, + type => FIELD_TYPE_SINGLE_SELECT}, + {name => 'bug_status', desc => 'Status', in_new_bugmail => 1, + type => FIELD_TYPE_SINGLE_SELECT}, {name => 'status_whiteboard', desc => 'Status Whiteboard', in_new_bugmail => 1}, {name => 'keywords', desc => 'Keywords', in_new_bugmail => 1}, - {name => 'resolution', desc => 'Resolution'}, - {name => 'bug_severity', desc => 'Severity', in_new_bugmail => 1}, - {name => 'priority', desc => 'Priority', in_new_bugmail => 1}, + {name => 'resolution', desc => 'Resolution', + type => FIELD_TYPE_SINGLE_SELECT}, + {name => 'bug_severity', desc => 'Severity', in_new_bugmail => 1, + type => FIELD_TYPE_SINGLE_SELECT}, + {name => 'priority', desc => 'Priority', in_new_bugmail => 1, + type => FIELD_TYPE_SINGLE_SELECT}, {name => 'component', desc => 'Component', in_new_bugmail => 1}, {name => 'assigned_to', desc => 'AssignedTo', in_new_bugmail => 1}, {name => 'reporter', desc => 'ReportedBy', in_new_bugmail => 1}, @@ -200,6 +208,20 @@ use constant DEFAULT_FIELDS => ( {name => "owner_idle_time", desc => "Time Since Assignee Touched"}, ); +################ +# Constructors # +################ + +# Override match to add is_select. +sub match { + my $self = shift; + my ($params) = @_; + if (delete $params->{is_select}) { + $params->{type} = [FIELD_TYPE_SINGLE_SELECT, FIELD_TYPE_MULTI_SELECT]; + } + return $self->SUPER::match(@_); +} + ############## # Validators # ############## @@ -551,6 +573,9 @@ sub set_visibility_value { delete $self->{visibility_value}; } +# This is only used internally by upgrade code in Bugzilla::Field. +sub _set_type { $_[0]->set('type', $_[1]); } + =pod =head2 Instance Method @@ -766,6 +791,7 @@ sub populate_field_definitions { if ($field) { $field->set_description($def->{desc}); $field->set_in_new_bugmail($def->{in_new_bugmail}); + $field->_set_type($def->{type}) if $def->{type}; $field->update(); } else { @@ -773,8 +799,7 @@ sub populate_field_definitions { $def->{mailhead} = $def->{in_new_bugmail}; delete $def->{in_new_bugmail}; } - $def->{description} = $def->{desc}; - delete $def->{desc}; + $def->{description} = delete $def->{desc}; Bugzilla::Field->create($def); } } diff --git a/editvalues.cgi b/editvalues.cgi index 85d4c9761..338245284 100755 --- a/editvalues.cgi +++ b/editvalues.cgi @@ -29,18 +29,6 @@ use Bugzilla::Token; use Bugzilla::Field; use Bugzilla::Field::Choice; -# List of different tables that contain the changeable field values -# (the old "enums.") Keep them in alphabetical order by their -# English name from field-descs.html.tmpl. -# Format: Array of valid field names. -my @valid_fields = ('op_sys', 'rep_platform', 'priority', 'bug_severity', - 'bug_status', 'resolution'); - -# Add custom select fields. -my @custom_fields = Bugzilla->get_fields( - {custom => 1, type => [FIELD_TYPE_SINGLE_SELECT, FIELD_TYPE_MULTI_SELECT]}); -push(@valid_fields, map { $_->name } @custom_fields); - ############### # Subroutines # ############### @@ -87,8 +75,7 @@ my $token = $cgi->param('token'); # field = '' -> Show nice list of fields # if (!$cgi->param('field')) { - # Convert @valid_fields into the format that select-field wants. - my @field_list = map({ name => $_ }, @valid_fields); + my @field_list = Bugzilla->get_fields({ is_select => 1 }); $vars->{'fields'} = \@field_list; $template->process("admin/fieldvalues/select-field.html.tmpl", $vars) @@ -98,7 +85,7 @@ if (!$cgi->param('field')) { # At this point, the field must be defined. my $field = Bugzilla::Field->check($cgi->param('field')); -if (!grep($_ eq $field->name, @valid_fields)) { +if (!$field->is_select) { ThrowUserError('fieldname_invalid', { field => $field }); } $vars->{'field'} = $field; diff --git a/template/en/default/admin/custom_fields/cf-js.js.tmpl b/template/en/default/admin/custom_fields/cf-js.js.tmpl index 863f14dca..bf72ff998 100644 --- a/template/en/default/admin/custom_fields/cf-js.js.tmpl +++ b/template/en/default/admin/custom_fields/cf-js.js.tmpl @@ -24,8 +24,7 @@ function toggleCheckbox(this_checkbox, other_checkbox_id) { } var select_values = new Array(); -[% FOREACH sel_field = Bugzilla.active_custom_fields %] - [% NEXT IF !sel_field.is_select %] +[% FOREACH sel_field = Bugzilla.get_fields({ is_select => 1 }) %] select_values[[% sel_field.id FILTER js %]] = [ [% FOREACH legal_value = sel_field.legal_values %] [[% legal_value.id FILTER js %], '[% legal_value.name FILTER html %]'], diff --git a/template/en/default/admin/custom_fields/create.html.tmpl b/template/en/default/admin/custom_fields/create.html.tmpl index da10c7bcb..17bd5bfdc 100644 --- a/template/en/default/admin/custom_fields/create.html.tmpl +++ b/template/en/default/admin/custom_fields/create.html.tmpl @@ -99,8 +99,7 @@ - [% FOREACH sel_field = Bugzilla.active_custom_fields %] - [% NEXT IF !sel_field.is_select || sel_field.id == field.id %] + [% FOREACH sel_field = Bugzilla.get_fields({ is_select => 1 }) %] + [% NEXT IF sel_field.id == field.id %]