2013-06-24 184 views
0

我想要获取选择页面(新建和浏览),以显示分类,产品,组件和cf_subcomponent的下拉框。 并基于前一个字段的选择填充有效的选择选项。bugzilla模板选择产品

我不是我得到的变量正确的bugzilla,也认为我的JS是不正确的。

我想这个结束了在URI的下一个页面级

http://bugs/buglist.cgi?product=<product1>&component=<component1>&cf_subcomponent=<subcomponent1> 

继承人是我迄今为止


[%# INTERFACE: 
    # classifications: array of hashes, with an 'object' key representing a 
    #     classification object and 'products' the list of 
    #     product objects the user can enter bugs into. 
    # target: the script that displays this template. 
    # cloned_bug_id: ID of the bug being cloned. 
    # format: the desired format to display the target. 
    #%] 

[% IF target == "enter_bug.cgi" %] 
    [% title = "Enter $terms.Bug" %] 
    [% h2 = BLOCK %]First, you must pick a product on which to enter [% terms.abug %]: [% END %] 
[% ELSIF target == "describecomponents.cgi" %] 
    [% title = "Browse" %] 
    [% h2 = "Select a product category to browse:" %] 
[% END %] 

[% DEFAULT title = "Choose a Product" %] 
[% PROCESS global/header.html.tmpl %] 

[%# This script displays the descriptions for selected components. %] 

var products = new Array([% classification.products.size %]); 
var components = new Array([% product.components.size %]); 
var comp_desc = new Array([% product.components.size %]); 
var flags = new Array([% product.components.size %]); 
[% count = 0 %] 
[% FOREACH product = classification.products %] 
    products[[% count %]] = "[% product.name FILTER js %]"; 
    [%- FOREACH c = product.components %] 
     [% NEXT IF NOT c.is_active %] 
     components[[% count %]] = "[% c.name FILTER js %]"; 
     comp_desc[[% count %]] = "[% c.description FILTER html_light FILTER js %]"; 
     [% flag_list = [] %] 
     [% FOREACH f = c.flag_types.bug %] 
      [% NEXT UNLESS f.is_active %] 
      [% flag_list.push(f.id) %] 
     [% END %] 
     [% FOREACH f = c.flag_types.attachment %] 
      [% NEXT UNLESS f.is_active %] 
      [% flag_list.push(f.id) %] 
     [% END %] 
     flags[[% count %]] = [[% flag_list.join(",") FILTER js %]]; 

     [% count = count + 1 %] 
    [%- END %] 
[% END %] 

function set_assign_to() { 
    // Based on the selected component, fill the "Assign To:" field 
    // with the default component owner, and the "QA Contact:" field 
    // with the default QA Contact. It also selectively enables flags. 
    var form = document.Create; 

    var index = -1; 
    if (form.component.type == 'select-one') { 
     index = form.component.selectedIndex; 
    } else if (form.component.type == 'hidden') { 
     // Assume there is only one component in the list 
     index = 0; 
    } 
    if (index != -1) { 
     var component = components[index]; 

     document.getElementById('comp_desc').innerHTML = comp_desc[index]; 

     // We show or hide the available flags depending on the selected component. 
     var flag_rows = YAHOO.util.Dom.getElementsByClassName('bz_flag_type', 'tbody'); 
     for (var i = 0; i 1 ? 1 : 0; 
      var show = 0; 
      // Loop through the allowed flag ids for the selected component 
      // and if we match, then show the row, otherwise hide the row. 
      for (var j = 0; j 


    


    [%# We can't use the select block in these two cases for various reasons. %] 
    
    [% classification_desc_url = BLOCK -%] 
     describecomponents.cgi? 
    [% END %] 
    [% INCLUDE "bug/field-label.html.tmpl" 
     field = bug_fields.classification editable = 1 
     desc_url =classification_desc_url 
    %]  
    
     
     [%- FOREACH class = classifications %] 
      [% NEXT IF NOT class.is_active %] 
      
      [% class.name FILTER html -%] 
      
     [%- END %] 
     

     
     
     
    

    
     [%# Enclose the fieldset in a nested table so that its width changes based 
     # on the length on the classification description. %] 
     
     
      
      
       Classification Description 
       Select a classification to read its description. 
      
      
     
     
    
    

    [%# We can't use the select block in these two cases for various reasons. %] 
    
    [% product_desc_url = BLOCK -%] 
     describecomponents.cgi?classification=[% classification.name FILTER uri %] 
    [% END %] 
    [% INCLUDE "bug/field-label.html.tmpl" 
     field = bug_fields.product editable = 1 
     desc_url = product_desc_url 
    %]  
    
     
     [%- FOREACH p = classification.products %] 
      [% NEXT IF NOT p.is_active %] 
      
      [% p.name FILTER html -%] 
      

     [%- END %] 
     

     
     
     
    

    
     [%# Enclose the fieldset in a nested table so that its width changes based 
     # on the length on the product description. %] 
     
     
      
      
       Product Description 
       Select a product to read its description. 
      
      
     
     
    
    

    [%# We can't use the select block in these two cases for various reasons. %] 
    
    [% component_desc_url = BLOCK -%] 
     describecomponents.cgi?product=[% product.name FILTER uri %] 
    [% END %] 
    [% INCLUDE "bug/field-label.html.tmpl" 
     field = bug_fields.component editable = 1 
     desc_url = component_desc_url 
    %]  
    
     
     [%# Build the lists of assignees and QA contacts if "usemenuforusers" is enabled. %] 
     [%- FOREACH c = product.components %] 
      [% NEXT IF NOT c.is_active %] 
      
      [% c.name FILTER html -%] 
      

     [%- END %] 
     

     
     
     
    

    
     [%# Enclose the fieldset in a nested table so that its width changes based 
     # on the length on the component description. %] 
     
     
      
      
       Component Description 
       Select a component to read its description. 
      
      
     
     
    
    

    
    [% USE Bugzilla %] 

    [% FOREACH field = Bugzilla.active_custom_fields %] 
    [% IF field.name == "cf_subcomponent" %] 
     [% NEXT UNLESS field.enter_bug %] 
     [% SET value = ${field.name}.defined ? ${field.name} : "" %] 
     
      [% INCLUDE bug/field.html.tmpl 
       bug = default, field = field, value = value, editable = 1, 
       value_span = 3 %] 
     
    [% END %] 
    [% END %] 
    

回答

0

我结束了对每个选择写一个完整的JavaScript,啰嗦,但我找不到另一种方式。

正如你可以看到这是一个例子,我有其他组件上树,但这应该告诉你该怎么做。

[%# This Source Code Form is subject to the terms of the Mozilla Public 
    # License, v. 2.0. If a copy of the MPL was not distributed with this 
    # file, You can obtain one at http://mozilla.org/MPL/2.0/. 
    # 
    # This Source Code Form is "Incompatible With Secondary Licenses", as 
    # defined by the Mozilla Public License, v. 2.0. 
    #%] 

[%# INTERFACE: 
    # classifications: array of hashes, with an 'object' key representing a 
    #     classification object and 'products' the list of 
    #     product objects the user can enter bugs into. 
    # target: the script that displays this template. 
    # cloned_bug_id: ID of the bug being cloned. 
    # format: the desired format to display the target. 
    #%] 

[% IF target == "enter_bug.cgi" %] 
    [% title = "Enter $terms.Bug" %] 
    [% h2 = BLOCK %]First, you must pick a product on which to enter [% terms.abug %]: [%  END %] 
[% ELSIF target == "describecomponents.cgi" %] 
    [% target = "buglist.cgi" %] 
    [% title = "Browse" %] 
    [% h2 = "Select a product category to browse:" %] 
[% END %] 

[% DEFAULT title = "Choose a Product" %] 
[% PROCESS global/header.html.tmpl %] 

[% USE Bugzilla %] 
[%# This script displays the descriptions for selected components. %] 
<script type="text/javascript"> 
var classifications = new Array([% classifications.size %]); 
[% count = 0 %] 
[% FOREACH cl = classifications %] 
    classifications[[% count %]] = "[% cl.object.name FILTER js %]"; 
[% count = count + 1 %] 
[% END %] 

function setComponentSelection() { 
//hide all following areas 
document.getElementById("subCompBody").style.visibility = 'hidden'; 
document.getElementById('subcomponent').selectedIndex=-1; 

var compSel = document.getElementById('component'); 
var compInd = compSel.selectedIndex; 
if(compInd != -1) 
{ 
    var subcompSel = document.getElementById('subcomponent'); 
    subcompSel.options.length = 0; 

    //get classification 
    var classSel = document.getElementById('classification'); 
    var classInd = classSel.selectedIndex; 
    var showSubCompBody = 0; 
    if(classInd != -1) 
    { 
     [% FOREACH cll = classifications %] 
      if(classSel.options[classInd].text == "[% cll.object.name FILTER js %]") 
      { 
       [% bug.classification = cll %] 
       var prodSel = document.getElementById('product'); 
       var prodInd = prodSel.selectedIndex; 
       if(prodInd!=-1) 
       { 
        [% FOREACH p = cll.products %] 
         if(prodSel.options[prodInd].text == "[% p.name FILTER js %]") 
         { 
          [% bug.product = p %] 
          [% FOREACH c = p.components %] 
           if(compSel.options[compInd].text == "[% c.name FILTER js %]") 
           { 
            [% bug.component = c %] 
            [% FOREACH field = Bugzilla.active_custom_fields %] 
             [% IF field.name == "cf_subcomponent" %] 
              [%- FOREACH fl = field.legal_values %] 
               [% IF c.name == fl.visibility_value.name %] 
                showSubCompBody = 1; 
                var option = document.createElement("option"); 
                option.text = "[% fl.name FILTER js %]"; 
                option.value = "[% fl.name FILTER js %]"; 
                subcompSel.add(option); 
               [% END %] 
              [% END %] 
             [% END %] 
            [% END %] 
           } 
          [% END %]  
         } 
        [% END %] 
       } 
      } 
     [% END %] 
    } 

    if(showSubCompBody==1) 
     document.getElementById("subCompBody").style.visibility = 'visible'; 
} 
} 

function hideCombos(){ 
//hide all combo boxes if java script is supported, if not they should all stay shown 
document.getElementById("productBody").style.visibility = 'hidden'; 
document.getElementById("componentBody").style.visibility = 'hidden'; 
document.getElementById("subCompBody").style.visibility = 'hidden'; 
} 
</script> 

<h2>[% h2 FILTER html %]</h2> 
<form action="[% target %]?component=[% c.name FILTER uri %]&cf_subcomponent=[%  subComp.name FILTER uri %] 
      [%- IF cloned_bug_id %]&amp;cloned_bug_id=[% cloned_bug_id FILTER uri %][% END -%] 
      [%- IF format %]&amp;format=[% format FILTER uri %][% END %]"> 
<table> 
<tbody id="componentBody"> 
    <tr id="field_container_component"> 
[% component_desc_url = BLOCK -%] 
    describecomponents.cgi? 
[% END %] 
[% INCLUDE "bug/field-label.html.tmpl" 
    field = bug_fields.component editable = 1 
    desc_url = component_desc_url 
%]  
<td> 
    <select name="component" id="component" onchange="setComponentSelection();" 
      size="10" aria-required="true" class="required"> 
    [%- FOREACH cl = classifications %] 
     [%- FOREACH p = cl.products %] 
      [%- FOREACH c = p.components %] 
       <option value="[% c.name FILTER html %]" 
        id="v[% c.id FILTER html %]_product"> 
        [% c.name FILTER html -%] 
       </option> 
      [% END %] 
     [% END %] 
    [%- END %] 
    </select> 
</td> 
    </tr> 
</tbody> 

<tbody id="subCompBody"> 
<tr> 
    <td> 
     <font color="red">*</font>Sub Component:  
    </td> 
    <td> 
     [% FOREACH field = Bugzilla.active_custom_fields %] 
      [% IF field.name == "cf_subcomponent" %] 
       <select name="cf_subcomponent" id="subcomponent" " 
        size="10" aria-required="true" class="required"> 
        [% FOREACH fl = field.legal_values %] 
         <option value="[% fl.name FILTER html %]" 
          id="v[% fl.id FILTER html %]_product"> 
          [% fl.name FILTER html -%] 
         </option> 
        [% END %] 
       </select> 
      [% END %] 
     [% END %] 
    </td> 
</tr> 
</tbody> 

    <tr> 
    <th colspan="2">&nbsp;</th> 
    </tr> 

<tr> 
    <th> 
     <input type="submit" value="Select"/> 
    </th> 
</tr> 

<script type="text/javascript"> 
hideCombos(); 
</script> 
</tbody> 
</table> 
</form>