From 3cea91884b28b52df4e38f2ba88c00b65071a81f Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Sat, 25 Oct 2008 04:11:30 +0000 Subject: Bug 291433: Ability to have custom fields whose visibility depends on the values of other fields Patch By Max Kanat-Alexander r=bbaetz, a=mkanat --- .../en/default/admin/custom_fields/cf-js.js.tmpl | 47 ++++++++++++++++++++ .../default/admin/custom_fields/create.html.tmpl | 37 +++++++++++----- .../en/default/admin/custom_fields/edit.html.tmpl | 51 +++++++++++++++------- .../admin/fieldvalues/confirm-delete.html.tmpl | 15 ++++++- 4 files changed, 121 insertions(+), 29 deletions(-) create mode 100644 template/en/default/admin/custom_fields/cf-js.js.tmpl (limited to 'template/en/default/admin') diff --git a/template/en/default/admin/custom_fields/cf-js.js.tmpl b/template/en/default/admin/custom_fields/cf-js.js.tmpl new file mode 100644 index 000000000..863f14dca --- /dev/null +++ b/template/en/default/admin/custom_fields/cf-js.js.tmpl @@ -0,0 +1,47 @@ +[%# 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 NASA. + # Portions created by NASA are Copyright (C) 2008 + # San Jose State University Foundation. All Rights Reserved. + # + # Contributor(s): Max Kanat-Alexander + #%] + +// Disable a checkbox based on the state of another one. +function toggleCheckbox(this_checkbox, other_checkbox_id) { + var other_checkbox = document.getElementById(other_checkbox_id); + other_checkbox.disabled = !this_checkbox.checked; +} + +var select_values = new Array(); +[% FOREACH sel_field = Bugzilla.active_custom_fields %] + [% NEXT IF !sel_field.is_select %] + select_values[[% sel_field.id FILTER js %]] = [ + [% FOREACH legal_value = sel_field.legal_values %] + [[% legal_value.id FILTER js %], '[% legal_value.name FILTER html %]'], + [% END %] + ]; +[% END %] + +function onChangeVisibilityField() { + var vis_field = document.getElementById('visibility_field_id'); + var vis_value = document.getElementById('visibility_value_id'); + + if (vis_field.value) { + var values = select_values[vis_field.value]; + bz_populateSelectFromArray(vis_value, values); + } + else { + bz_clearOptions(vis_value); + } +} diff --git a/template/en/default/admin/custom_fields/create.html.tmpl b/template/en/default/admin/custom_fields/create.html.tmpl index 5dd50ce3b..da10c7bcb 100644 --- a/template/en/default/admin/custom_fields/create.html.tmpl +++ b/template/en/default/admin/custom_fields/create.html.tmpl @@ -19,22 +19,17 @@ [% PROCESS "global/field-descs.none.tmpl" %] +[% javascript = BLOCK %] + [% INCLUDE "admin/custom_fields/cf-js.js.tmpl" %] +[% END %] + [% PROCESS global/header.html.tmpl title = "Add a new Custom Field" onload = "document.getElementById('new_bugmail').disabled = true;" + javascript_urls = [ 'js/util.js' ] doc_section = "custom-fields.html#add-custom-fields" %] - -

Adding custom fields can make the interface of [% terms.Bugzilla %] very complicated. Many admins who are new to [% terms.Bugzilla %] start off @@ -97,8 +92,26 @@ -   -   + + + + + + + +

diff --git a/template/en/default/admin/custom_fields/edit.html.tmpl b/template/en/default/admin/custom_fields/edit.html.tmpl index 02334ab13..2186c7562 100644 --- a/template/en/default/admin/custom_fields/edit.html.tmpl +++ b/template/en/default/admin/custom_fields/edit.html.tmpl @@ -14,7 +14,7 @@ #%] [%# INTERFACE: - # none + # field: Bugzila::Field; the current field being edited #%] [% PROCESS "global/field-descs.none.tmpl" %] @@ -23,22 +23,17 @@ Edit the Custom Field '[% field.name FILTER html %]' ([% field.description FILTER html %]) [% END %] +[% javascript = BLOCK %] + [% INCLUDE "admin/custom_fields/cf-js.js.tmpl" %] +[% END %] + [% PROCESS global/header.html.tmpl title = title onload = "toggleCheckbox(document.getElementById('enter_bug'), 'new_bugmail');" + javascript_urls = [ 'js/util.js' ] doc_section = "custom-fields.html#edit-custom-fields" %] - -

Descriptions are a very short string describing the field and will be used as the label for this field in the user interface. @@ -82,12 +77,36 @@ - -   -   + + + + + + + + - [% IF field.type == constants.FIELD_TYPE_SINGLE_SELECT - || field.type == constants.FIELD_TYPE_MULTI_SELECT %] + [% IF field.is_select %]   diff --git a/template/en/default/admin/fieldvalues/confirm-delete.html.tmpl b/template/en/default/admin/fieldvalues/confirm-delete.html.tmpl index 12be0e8e4..2389fb6ae 100644 --- a/template/en/default/admin/fieldvalues/confirm-delete.html.tmpl +++ b/template/en/default/admin/fieldvalues/confirm-delete.html.tmpl @@ -61,7 +61,9 @@

Confirmation

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

Sorry, but the '[% value.name FILTER html %]' value cannot be deleted from the '[% field.description FILTER html %]' field for the following @@ -108,6 +110,17 @@ '[%- field.description FILTER html %]', and so it can not be deleted. [% END %] + + [% IF value.controls_visibility_of_fields.size %] +

  • This value controls the visibility of the following fields:
    + [% FOREACH field = value.controls_visibility_of_fields %] + + [%- field.description FILTER html %] + ([% field.name FILTER html %])
    + [% END %] +
  • + [% END %] [% ELSE %] -- cgit v1.2.3-24-g4f1b