[%# 1.0@bugzilla.org %]
[%# 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 Test Runner System.
  #
  # The Initial Developer of the Original Code is Maciej Maczynski.
  # Portions created by Maciej Maczynski are Copyright (C) 2001
  # Maciej Maczynski. All Rights Reserved.
  #
  # Contributor(s): Ed Fuentetaja <efuentetaja@acm.org>
  #                 Greg Hendricks <ghendricks@novell.com>
  #%]

[%# INTERFACE:
  # ...
  #%]
  
[%############################################################################%]
[%# Template Initialization                                                  #%]
[%############################################################################%]

[% PROCESS global/variables.none.tmpl %]
[% PROCESS testopia/blocks.html.tmpl %]
[% SET title = "Test Case $case.id: $case.summary" %]

[%############################################################################%]
[%# Page Header                                                              #%]
[%############################################################################%]

[% PROCESS global/header.html.tmpl %]

[% PROCESS testopia/style.none.tmpl %]

<script src="testopia/js/util.js" type="text/javascript"></script>
<script src="testopia/js/tags.js" type="text/javascript"></script>
<script type="text/javascript">
  djConfig = {
    isDebug: true,
    parseWidgets: false,
    searchIds: ["tcaction", "tceffect", "tcsetup", "tcbreakdown", "newtag","tagTable","tester"]
  };
</script>
<script src="testopia/dojo/dojo.js" type="text/javascript"></script>
<script type="text/javascript">

    function updateComponent(comp_id, action){
        if (comp_id == 0)
          return;

        document.getElementById("addComp").disabled = true;
        document.getElementById("deleteComp").disabled = true;
        dojo.io.bind({
            url:     "tr_show_case.cgi",
            content: {  component_id: comp_id, case_id: [% case.id FILTER none %], action: action },
            load:    function(type, data, evt){ 
                if (data.ignore == 1){
                  alert("That component is already associated with this test case");
                  document.getElementById("addComp").disabled = false;
                  document.getElementById("deleteComp").disabled = false;
                  return;
                }
                var comps = document.getElementById("components");
                comps.options.length = 0;
                for (i in data){
                  var myOp = new Option(data[i].name, data[i].id);
                  addOption(comps,myOp);
                }
                
                document.getElementById("addComp").disabled = false;
                document.getElementById("deleteComp").disabled = false;
                },
            error:   function(type, error){ alert(error.message);},
            mimetype: "text/json"
        });
    }
    function getProdComps(product){
        document.getElementById("comp_pick").disabled = true;
        document.getElementById("addComp").disabled = true;
        document.getElementById("deleteComp").disabled = true;
        dojo.io.bind({
            url:   "tr_new_plan.cgi",
            content: {  product_id: product, action: "getcomps" },
            load:  function(type, data, evt){
                     var comps = document.getElementById("comp_pick");
                     comps.options.length = 0;
                     for (i in data){
                       var myOp = new Option(data[i].name, data[i].id);
                       addOption(comps, myOp);
                     }
                     document.getElementById("comp_pick").disabled = false;
                     document.getElementById("addComp").disabled = false;
                     document.getElementById("deleteComp").disabled = false;
                   },
            error: function(type, error){ alert("ERROR");},
            mimetype: "text/json"
        });
    }
    
</script>

[% PROCESS testopia/messages.html.tmpl %]

[% PROCESS testopia/case/navigate.html.tmpl %]

[% requirement = case.requirement FILTER html %]

[%##### Overview #####%]
[% IF copied %]
<h3>Case copied from test case [% copied.id FILTER none %]</h3>
<a href="tr_show_case.cgi?case_id=[% copied.id FILTER none %]">Back to case [% copied.id FILTER none %]</a>
<br>
[% END %]
<FORM name="TestCaseForm" id="TestCaseForm" method="POST" action="tr_show_case.cgi" enctype="multipart/form-data">
<div id="case_overview">
<h3>Overview</h3>
<table border="0" cellpadding="1" width="100%">
  <tbody align="left">
    <tr class="bz_row_header">
      <th>Alias</th>
      <th>Requirement</th>
      <th>Created</th>
      </tr>
    <tr class="bz_row_data">
      <td>[% case.alias FILTER html %]</td>
      <td>[% requirement FILTER quoteUrls %]</td>
      <td>[% case.creation_date FILTER time %]</td>
      </tr>
    <tr class="bz_row_header">
      <th>Author</th>
      <th>Case Version</th>
      <th>Category</th>
      </tr>
    <tr class="bz_row_data">
      <td>Author <a href="mailto:[% case.author.email FILTER html %]">[% case.author.identity FILTER html %]</a><br>
          Default Tester <a href="mailto:[% case.default_tester.email FILTER html %]">[% case.default_tester.identity FILTER html %]</a></td>
      <td>[% case.version FILTER html %]</td>
      <td>[% case.category.name FILTER html %]</td>
    </tr>
    <tr class="bz_row_header">
      <th>Priority</th>
      <th>Status</th>
      <th>Automated</th>
      </tr>
    <tr class="bz_row_data">
      <td>[% case.priority FILTER html %]</td>
      <td>[% case.status FILTER html %]</td>
      <td>[% case.isautomated ? "YES" : "NO" FILTER html %]</td>
    </tr>
    <tr class="bz_row_header">
      <th>Used in Plans</th>
      <th>[% terms.Bugs %] Detected</th>
      <th>Found in Runs (total)</th>
    </tr>
    <tr class="bz_row_data">
      <td>
      [% FOREACH plan = case.plans %]
        <a href="tr_show_plan.cgi?plan_id=[% plan.id FILTER none %]">[% plan.id FILTER none %][% IF plan.canview %]:&nbsp;[% plan.name FILTER html %][% END %]</a>
        [% IF case.can_unlink_plan(plan.id) %]
        <a href="tr_show_case.cgi?action=unlink&plan_id=[% plan.id FILTER none %]&case_id=[% case.id FILTER none %]"><img src="testopia/img/del.gif" alt="Unlink Test Plan" /></a>
        [% END %]
        <br/>
      [% END %]
      </td>
      <td>
      [% FOREACH bug_id = case.bugs %]
        <a href="show_bug.cgi?id=[% bug.id FILTER none %]">[% bug.id FILTER none %]</a>
      [% END %]
      </td>
      <td><a href="tr_list_runs.cgi?case_id=[% case.id FILTER none %]">[% case.run_count FILTER none %]</a></td>
    </tr>
    <tr class="bz_row_data">
      <td colspan="3"><div align="right">
      [% IF case.canedit %]
        <a href="#attributes">Edit Case Attributes</a>
        <input type="submit" name="action" value="Commit" style="visibility:hidden;">
      [% END %]
        <input type="submit" name="action" value="History">
        <input type="submit" name="action" value="Clone">
        <input type="submit" name="action" value="Print">
      [% IF case.candelete %]
        <input type="submit" name="action" value="Delete">
      [% END %]
      </div></td>
    </tr>
  </tbody>
</table>
</div>

[%##### Components and Tags #####%]
<h3>Components and Tags</h3>
<div id="case_components">
<table width="100%" border="0">
[% IF case.canedit %]
  <tr class="bz_row_header">
    <th>Components</th>
    <th><a href="tr_tags.cgi?case_id=[% case.id FILTER none %]">Tags</a></th>
  </tr>
  <tr>
    <td align="left">
    <table>
      <tr><th align="right">Product</th>
      <td>
      [% PROCESS select sel = { name      => 'prod_pick',
                                list      => user.get_selectable_products,
                                default   => case.get_product_ids.0,
                                events    => 'onChange="getProdComps(this.value)"',
                                accesskey => 'p' } %]
      </td>
    </tr>
    <tr>
      <th align="right">Component</th>
      <td>
      [% PROCESS select sel = { name      => 'comp_pick',
                                list      => case.get_selectable_components
                                accesskey => 'p' } %]
      <input type="button" id="addComp" value="Add" onClick="updateComponent(document.getElementById('comp_pick').value, 'addcomponent')">
      </td>
    </tr>
[% END %]
    <tr>
      <td>&nbsp;</td>
      <td>
    [% SET components = case.components %]
   
      [% PROCESS select sel = { name      => 'components',
                                list      => components
                                accesskey => 'c'
                                elements  => 7 } %]
      <br>
    [% IF case.canedit %]
      <input type="button" id="deleteComp" value="Remove" onClick="updateComponent(document.getElementById('components').value, 'removecomponent')">
    [% END %]
      </td></tr>
    </table>
    </td>
    <td valign="top" align="center" rowspan="2">
    <div id="tagTable" dojoType="ContentPane">
    [% PROCESS testopia/tag/table.html.tmpl 
       item = case
       type = 'case' 
    %]
    </div>
    </td>    
  </tr>
</table>
</div>

[%##### Test Case Runs #####%]
<br><br>
<h3>Test Case Run History</h3>
<div id="case_run_history">
[% PROCESS 'testopia/caserun/case-history.html.tmpl'
   testcaseruns = case.caseruns %]
</div>
[%##### Reports #####%]
<br><br>
<h3>Reports</h3>
<table>
  <tr>
    <td>
      <img src="tr_case_reports.cgi?case_id=[% case.id FILTER none %]&type=status-breakdown">
    </td>
    <td>
    <table>
    <tr class="bz_row_header">
      <th>Tabular Reports</th>
      <th>Time Reports</th>
    </tr>
    <tr>
    <td valign="top"><a href="tr_query.cgi?current_tab=case&report=1">General Reports</a></td>
    <td valign="top" align="center">
      <b>Estimated Time</b><br>
      [% case.estimated_time FILTER html %]<br><br>
      <b>Actual Average Time</b><br>
      [% case.calculate_average_time FILTER html %]
    </td>
    </tr>
    </table>
  </tr>
</table>
[%##### Attachments #####%]
<br><br>
<h3>Attachments</h3>
<div id="attachment">
[% PROCESS testopia/attachment/table.html.tmpl
   item = case
%]
</div>
[% #### Bugs ####%]
<br><br>
<h3>Bugs</h3>
<div id="bugs">
[% PROCESS testopia/case/bugs.html.tmpl
   item = case
%]
</div>
[%##### Edit Case #####%]
<br><br>
[% IF case.canedit %]
<h3>Attributes</h3>
<div id="edit_case">
    [% PROCESS testopia/case/form.html.tmpl %]
</div>
[% ELSE %]
[%##### Case Document #####%]
<br><br>
<h3>Setup</h3>
<div id="case_docs">
    [% case.text.setup FILTER quoteUrls %]
<br><br>
<h3>Breakdown</h3>
    [% case.text.breakdown FILTER quoteUrls %]
<br><br>
<h3>Action</h3>
    [% case.text.action FILTER quoteUrls %]
<br><br>
<h3>Expected Results</h3>
    [% case.text.effect FILTER quoteUrls %]
</div>

[% END %]
</FORM>

<div id="buglist_actions">
  <div class="links">
    <span class="label">Export:</span>
      <a href="tr_show_case.cgi?&amp;case_id=[% case.id FILTER none %]&amp;ctype=csv"><image src="testopia/img/csv.png" class="image"></a>
        |
      <a href="tr_show_case.cgi?&amp;case_id=[% case.id FILTER none %]&amp;ctype=xml"><image src="testopia/img/xml.png" class="image"></a>
    </div>
</div>

[%##### Footer #####%]

[% PROCESS global/footer.html.tmpl %]
