diff options
author | mkanat%bugzilla.org <> | 2008-10-25 06:11:30 +0200 |
---|---|---|
committer | mkanat%bugzilla.org <> | 2008-10-25 06:11:30 +0200 |
commit | 3cea91884b28b52df4e38f2ba88c00b65071a81f (patch) | |
tree | c0f451235176b2b542a38b0c935dcddf0453a1ee /template | |
parent | e0da20baba17b7f068946c8647fb6d67e77c39b7 (diff) | |
download | bugzilla-3cea91884b28b52df4e38f2ba88c00b65071a81f.tar.gz bugzilla-3cea91884b28b52df4e38f2ba88c00b65071a81f.tar.xz |
Bug 291433: Ability to have custom fields whose visibility depends on the values of other fields
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=bbaetz, a=mkanat
Diffstat (limited to 'template')
6 files changed, 169 insertions, 33 deletions
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 <mkanat@bugzilla.org> + #%] + +// 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" %] -<script type="text/javascript"> - <!-- - // 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; - } - //--> -</script> - <p> 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 @@ <input type="text" id="sortkey" name="sortkey" size="6" maxlength="6"> </td> - <th> </th> - <td> </td> + <th align="right"> + <label for="visibility_field_id">Field only appears when:</label> + </th> + <td> + <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 %] + <option value="[% sel_field.id FILTER html %]"> + [% sel_field.description FILTER html %] + ([% sel_field.name FILTER html %]) + </option> + [% END %] + </select> + <label for="visibility_value_id"><strong>is set to:</strong></label> + <select name="visibility_value_id" id="visibility_value_id"> + <option value=""></option> + </select> + </td> </tr> </table> <p> 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" %] -<script type="text/javascript"> - <!-- - // 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; - } - //--> -</script> - <p> 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 @@ <input type="text" id="sortkey" name="sortkey" size="6" maxlength="6" value="[% field.sortkey FILTER html %]"> </td> - - <th> </th> - <td> </td> + <th align="right"> + <label for="visibility_field_id">Field only appears when:</label> + </th> + <td> + <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 %] + <option value="[% sel_field.id FILTER html %]" + [% ' selected="selected"' + IF sel_field.id == field.visibility_field.id %]> + [% sel_field.description FILTER html %] + ([% sel_field.name FILTER html %]) + </option> + [% END %] + </select> + <label for="visibility_value_id"><strong>is set to:</strong></label> + <select name="visibility_value_id" id="visibility_value_id"> + [% FOREACH value = field.visibility_field.legal_values %] + <option value="[% value.id FILTER html %]" + [% ' selected="selected"' + IF field.visibility_value.id == value.id %]> + [% value.name FILTER html %] + </option> + [% END %] + </select> + </td> </tr> - [% IF field.type == constants.FIELD_TYPE_SINGLE_SELECT - || field.type == constants.FIELD_TYPE_MULTI_SELECT %] + [% IF field.is_select %] <tr> <th> </th> <td colspan="3"> 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 @@ <h2>Confirmation</h2> -[% 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 +%] <p>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. </li> [% END %] + + [% IF value.controls_visibility_of_fields.size %] + <li>This value controls the visibility of the following fields:<br> + [% FOREACH field = value.controls_visibility_of_fields %] + <a href="editfields.cgi?action=edit&name= + [%- field.name FILTER url_quote %]"> + [%- field.description FILTER html %] + ([% field.name FILTER html %])</a><br> + [% END %] + </li> + [% END %] </ul> [% ELSE %] diff --git a/template/en/default/bug/field.html.tmpl b/template/en/default/bug/field.html.tmpl index 762e659db..3b26073aa 100644 --- a/template/en/default/bug/field.html.tmpl +++ b/template/en/default/bug/field.html.tmpl @@ -28,9 +28,21 @@ # allow_dont_change: display the --do_not_change-- option for select fields. # value_span: A colspan for the table cell containing # the field value. + # bug (optional): The current Bugzilla::Bug being displayed, or a hash + # with default field values being displayed on a page. #%] -<th class="field_label"> +[% SET hidden = 0 %] +[% IF field.visibility_field.defined %] + [% IF !bug.${field.visibility_field.name} + .contains(field.visibility_value.name) + %] + [% SET hidden = 1 %] + [% 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 %] @@ -38,7 +50,9 @@ [% '</label>' IF editable %] </th> -<td class="field_value" [% "colspan=\"$value_span\"" FILTER none IF value_span %]> +<td class="field_value [% ' bz_hidden_field' IF hidden %]" + id="field_container_[% field.name FILTER html %]" + [% " colspan=\"$value_span\"" FILTER none IF value_span %]> [% IF editable %] [% SWITCH field.type %] [% CASE constants.FIELD_TYPE_FREETEXT %] @@ -121,6 +135,14 @@ id = field.name name = field.name minrows = 4 maxrows = 8 cols = 60 defaultcontent = value %] [% END %] + + [% FOREACH controlled_field = field.controls_visibility_of %] + <script type="text/javascript"> + showFieldWhen('[% controlled_field.name FILTER js %]', + '[% field.name FILTER js %]', + '[% controlled_field.visibility_value.name FILTER js %]'); + </script> + [% END %] [% ELSIF field.type == constants.FIELD_TYPE_TEXTAREA %] <div class="uneditable_textarea">[% value FILTER wrap_comment(60) FILTER html %]</div> diff --git a/template/en/default/global/user-error.html.tmpl b/template/en/default/global/user-error.html.tmpl index 1b737744c..f4ea42ccf 100644 --- a/template/en/default/global/user-error.html.tmpl +++ b/template/en/default/global/user-error.html.tmpl @@ -402,6 +402,17 @@ ([% field.description FILTER html %]) already exists. Please choose another name. + [% ELSIF error == "field_cant_control_self" %] + [% title = "Field Can't Control Itself" %] + The [% field.description FILTER html %] field can't be set to control + itself. + + [% 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 %] + is not the right type of field. + [% ELSIF error == "field_invalid_name" %] [% title = "Invalid Field Name" %] '[% name FILTER html %]' is not a valid name for a field. @@ -430,6 +441,12 @@ The value '[% value.name FILTER html %]' already exists for the [%+ field.description FILTER html %] field. + [% 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 %]. + [% ELSIF error == "fieldvalue_is_default" %] [% title = "Specified Field Value Is Default" %] '[% value.name FILTER html %]' is the default value for @@ -1168,7 +1185,7 @@ in the <em>[% field_descs.$field FILTER html %]</em> field is less than the minimum allowable value of '[% min_num FILTER html %]'. - [% ELSIF error == "object_name_not_specified" %] + [% ELSIF error == "object_not_specified" %] [% type = BLOCK %][% INCLUDE object_name class = class %][% END %] [% title = BLOCK %][% type FILTER ucfirst FILTER html %] Not Specified[% END %] @@ -1177,7 +1194,12 @@ [% ELSIF error == "object_does_not_exist" %] [% type = BLOCK %][% INCLUDE object_name class = class %][% END %] [% title = BLOCK %]Invalid [% type FILTER ucfirst FILTER html %][% END %] - There is no [% type FILTER html %] named '[% name FILTER html %]' + There is no [% type FILTER html %] + [% IF id.defined %] + with the id '[% id FILTER html %]' + [% ELSE %] + named '[% name FILTER html %]' + [% END %] [% IF product.defined %] in the '[% product.name FILTER html %]' product [% END %]. |