[%# 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 Plan $plan.id: $plan.name" %]

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

[% PROCESS global/header.html.tmpl
  title = title
  style = style
%]

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

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

<script type="text/javascript">
  djConfig = {
    parseWidgets: false,
    searchIds:  [% dojo_search %]
  };
</script>
<script src="testopia/js/util.js" type="text/javascript"></script>
<script src="testopia/js/tags.js" type="text/javascript"></script>
<script src="testopia/dojo/dojo.js" type="text/javascript"></script>
<script type="text/javascript">
    dojo.require("dojo.widget.Tooltip");

    
    function fillSelects (data, item){
         var xmldocroot = data.documentElement;
         var err = xmldocroot.getElementsByTagName('error');
         if (err.length > 0){
            alert(err[0].childNodes[0].firstChild.nodeValue);
            document.getElementById("remBuild").disabled = false;
            document.getElementById("remCat").disabled = false;
            exit;
         }
         var selected = xmldocroot.getElementsByTagName(item);
         var comps = document.getElementById(item);
         comps.options.length = 0;

         for (i=0; i< selected.length; i++){
           var id = selected[i].childNodes[0].firstChild.nodeValue;
           var name = selected[i].childNodes[1].firstChild.nodeValue;
           var myOp = new Option(name, id);
           addOption(comps,myOp);
         }
         
         document.getElementById("remBuild").disabled = false;
         document.getElementById("remCat").disabled = false;

    }
    function removeCatBuild(id,item){
        if (id == 0)
          return;
        var choice = confirm("You are about to delete this " + item + ". Continue?");
        if (choice == 0)
          return;
        var myURL = (item == 'category' ? 'tr_categories.cgi' : 'tr_builds.cgi');
        document.getElementById("remBuild").disabled = true;
        document.getElementById("remCat").disabled = true;
        dojo.io.bind({
            url:     myURL,
            content: {  category_id: id, build_id: id, plan_id: [% plan.id FILTER none %], action: 'do_delete', ajax: 1 },
            load:    function(type, data, evt){ fillSelects(data, item);},
            error:   function(type, error){ alert("ERROR Removing Category or Build " + String(error));},
            mimetype: "text/xml"
            });
    }

    function updateCaseList(order, direction){
        dojo.io.bind({
            url:     'tr_show_plan.cgi',
            content: {  direction: direction, getlist: [% getlist ||'null' %], viewall: [% viewall || 'null'%], order: order, plan_id: [% plan.id FILTER none %], action: 'caselist', ajax: 1 },
            load:    function(type, data, evt){ document.getElementById('plan_cases').innerHTML = data; },
            error:   function(type, error){ alert("ERROR Error updating case list" + String(error));},
            mimetype: "text/html"
            });
    }
    function page(pagenum, viewall){
        dojo.io.bind({
            url:     'tr_show_plan.cgi',
            content: {  getlist: [% getlist ||'null' %], viewall: viewall, plan_id: [% plan.id FILTER none %], action: 'caselist', ajax: 1 },
            load:    function(type, data, evt){ document.getElementById('plan_cases').innerHTML = data; },
            error:   function(type, error){ alert("ERROR Getting Page" + String(error));},
            mimetype: "text/html"
            });
    }  
</script>




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

[%##### Overview #####%]

<form name="planform" action="[% form_action FILTER none %]" method="POST" enctype="multipart/form-data">
<div id="plan_overview">
<h3>Overview</h3>
<table border="0" cellpadding="1" width="100%">
  <tbody align="left">
    <tr class="bz_row_header">
      <th>Product</th>
      <th>Product Version </th>
      <th>Created</th>
      </tr>
    <tr class="bz_row_data">
      <td>[% plan.product.name FILTER html %]</td>
      <td>[% plan.product_version FILTER html %]</td>
      <td>[% plan.creation_date FILTER time %]</td>
      </tr>
    <tr class="bz_row_header">
      <th>Author</th>
      <th>Plan Version</th>
      <th>Type</th>
      </tr>
    <tr class="bz_row_data">
      <td><a href="mailto:[% plan.author.email FILTER html %]">[% plan.author.identity FILTER html %]</a></td>
      <td>[% plan.version FILTER html %]</td>
      <td>[% plan.plan_type FILTER html %]</td>
    </tr>
    <tr class="bz_row_data">
      <td colspan="3"><div align="right">
        <a href="#attributes">Edit Plan Attributes</a>
        <input type="hidden" name="plan_id" value="[% plan.id FILTER none %]">
        <input type="submit" name="action" value="Commit" style="visibility:hidden;">
        <input type="submit" name="action" value="[% plan.isactive ? "Archive" : "Unarchive" %]">
        <input type="submit" name="action" value="History">
        <input type="submit" name="action" value="Clone">
        <input type="submit" name="action" value="Print">
      [% IF plan.candelete %]
        <input type="submit" name="action" value="Delete">
      [% END %]
      </div></td>
    </tr>
  </tbody>
</table>
</div>

[%##### Categories and Tags #####%]
<h3>Categories and Tags</h3>
<div id="plan_categories">
<table width="100%" border="0">
  <tr class="bz_row_header">
    <th><a href="tr_categories.cgi?plan_id=[% plan.id FILTER none %]" target="_blank">Categories</a></th>
    <th><a href="tr_tags.cgi?id=[% plan.id FILTER none %]&type=plan">Tags</a></th>
    <th><a href="tr_builds.cgi?plan_id=[% plan.id FILTER none %]" target="_blank">Builds</a></th>
  </tr>
  <tr>
    <td align="left">
    [% PROCESS select sel = { name      => 'category',
                              list      => plan.product.categories
                              accesskey => 'c'
                              elements  => 7 } %]
    <br>
    [% IF plan.candelete %]
    <input type="button" value="Remove" id="remCat" onClick='removeCatBuild(document.getElementById("category").value, "category")'>
    [% END %]
    </td>
    <td valign="top" align="center" rowspan="2">

    <div id="tagTable">
    [% PROCESS testopia/tag/table.html.tmpl 
       item = plan 
       type = 'plan'
    %]
    </div>
    </td>
    <td align="right">
    [% PROCESS select sel = { name      => 'build',
                              list      => plan.product.builds
                              accesskey => 'b'
                              elements  => 7 } %]
    <br>
    [% IF plan.candelete %]
    <input type="button" value="Remove" id="remBuild" onClick='removeCatBuild(document.getElementById("build").value, "build")'>
    [% END %]
    </td>
    
  </tr>
  <tr>
    <td align="left"><a href="tr_categories.cgi?plan_id=[% plan.id FILTER none %]&action=add" target="_blank">Add</a></p></td>
    <td align="right"><a href="tr_builds.cgi?plan_id=[% plan.id FILTER none %]&action=add" target="_blank">Add</a></p></td>
  </tr>
</table>
</div>

[%##### Test Cases #####%]
<br><br>
<h3>Test Cases</h3>
<div id="plan_cases">
[% IF case_table.list_count >0 %]
  <a href="tr_new_case.cgi?plan_id=[% plan.id FILTER none %]">Create a New Test Case</a> 
[% END %]
[% PROCESS testopia/case/table.html.tmpl
   table = case_table %]
  <a href="tr_new_case.cgi?plan_id=[% plan.id FILTER none %]">Create a New Test Case</a>
  <a href="tr_list_cases.cgi?plan_id=[% plan.id FILTER none %]">List Cases</a>
</div>

[%##### Test Runs #####%]
<br><br>
<h3>Test Runs</h3>
<div id="plan_runs">
[% IF run_table.list_count >0 %]
<a href="tr_new_run.cgi?plan_id=[% plan.id FILTER none %]&case_status_id=2">Create a New Test Run</a><br />
[% END %]
[% PROCESS testopia/run/table.html.tmpl
   table = run_table %]
  <a href="tr_new_run.cgi?plan_id=[% plan.id FILTER none %]&case_status_id=2">Create a New Test Run</a>
  <a href="tr_list_runs.cgi?plan_id=[% plan.id FILTER none %]">List Runs</a>
</div>
[%##### Attachments #####%]
<br><br>
<h3>Attachments</h3>
<div id="attachment">
[% PROCESS testopia/attachment/table.html.tmpl
   item = plan
   type = "plan"   
%]
</div>
[%### Reports ###%]
<br><br>
<h3>Reports</h3>
<a href="tr_plan_reports.cgi?plan_id=[% plan.id FILTER none %]&type=build_coverage">Build Coverage</a><br/>
<a href="tr_query.cgi?current_tab=plan&report=1">General Reports</a><br/>
[% IF plan.bugs %]
<a href="tr_plan_reports.cgi?plan_id=[% plan.id FILTER none %]&type=bugcounts">Top Bugs</a><br>
<a href="buglist.cgi?bug_id=[% plan.bug_list FILTER none %]">Bugs Found in this Plan</a><br>
[% END %]
[%##### Edit Plan #####%]
<br>
[% IF plan.canedit %]
<h3>Attributes</h3>
<div id="edit_plan">
    [% PROCESS testopia/plan/form.html.tmpl %]
</div>
[% ELSE %]
[%##### Plan Document #####%]
<div id="plan_doc">
    [% plan.text %]
</div>

[% END %]
</form>

[% IF case_table.list_count >0 %]
<div id="buglist_actions">
	<div class="links">
[% IF case_table.list_count >0 %]
		<span class="label">Export Test Cases:</span>
		<a href="tr_show_plan.cgi?&amp;plan_id=[% plan.id FILTER none %]&amp;export=testcases&amp;ctype=csv&amp;viewall=1"><image src="testopia/img/csv.png" class="image"></a>
		|
		<a href="tr_show_plan.cgi?&amp;plan_id=[% plan.id FILTER none %]&amp;export=testcases&amp;ctype=xml&amp;viewall=1"><image src="testopia/img/xml.png" class="image"></a>
[% END %]
	</div>
</div>
[% END %]

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

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