]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 458436: Allow standard global select fields to control visibility of custom fields
authormkanat%bugzilla.org <>
Sat, 25 Oct 2008 04:14:56 +0000 (04:14 +0000)
committermkanat%bugzilla.org <>
Sat, 25 Oct 2008 04:14:56 +0000 (04:14 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=bbaetz, a=mkanat

Bugzilla/Field.pm
editvalues.cgi
template/en/default/admin/custom_fields/cf-js.js.tmpl
template/en/default/admin/custom_fields/create.html.tmpl
template/en/default/admin/custom_fields/edit.html.tmpl
template/en/default/bug/create/create.html.tmpl
template/en/default/bug/edit.html.tmpl
template/en/default/bug/field.html.tmpl
template/en/default/bug/knob.html.tmpl

index 7da8a8bba4d67b7131520746732873fa960e9a99..a5e380a11665a051061518ac9a6dc7aad3b2f9e3 100644 (file)
@@ -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);
         }
     }
index 85d4c9761552080203135d7d2868997e8ba4cadc..33824528461f71ae27a3772b88e03acebfa60f7f 100755 (executable)
@@ -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;
index 863f14dca33cc0fbe5341f528d7a1f436644daea..bf72ff99828f3d8de1867cecbf9ea73b7247f5de 100644 (file)
@@ -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 %]'],
index da10c7bcbf82b4944b6539dfd10b626c1ec5f1fa..17bd5bfdc86a3d32d0a66d4d05ffe25c032bd00c 100644 (file)
@@ -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 %])
index 2186c75627214df48fab049a43d04bc3784433e8..3d7355a775261361311340a5038eccf4fb8cdfdd 100644 (file)
@@ -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 %]>
index aaf2de5a6b7738b56e9c46aebabe35265807426a..0b941cc3575b6b5deb36374ab47cb7d4aaac9772 100644 (file)
@@ -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 %]
index c8a6f933c7d7163813b00281d73326c6b01c478a..fc74bcfb20523b7c8e396ed135a171eeaa760899 100644 (file)
 
 [% 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">
   <!--
   
       <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>
           <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 %] 
 [% BLOCK section_customfields %]
 [%# *** Custom Fields *** %]
 
-  [% USE Bugzilla %]
   [% FOREACH field = Bugzilla.active_custom_fields %]
     <tr>
       [% PROCESS bug/field.html.tmpl value=bug.${field.name}
index 3b26073aab9e51c9c92e9a71a3ae829b49b24d6a..9b93a9ff251207fbe20cf44d39d12e1311897dbd 100644 (file)
@@ -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.
   #%]
   [% 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 %]
 [% ELSE %]
   [% value.join(', ') FILTER html %]
 [% END %]
-</td>
+[% '</td>' IF NOT no_tds %]
index 4cf6031e7e74dc25b865407ad91ca5ddda432236..b984410e0390e0d6d9e43027ed8a6e0b9a27e0bb 100644 (file)
   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 %]