From 63be194996849202878c4a87e4c68a25d1976d3e Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Fri, 7 Nov 2008 17:34:39 +0000 Subject: Bug 308253: Ability to add select (enum) fields to a bug whose list of values depends on the value of another field Patch By Max Kanat-Alexander r=bbaetz, a=mkanat --- .../en/default/admin/custom_fields/cf-js.js.tmpl | 12 ++++++++ .../default/admin/custom_fields/create.html.tmpl | 24 ++++++++++++++- .../en/default/admin/custom_fields/edit.html.tmpl | 24 ++++++++++++++- .../admin/fieldvalues/confirm-delete.html.tmpl | 17 +++++++++- .../en/default/admin/fieldvalues/create.html.tmpl | 21 +++++++++++++ .../en/default/admin/fieldvalues/edit.html.tmpl | 27 +++++++++++++++- template/en/default/bug/create/create.html.tmpl | 11 +++---- template/en/default/bug/field-events.js.tmpl | 36 ++++++++++++++++++++++ template/en/default/bug/field.html.tmpl | 32 ++++++++++++------- template/en/default/bug/knob.html.tmpl | 12 ++------ template/en/default/global/messages.html.tmpl | 11 +++++++ template/en/default/global/user-error.html.tmpl | 24 +++++++++++++-- 12 files changed, 217 insertions(+), 34 deletions(-) create mode 100644 template/en/default/bug/field-events.js.tmpl (limited to 'template') 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 bf72ff998..6c5bbf626 100644 --- a/template/en/default/admin/custom_fields/cf-js.js.tmpl +++ b/template/en/default/admin/custom_fields/cf-js.js.tmpl @@ -32,6 +32,18 @@ var select_values = new Array(); ]; [% END %] +function onChangeType(type_field) { + var value_field = document.getElementById('value_field_id'); + if (type_field.value == [% constants.FIELD_TYPE_SINGLE_SELECT %] + || type_field.value == [% constants.FIELD_TYPE_MULTI_SELECT %]) + { + value_field.disabled = false; + } + else { + value_field.disabled = true; + } +} + function onChangeVisibilityField() { var vis_field = document.getElementById('visibility_field_id'); var vis_value = document.getElementById('visibility_value_id'); diff --git a/template/en/default/admin/custom_fields/create.html.tmpl b/template/en/default/admin/custom_fields/create.html.tmpl index 17bd5bfdc..a2db4708b 100644 --- a/template/en/default/admin/custom_fields/create.html.tmpl +++ b/template/en/default/admin/custom_fields/create.html.tmpl @@ -75,7 +75,7 @@ - [% FOREACH type = field_types.keys %] [% NEXT IF type == constants.FIELD_TYPE_UNKNOWN %] @@ -112,6 +112,28 @@ + + +   + + + + + + + +

diff --git a/template/en/default/admin/custom_fields/edit.html.tmpl b/template/en/default/admin/custom_fields/edit.html.tmpl index 3d7355a77..b6a8ae9bd 100644 --- a/template/en/default/admin/custom_fields/edit.html.tmpl +++ b/template/en/default/admin/custom_fields/edit.html.tmpl @@ -109,10 +109,32 @@ [% IF field.is_select %]   - + Edit legal values for this field. + + + + + + + + [% END %] diff --git a/template/en/default/admin/fieldvalues/confirm-delete.html.tmpl b/template/en/default/admin/fieldvalues/confirm-delete.html.tmpl index 2389fb6ae..b215edf04 100644 --- a/template/en/default/admin/fieldvalues/confirm-delete.html.tmpl +++ b/template/en/default/admin/fieldvalues/confirm-delete.html.tmpl @@ -62,7 +62,8 @@

Confirmation

[% IF value.is_default || value.bug_count || (value_count == 1) - || value.controls_visibility_of_fields.size + || value.controls_visibility_of_fields.size + || value.controlled_values.size %]

Sorry, but the '[% value.name FILTER html %]' value cannot be deleted @@ -121,6 +122,20 @@ [% END %] [% END %] + + [% IF value.controlled_values.size %] +

  • This value controls the visibility of the following values in + other fields:
    + [% FOREACH controlled = value.controlled_values %] + + [% controlled.field.description FILTER html %] + ([% controlled.field.name FILTER html %]): + [%+ controlled.name FILTER html %]
    + [% END %] +
  • + [% END %] [% ELSE %] diff --git a/template/en/default/admin/fieldvalues/create.html.tmpl b/template/en/default/admin/fieldvalues/create.html.tmpl index bd6c427e6..f1eec1a5a 100644 --- a/template/en/default/admin/fieldvalues/create.html.tmpl +++ b/template/en/default/admin/fieldvalues/create.html.tmpl @@ -62,6 +62,27 @@ [% END %] + [% IF field.value_field %] + + + + + + + (Leave unset to have this value always appear.) + + + [% END %] diff --git a/template/en/default/admin/fieldvalues/edit.html.tmpl b/template/en/default/admin/fieldvalues/edit.html.tmpl index f12383866..b01415577 100644 --- a/template/en/default/admin/fieldvalues/edit.html.tmpl +++ b/template/en/default/admin/fieldvalues/edit.html.tmpl @@ -32,7 +32,9 @@ - + [% END %] + [% IF field.value_field %] + + + + + [% END %]
    + + [% IF value.is_static %] [% IF value.is_open %]Open[% ELSE %]Closed[% END %]
    + + + + (Leave unset to have this value always appear.) +
    diff --git a/template/en/default/bug/create/create.html.tmpl b/template/en/default/bug/create/create.html.tmpl index 0b941cc35..089292603 100644 --- a/template/en/default/bug/create/create.html.tmpl +++ b/template/en/default/bug/create/create.html.tmpl @@ -642,13 +642,12 @@ function handleWantsAttachment(wants_attachment) { [% IF sel.name == "bug_status" %] - [% FOREACH controlled = select_fields.bug_status.controls_visibility_of %] - - [% END %] [% END %] [% END %] diff --git a/template/en/default/bug/field-events.js.tmpl b/template/en/default/bug/field-events.js.tmpl new file mode 100644 index 000000000..7cdf64687 --- /dev/null +++ b/template/en/default/bug/field-events.js.tmpl @@ -0,0 +1,36 @@ +[%# The contents of this file are subject to the Mozilla Public + # License Version 1.1 (the "License"); you may not use this file + # except in compliance with the License. You may obtain a copy of + # the License at http://www.mozilla.org/MPL/ + # + # Software distributed under the License is distributed on an "AS + # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + # implied. See the License for the specific language governing + # rights and limitations under the License. + # + # The Original Code is the Bugzilla Bug Tracking System. + # + # The Initial Developer of the Original Code is the San Jose State + # University Foundation. Portions created by the Initial Developer + # are Copyright (C) 2008 the Initial Developer. All Rights Reserved. + # + # Contributor(s): Max Kanat-Alexander + #%] + +[%# INTERFACE: + # field: a Bugzilla::Field object + #%] + +[% FOREACH controlled_field = field.controls_visibility_of %] + showFieldWhen('[% controlled_field.name FILTER js %]', + '[% field.name FILTER js %]', + '[% controlled_field.visibility_value.name FILTER js %]'); +[% END %] +[% FOREACH legal_value = field.legal_values %] + [% FOREACH controlled_value = legal_value.controlled_values %] + showValueWhen('[% controlled_value.field.name FILTER js %]', + '[% controlled_value.name FILTER js %]', + '[% field.name FILTER js %]', + '[% legal_value.name FILTER js %]'); + [% END %] +[% END %] diff --git a/template/en/default/bug/field.html.tmpl b/template/en/default/bug/field.html.tmpl index 9b93a9ff2..d29aaa305 100644 --- a/template/en/default/bug/field.html.tmpl +++ b/template/en/default/bug/field.html.tmpl @@ -126,10 +126,20 @@ [% END %] [% FOREACH legal_value = field.legal_values %] + [% SET control_value = legal_value.visibility_value %] + [% SET control_field = field.value_field %] + [%# We always show selected values, even if they should be + # hidden %] + [% IF value.contains(legal_value.name).size %] + selected="selected" + [% ELSIF control_field && control_value + && !bug.${control_field.name}.contains(control_value.name) + %] + class="bz_hidden_option" disabled="disabled" + [% END %]> + [%- legal_value.name FILTER html -%] + [% END %] [%# When you pass an empty multi-select in the web interface, @@ -142,19 +152,19 @@ [% IF field.type == constants.FIELD_TYPE_MULTI_SELECT %] [% END %] + + + [% CASE constants.FIELD_TYPE_TEXTAREA %] [% INCLUDE global/textarea.html.tmpl id = field.name name = field.name minrows = 4 maxrows = 8 cols = 60 defaultcontent = value %] [% END %] - - [% FOREACH controlled_field = field.controls_visibility_of %] - - [% END %] [% ELSIF field.type == constants.FIELD_TYPE_TEXTAREA %]
    [% value FILTER wrap_comment(60) FILTER html %]
    diff --git a/template/en/default/bug/knob.html.tmpl b/template/en/default/bug/knob.html.tmpl index 038e6cbb3..be94559aa 100644 --- a/template/en/default/bug/knob.html.tmpl +++ b/template/en/default/bug/knob.html.tmpl @@ -122,16 +122,8 @@ ['[% "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 %] + [% INCLUDE "bug/field-events.js.tmpl" field = select_fields.bug_status %] + [% INCLUDE "bug/field-events.js.tmpl" field = select_fields.resolution %] [%# Common actions %] diff --git a/template/en/default/global/messages.html.tmpl b/template/en/default/global/messages.html.tmpl index d7de4fbc7..1a9c7220a 100644 --- a/template/en/default/global/messages.html.tmpl +++ b/template/en/default/global/messages.html.tmpl @@ -332,6 +332,17 @@
  • Sortkey updated to [% changes.sortkey.1 FILTER html %].
  • [% END %] + [% IF changes.visibility_value_id %] + [% IF value.visibility_value.defined %] +
  • It only appears when + [%+ value.field.value_field.description FILTER html %] is set to + '[%+ value.visibility_value.name FILTER html %]'.
  • + [% ELSE %] +
  • It now always appears, no matter what + [%+ value.field.value_field.description FILTER html %] is set to. +
  • + [% END %] + [% END %] [% ELSE %] No changes made to the field value [% value_old FILTER html %]. diff --git a/template/en/default/global/user-error.html.tmpl b/template/en/default/global/user-error.html.tmpl index 0936847f5..0b10b7396 100644 --- a/template/en/default/global/user-error.html.tmpl +++ b/template/en/default/global/user-error.html.tmpl @@ -412,7 +412,7 @@ [% ELSIF error == "field_control_must_be_select" %] [% title = "Invalid Field Type Selected" %] Only drop-down and multi-select fields can be used to control - the visibility of other fields. [% field.description FILTER html %] + the visibility/values of other fields. [% field.description FILTER html %] is not the right type of field. [% ELSIF error == "field_invalid_name" %] @@ -433,6 +433,11 @@ [% title = "Missing Name for Field" %] You must enter a name for this field. + [% ELSIF error == "field_value_control_select_only" %] + [% title = "Invalid Value Control Field" %] + Only Drop-Down or Multi-Select fields can have a field that + controls their values. + [% ELSIF error == "fieldname_invalid" %] [% title = "Specified Field Does Not Exist" %] The field '[% field.name FILTER html %]' does not exist or @@ -446,8 +451,21 @@ [% ELSIF error == "fieldvalue_is_controller" %] [% title = "Value Controls Other Fields" %] You cannot delete the '[% value.name FILTER html %]' value for this - field because it controls the visibility of the following other fields: - [%+ fields.join(', ') FILTER html %]. + field because + [% IF fields.size %] + it controls the visibility of the following fields: + [%+ fields.join(', ') FILTER html %]. + [% END %] + [% ' and ' IF fields.size AND vals.size %] + [% IF vals.size %] + it controls the visibility of the following field values: + + [% END %] [% ELSIF error == "fieldvalue_is_default" %] [% title = "Specified Field Value Is Default" %] -- cgit v1.2.3-24-g4f1b