Commit a9822cee authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 458436: Allow standard global select fields to control visibility of custom fields

Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=bbaetz, a=mkanat
parent 5323ab05
...@@ -125,6 +125,8 @@ use constant UPDATE_COLUMNS => qw( ...@@ -125,6 +125,8 @@ use constant UPDATE_COLUMNS => qw(
enter_bug enter_bug
visibility_field_id visibility_field_id
visibility_value_id visibility_value_id
type
); );
# How various field types translate into SQL data definitions. # How various field types translate into SQL data definitions.
...@@ -148,16 +150,22 @@ use constant DEFAULT_FIELDS => ( ...@@ -148,16 +150,22 @@ use constant DEFAULT_FIELDS => (
{name => 'classification', desc => 'Classification', in_new_bugmail => 1}, {name => 'classification', desc => 'Classification', in_new_bugmail => 1},
{name => 'product', desc => 'Product', in_new_bugmail => 1}, {name => 'product', desc => 'Product', in_new_bugmail => 1},
{name => 'version', desc => 'Version', 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 => 'bug_file_loc', desc => 'URL', in_new_bugmail => 1},
{name => 'op_sys', desc => 'OS/Version', in_new_bugmail => 1}, {name => 'op_sys', desc => 'OS/Version', in_new_bugmail => 1,
{name => 'bug_status', desc => 'Status', 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', {name => 'status_whiteboard', desc => 'Status Whiteboard',
in_new_bugmail => 1}, in_new_bugmail => 1},
{name => 'keywords', desc => 'Keywords', in_new_bugmail => 1}, {name => 'keywords', desc => 'Keywords', in_new_bugmail => 1},
{name => 'resolution', desc => 'Resolution'}, {name => 'resolution', desc => 'Resolution',
{name => 'bug_severity', desc => 'Severity', in_new_bugmail => 1}, type => FIELD_TYPE_SINGLE_SELECT},
{name => 'priority', desc => 'Priority', in_new_bugmail => 1}, {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 => 'component', desc => 'Component', in_new_bugmail => 1},
{name => 'assigned_to', desc => 'AssignedTo', in_new_bugmail => 1}, {name => 'assigned_to', desc => 'AssignedTo', in_new_bugmail => 1},
{name => 'reporter', desc => 'ReportedBy', in_new_bugmail => 1}, {name => 'reporter', desc => 'ReportedBy', in_new_bugmail => 1},
...@@ -200,6 +208,20 @@ use constant DEFAULT_FIELDS => ( ...@@ -200,6 +208,20 @@ use constant DEFAULT_FIELDS => (
{name => "owner_idle_time", desc => "Time Since Assignee Touched"}, {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 # # Validators #
############## ##############
...@@ -551,6 +573,9 @@ sub set_visibility_value { ...@@ -551,6 +573,9 @@ sub set_visibility_value {
delete $self->{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 =pod
=head2 Instance Method =head2 Instance Method
...@@ -766,6 +791,7 @@ sub populate_field_definitions { ...@@ -766,6 +791,7 @@ sub populate_field_definitions {
if ($field) { if ($field) {
$field->set_description($def->{desc}); $field->set_description($def->{desc});
$field->set_in_new_bugmail($def->{in_new_bugmail}); $field->set_in_new_bugmail($def->{in_new_bugmail});
$field->_set_type($def->{type}) if $def->{type};
$field->update(); $field->update();
} }
else { else {
...@@ -773,8 +799,7 @@ sub populate_field_definitions { ...@@ -773,8 +799,7 @@ sub populate_field_definitions {
$def->{mailhead} = $def->{in_new_bugmail}; $def->{mailhead} = $def->{in_new_bugmail};
delete $def->{in_new_bugmail}; delete $def->{in_new_bugmail};
} }
$def->{description} = $def->{desc}; $def->{description} = delete $def->{desc};
delete $def->{desc};
Bugzilla::Field->create($def); Bugzilla::Field->create($def);
} }
} }
......
...@@ -29,18 +29,6 @@ use Bugzilla::Token; ...@@ -29,18 +29,6 @@ use Bugzilla::Token;
use Bugzilla::Field; use Bugzilla::Field;
use Bugzilla::Field::Choice; 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 # # Subroutines #
############### ###############
...@@ -87,8 +75,7 @@ my $token = $cgi->param('token'); ...@@ -87,8 +75,7 @@ my $token = $cgi->param('token');
# field = '' -> Show nice list of fields # field = '' -> Show nice list of fields
# #
if (!$cgi->param('field')) { if (!$cgi->param('field')) {
# Convert @valid_fields into the format that select-field wants. my @field_list = Bugzilla->get_fields({ is_select => 1 });
my @field_list = map({ name => $_ }, @valid_fields);
$vars->{'fields'} = \@field_list; $vars->{'fields'} = \@field_list;
$template->process("admin/fieldvalues/select-field.html.tmpl", $vars) $template->process("admin/fieldvalues/select-field.html.tmpl", $vars)
...@@ -98,7 +85,7 @@ if (!$cgi->param('field')) { ...@@ -98,7 +85,7 @@ if (!$cgi->param('field')) {
# At this point, the field must be defined. # At this point, the field must be defined.
my $field = Bugzilla::Field->check($cgi->param('field')); my $field = Bugzilla::Field->check($cgi->param('field'));
if (!grep($_ eq $field->name, @valid_fields)) { if (!$field->is_select) {
ThrowUserError('fieldname_invalid', { field => $field }); ThrowUserError('fieldname_invalid', { field => $field });
} }
$vars->{'field'} = $field; $vars->{'field'} = $field;
......
...@@ -24,8 +24,7 @@ function toggleCheckbox(this_checkbox, other_checkbox_id) { ...@@ -24,8 +24,7 @@ function toggleCheckbox(this_checkbox, other_checkbox_id) {
} }
var select_values = new Array(); var select_values = new Array();
[% FOREACH sel_field = Bugzilla.active_custom_fields %] [% FOREACH sel_field = Bugzilla.get_fields({ is_select => 1 }) %]
[% NEXT IF !sel_field.is_select %]
select_values[[% sel_field.id FILTER js %]] = [ select_values[[% sel_field.id FILTER js %]] = [
[% FOREACH legal_value = sel_field.legal_values %] [% FOREACH legal_value = sel_field.legal_values %]
[[% legal_value.id FILTER js %], '[% legal_value.name FILTER html %]'], [[% legal_value.id FILTER js %], '[% legal_value.name FILTER html %]'],
......
...@@ -99,8 +99,7 @@ ...@@ -99,8 +99,7 @@
<select name="visibility_field_id" id="visibility_field_id" <select name="visibility_field_id" id="visibility_field_id"
onchange="onChangeVisibilityField()"> onchange="onChangeVisibilityField()">
<option></option> <option></option>
[% FOREACH sel_field = Bugzilla.active_custom_fields %] [% FOREACH sel_field = Bugzilla.get_fields({ is_select => 1 }) %]
[% NEXT IF !sel_field.is_select %]
<option value="[% sel_field.id FILTER html %]"> <option value="[% sel_field.id FILTER html %]">
[% sel_field.description FILTER html %] [% sel_field.description FILTER html %]
([% sel_field.name FILTER html %]) ([% sel_field.name FILTER html %])
......
...@@ -84,8 +84,8 @@ ...@@ -84,8 +84,8 @@
<select name="visibility_field_id" id="visibility_field_id" <select name="visibility_field_id" id="visibility_field_id"
onchange="onChangeVisibilityField()"> onchange="onChangeVisibilityField()">
<option></option> <option></option>
[% FOREACH sel_field = Bugzilla.active_custom_fields %] [% FOREACH sel_field = Bugzilla.get_fields({ is_select => 1 }) %]
[% NEXT IF !sel_field.is_select || sel_field.id == field.id %] [% NEXT IF sel_field.id == field.id %]
<option value="[% sel_field.id FILTER html %]" <option value="[% sel_field.id FILTER html %]"
[% ' selected="selected"' [% ' selected="selected"'
IF sel_field.id == field.visibility_field.id %]> IF sel_field.id == field.visibility_field.id %]>
......
...@@ -162,6 +162,14 @@ function handleWantsAttachment(wants_attachment) { ...@@ -162,6 +162,14 @@ function handleWantsAttachment(wants_attachment) {
--> -->
</script> </script>
[% USE Bugzilla %]
[% SET select_fields = {} %]
[% FOREACH field = Bugzilla.get_fields(
{ type => constants.FIELD_TYPE_SINGLE_SELECT, custom => 0 })
%]
[% select_fields.${field.name} = field %]
[% END %]
<form name="Create" id="Create" method="post" action="post_bug.cgi" <form name="Create" id="Create" method="post" action="post_bug.cgi"
enctype="multipart/form-data"> enctype="multipart/form-data">
<input type="hidden" name="product" value="[% product.name FILTER html %]"> <input type="hidden" name="product" value="[% product.name FILTER html %]">
...@@ -235,18 +243,21 @@ function handleWantsAttachment(wants_attachment) { ...@@ -235,18 +243,21 @@ function handleWantsAttachment(wants_attachment) {
</select> </select>
</td> </td>
[% sel = { description => 'Severity', name => 'bug_severity' } %] [% INCLUDE bug/field.html.tmpl
[% INCLUDE select %] bug = default, field = select_fields.bug_severity, editable = 1,
value = default.bug_severity %]
</tr> </tr>
<tr> <tr>
[% sel = { description => 'Platform', name => 'rep_platform' } %] [% INCLUDE bug/field.html.tmpl
[% INCLUDE select %] bug = default, field = select_fields.rep_platform, editable = 1,
value = default.rep_platform %]
</tr> </tr>
<tr> <tr>
[% sel = { description => 'OS', name => 'op_sys' } %] [% INCLUDE bug/field.html.tmpl
[% INCLUDE select %] bug = default, field = select_fields.op_sys, editable = 1,
value = default.op_sys %]
</tr> </tr>
</tbody> </tbody>
...@@ -260,12 +271,11 @@ function handleWantsAttachment(wants_attachment) { ...@@ -260,12 +271,11 @@ function handleWantsAttachment(wants_attachment) {
[% END %] [% END %]
[% IF Param('letsubmitterchoosepriority') %] [% IF Param('letsubmitterchoosepriority') %]
[% sel = { description => 'Priority', name => 'priority' } %] [% INCLUDE bug/field.html.tmpl
[% INCLUDE select %] bug = default, field = select_fields.priority, editable = 1,
value = default.priority %]
[% ELSE %] [% ELSE %]
<td colspan="2"> <td colspan="2">&nbsp;</td>
<input type="hidden" name="priority" value="[% default.priority FILTER html %]">
</td>
[% END %] [% END %]
</tr> </tr>
</tbody> </tbody>
...@@ -437,7 +447,9 @@ function handleWantsAttachment(wants_attachment) { ...@@ -437,7 +447,9 @@ function handleWantsAttachment(wants_attachment) {
[% NEXT UNLESS field.enter_bug %] [% NEXT UNLESS field.enter_bug %]
[% SET value = ${field.name}.defined ? ${field.name} : "" %] [% SET value = ${field.name}.defined ? ${field.name} : "" %]
<tr> <tr>
[% PROCESS bug/field.html.tmpl editable=1 value_span=3 %] [% INCLUDE bug/field.html.tmpl
bug = default, field = field, value = value, editable = 1,
value_span = 3 %]
</tr> </tr>
[% END %] [% END %]
...@@ -617,7 +629,7 @@ function handleWantsAttachment(wants_attachment) { ...@@ -617,7 +629,7 @@ function handleWantsAttachment(wants_attachment) {
[% END %] [% END %]
<td> <td>
<select name="[% sel.name %]"> <select name="[% sel.name %]" id="[% sel.name %]">
[%- FOREACH x = ${sel.name} %] [%- FOREACH x = ${sel.name} %]
<option value="[% x FILTER html %]" <option value="[% x FILTER html %]"
[% " selected=\"selected\"" IF x == default.${sel.name} %]> [% " selected=\"selected\"" IF x == default.${sel.name} %]>
...@@ -628,5 +640,15 @@ function handleWantsAttachment(wants_attachment) { ...@@ -628,5 +640,15 @@ function handleWantsAttachment(wants_attachment) {
[% END %]</option> [% END %]</option>
[% END %] [% END %]
</select> </select>
[% IF sel.name == "bug_status" %]
[% FOREACH controlled = select_fields.bug_status.controls_visibility_of %]
<script type="text/javascript">
showFieldWhen('[% controlled.name FILTER js %]',
'bug_status',
'[% controlled.visibility_value.name FILTER js %]');
</script>
[% END %]
[% END %]
</td> </td>
[% END %] [% END %]
...@@ -30,6 +30,14 @@ ...@@ -30,6 +30,14 @@
[% PROCESS bug/time.html.tmpl %] [% PROCESS bug/time.html.tmpl %]
[% USE Bugzilla %]
[% SET select_fields = {} %]
[% FOREACH field = Bugzilla.get_fields(
{ type => constants.FIELD_TYPE_SINGLE_SELECT, custom => 0 })
%]
[% select_fields.${field.name} = field %]
[% END %]
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
...@@ -390,9 +398,15 @@ ...@@ -390,9 +398,15 @@
<td class="field_label"> <td class="field_label">
<label for="rep_platform" accesskey="h"><b>Platform</b></label>: <label for="rep_platform" accesskey="h"><b>Platform</b></label>:
</td> </td>
<td> <td class="field_value">
[% PROCESS select selname => "rep_platform" no_td=> 1 %] [% INCLUDE bug/field.html.tmpl
[%+ PROCESS select selname => "op_sys" no_td=> 1 %] bug = bug, field = select_fields.rep_platform,
no_tds = 1, value = bug.rep_platform
editable = bug.check_can_change_field('rep_platform', 0, 1) %]
[%+ INCLUDE bug/field.html.tmpl
bug = bug, field = select_fields.op_sys,
no_tds = 1, value = bug.op_sys
editable = bug.check_can_change_field('op_sys', 0, 1) %]
<script type="text/javascript"> <script type="text/javascript">
assignToDefaultOnChange(['product', 'component']); assignToDefaultOnChange(['product', 'component']);
</script> </script>
...@@ -433,8 +447,14 @@ ...@@ -433,8 +447,14 @@
<b><a href="page.cgi?id=fields.html#importance"><u>I</u>mportance</a></b></label>: <b><a href="page.cgi?id=fields.html#importance"><u>I</u>mportance</a></b></label>:
</td> </td>
<td> <td>
[% PROCESS select selname => "priority" no_td=>1 %] [% INCLUDE bug/field.html.tmpl
[% PROCESS select selname = "bug_severity" no_td=>1 %] bug = bug, field = select_fields.priority,
no_tds = 1, value = bug.priority
editable = bug.check_can_change_field('priority', 0, 1) %]
[%+ INCLUDE bug/field.html.tmpl
bug = bug, field = select_fields.bug_severity,
no_tds = 1, value = bug.bug_severity
editable = bug.check_can_change_field('bug_severity', 0, 1) %]
[% IF bug.use_votes %] [% IF bug.use_votes %]
<span id="votes_container"> <span id="votes_container">
[% IF bug.votes %] [% IF bug.votes %]
...@@ -915,7 +935,6 @@ ...@@ -915,7 +935,6 @@
[% BLOCK section_customfields %] [% BLOCK section_customfields %]
[%# *** Custom Fields *** %] [%# *** Custom Fields *** %]
[% USE Bugzilla %]
[% FOREACH field = Bugzilla.active_custom_fields %] [% FOREACH field = Bugzilla.active_custom_fields %]
<tr> <tr>
[% PROCESS bug/field.html.tmpl value=bug.${field.name} [% PROCESS bug/field.html.tmpl value=bug.${field.name}
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
# allow_dont_change: display the --do_not_change-- option for select fields. # allow_dont_change: display the --do_not_change-- option for select fields.
# value_span: A colspan for the table cell containing # value_span: A colspan for the table cell containing
# the field value. # the field value.
# no_tds: boolean; if true, don't display the label <th> or the
# wrapping <td> for the field.
# bug (optional): The current Bugzilla::Bug being displayed, or a hash # bug (optional): The current Bugzilla::Bug being displayed, or a hash
# with default field values being displayed on a page. # with default field values being displayed on a page.
#%] #%]
...@@ -41,18 +43,28 @@ ...@@ -41,18 +43,28 @@
[% END %] [% END %]
[% END %] [% END %]
<th class="field_label [% ' bz_hidden_field' IF hidden %]" [% IF NOT no_tds %]
id="field_label_[% field.name FILTER html %]"> <th class="field_label [% ' bz_hidden_field' IF hidden %]"
[% IF editable %] id="field_label_[% field.name FILTER html %]">
<label for="[% field.name FILTER html %]"> [% IF editable %]
[% END %] <label for="[% field.name FILTER html %]">
[% field_descs.${field.name} FILTER html %]: [% END %]
[% '</label>' IF editable %] [% IF !field.custom %]
</th> <a href="page.cgi?id=fields.html#[% field.name FILTER url_quote %]">
[% END -%]
[% field_descs.${field.name} FILTER html %]:
[%- IF !field.custom %]
</a>
[% END %]
[% '</label>' IF editable %]
</th>
[% END %]
[% IF NOT no_tds %]
<td class="field_value [% ' bz_hidden_field' IF hidden %]" <td class="field_value [% ' bz_hidden_field' IF hidden %]"
id="field_container_[% field.name FILTER html %]" id="field_container_[% field.name FILTER html %]"
[% " colspan=\"$value_span\"" FILTER none IF value_span %]> [% " colspan=\"$value_span\"" FILTER none IF value_span %]>
[% END %]
[% IF editable %] [% IF editable %]
[% SWITCH field.type %] [% SWITCH field.type %]
[% CASE constants.FIELD_TYPE_FREETEXT %] [% CASE constants.FIELD_TYPE_FREETEXT %]
...@@ -153,4 +165,4 @@ ...@@ -153,4 +165,4 @@
[% ELSE %] [% ELSE %]
[% value.join(', ') FILTER html %] [% value.join(', ') FILTER html %]
[% END %] [% END %]
</td> [% '</td>' IF NOT no_tds %]
...@@ -120,6 +120,17 @@ ...@@ -120,6 +120,17 @@
YAHOO.util.Event.addListener( window, 'load', showHideStatusItems, YAHOO.util.Event.addListener( window, 'load', showHideStatusItems,
['[% "is_duplicate" IF bug.dup_id %]', ['[% "is_duplicate" IF bug.dup_id %]',
'[% bug.bug_status FILTER js %]'] ); '[% bug.bug_status FILTER js %]'] );
[% FOREACH controlled = select_fields.bug_status.controls_visibility_of %]
showFieldWhen('[% controlled.name FILTER js %]',
'bug_status',
'[% controlled.visibility_value.name FILTER js %]');
[% END %]
[% FOREACH controlled = select_fields.resolution.controls_visibility_of %]
showFieldWhen('[% controlled.name FILTER js %]',
'resolution',
'[% controlled.visibility_value.name FILTER js %]');
[% END %]
</script> </script>
[%# Common actions %] [%# Common actions %]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment