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(
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);
}
}
......
......@@ -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;
......
......@@ -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 %]'],
......
......@@ -99,8 +99,7 @@
<select name="visibility_field_id" id="visibility_field_id"
onchange="onChangeVisibilityField()">
<option></option>
[% FOREACH sel_field = Bugzilla.active_custom_fields %]
[% NEXT IF !sel_field.is_select %]
[% FOREACH sel_field = Bugzilla.get_fields({ is_select => 1 }) %]
<option value="[% sel_field.id FILTER html %]">
[% sel_field.description FILTER html %]
([% sel_field.name FILTER html %])
......
......@@ -84,8 +84,8 @@
<select name="visibility_field_id" id="visibility_field_id"
onchange="onChangeVisibilityField()">
<option></option>
[% 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 %]
<option value="[% sel_field.id FILTER html %]"
[% ' selected="selected"'
IF sel_field.id == field.visibility_field.id %]>
......
......@@ -162,6 +162,14 @@ function handleWantsAttachment(wants_attachment) {
-->
</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"
enctype="multipart/form-data">
<input type="hidden" name="product" value="[% product.name FILTER html %]">
......@@ -235,18 +243,21 @@ function handleWantsAttachment(wants_attachment) {
</select>
</td>
[% sel = { description => 'Severity', name => 'bug_severity' } %]
[% INCLUDE select %]
[% INCLUDE bug/field.html.tmpl
bug = default, field = select_fields.bug_severity, editable = 1,
value = default.bug_severity %]
</tr>
<tr>
[% sel = { description => 'Platform', name => 'rep_platform' } %]
[% INCLUDE select %]
[% INCLUDE bug/field.html.tmpl
bug = default, field = select_fields.rep_platform, editable = 1,
value = default.rep_platform %]
</tr>
<tr>
[% sel = { description => 'OS', name => 'op_sys' } %]
[% INCLUDE select %]
[% INCLUDE bug/field.html.tmpl
bug = default, field = select_fields.op_sys, editable = 1,
value = default.op_sys %]
</tr>
</tbody>
......@@ -260,12 +271,11 @@ function handleWantsAttachment(wants_attachment) {
[% END %]
[% IF Param('letsubmitterchoosepriority') %]
[% sel = { description => 'Priority', name => 'priority' } %]
[% INCLUDE select %]
[% INCLUDE bug/field.html.tmpl
bug = default, field = select_fields.priority, editable = 1,
value = default.priority %]
[% ELSE %]
<td colspan="2">
<input type="hidden" name="priority" value="[% default.priority FILTER html %]">
</td>
<td colspan="2">&nbsp;</td>
[% END %]
</tr>
</tbody>
......@@ -437,7 +447,9 @@ function handleWantsAttachment(wants_attachment) {
[% NEXT UNLESS field.enter_bug %]
[% SET value = ${field.name}.defined ? ${field.name} : "" %]
<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>
[% END %]
......@@ -617,7 +629,7 @@ function handleWantsAttachment(wants_attachment) {
[% END %]
<td>
<select name="[% sel.name %]">
<select name="[% sel.name %]" id="[% sel.name %]">
[%- FOREACH x = ${sel.name} %]
<option value="[% x FILTER html %]"
[% " selected=\"selected\"" IF x == default.${sel.name} %]>
......@@ -628,5 +640,15 @@ function handleWantsAttachment(wants_attachment) {
[% END %]</option>
[% END %]
</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>
[% END %]
......@@ -30,6 +30,14 @@
[% 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">
<!--
......@@ -390,9 +398,15 @@
<td class="field_label">
<label for="rep_platform" accesskey="h"><b>Platform</b></label>:
</td>
<td>
[% PROCESS select selname => "rep_platform" no_td=> 1 %]
[%+ PROCESS select selname => "op_sys" no_td=> 1 %]
<td class="field_value">
[% INCLUDE bug/field.html.tmpl
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">
assignToDefaultOnChange(['product', 'component']);
</script>
......@@ -433,8 +447,14 @@
<b><a href="page.cgi?id=fields.html#importance"><u>I</u>mportance</a></b></label>:
</td>
<td>
[% PROCESS select selname => "priority" no_td=>1 %]
[% PROCESS select selname = "bug_severity" no_td=>1 %]
[% INCLUDE bug/field.html.tmpl
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 %]
<span id="votes_container">
[% IF bug.votes %]
......@@ -915,7 +935,6 @@
[% BLOCK section_customfields %]
[%# *** Custom Fields *** %]
[% USE Bugzilla %]
[% FOREACH field = Bugzilla.active_custom_fields %]
<tr>
[% PROCESS bug/field.html.tmpl value=bug.${field.name}
......
......@@ -28,6 +28,8 @@
# allow_dont_change: display the --do_not_change-- option for select fields.
# value_span: A colspan for the table cell containing
# 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
# with default field values being displayed on a page.
#%]
......@@ -41,18 +43,28 @@
[% END %]
[% END %]
<th class="field_label [% ' bz_hidden_field' IF hidden %]"
id="field_label_[% field.name FILTER html %]">
[% IF editable %]
<label for="[% field.name FILTER html %]">
[% END %]
[% field_descs.${field.name} FILTER html %]:
[% '</label>' IF editable %]
</th>
[% IF NOT no_tds %]
<th class="field_label [% ' bz_hidden_field' IF hidden %]"
id="field_label_[% field.name FILTER html %]">
[% IF editable %]
<label for="[% field.name FILTER html %]">
[% END %]
[% IF !field.custom %]
<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 %]"
id="field_container_[% field.name FILTER html %]"
[% " colspan=\"$value_span\"" FILTER none IF value_span %]>
[% END %]
[% IF editable %]
[% SWITCH field.type %]
[% CASE constants.FIELD_TYPE_FREETEXT %]
......@@ -153,4 +165,4 @@
[% ELSE %]
[% value.join(', ') FILTER html %]
[% END %]
</td>
[% '</td>' IF NOT no_tds %]
......@@ -120,6 +120,17 @@
YAHOO.util.Event.addListener( window, 'load', showHideStatusItems,
['[% "is_duplicate" IF bug.dup_id %]',
'[% 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>
[%# 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