[%# 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>
  #%]

<script type="text/javascript">
    dojo.require("dojo.io");
    function getProdEnvs(product){
        document.getElementById("env_pick").disabled = true;
        document.getElementById("action").disabled = true;
        dojo.io.bind({
            url:   "tr_new_plan.cgi",
            content: {  product_id: product, action: "getenvs" },
            load:  function(type, data, evt){
                     var comps = document.getElementById("env_pick");
                     comps.options.length = 0;
                     for (i in data){
                       var myOp = new Option(data[i].name, data[i].id);
                       addOption(comps, myOp);
                     }
                     document.getElementById("env_pick").disabled = false;
                     document.getElementById("action").disabled = false;
                   },
            error: function(type, error){ alert(error.message);},
            mimetype: "text/json"
        });
    }
</script>

<a name="attributes"></a>
  <input type="hidden" name="run_id" value="[% run.id FILTER none %]"> 
  <table border="0" cellpadding="2" cellspacing="0">
    <tr>
      <th align="right">Product Version</td>

      <td>
        [% PROCESS select sel = { name => "product_version", 
                                  list => run.plan.get_product_versions, 
                                  default => run.product_version ? run.product_version : run.plan.product_version }
         %]
      </td>

      <th align="right">Plan Version</td>
      <td>
        [% PROCESS select sel = { name => "plan_version", 
                                  list => run.plan.get_plan_versions, 
                                  default => run.plan_text_version }
         %]
      </td>
    </tr>

    <tr>
      <th align="right">Manager</th>
      <td><input name="manager" value="[% run.manager.login ? run.manager.login : user.login FILTER html %]"></td>
      <th align="right"><a href="tr_builds.cgi?plan_id=[% run.plan.id FILTER none %]">Build</a></td>
      <td>
        [% PROCESS select sel = { name => "build", 
                                  list => run.plan.product.builds,
                                  default => run.build.id }
         %]
       [% IF action == 'Add' %]
         <b>or New:</b> <input name="new_build">
       [% END %]
      </td>
      
    </tr>

    <tr>
      <th align="right">Status</th>
      <td colspan="3">
        [% SET statuslist = [{ id => 1, name => 'Running'}, {id => 0, name=> 'Stopped'}] %]
        [% PROCESS select sel = { name => "status", 
                                  list => statuslist, 
                                  default => run.stop_date ? 0 : 1 }
        %]

      </td>
    </tr>
    <tr><td colspan="4" align="center">
      <table>
        <tr><th align="center"  colspan="2">Environment</th></tr>
        <tr>
          <th align="right">ID</th>
          <td><input name="environment" id="environment" value="[% run.environment.id FILTER none %]" />
            <a href="tr_query.cgi?current_tab=environment" target="blank"><img src="testopia/img/env_lookup.png" title="Search for Environments" align="middle"></a>
            <a href="tr_new_environment.cgi" target="_blank">New</a>
          </td>
        </tr>
        <tr>
          <th>Or Select from Product</th>
          <td>
    [% PROCESS select sel = { name      => 'prod_pick',
                              list      => user.get_selectable_products,
                              default   => run.plan.product_id
                              events    => 'onChange="getProdEnvs(this.value)"' } %]
          </td>
        </tr>
        <tr>
          <td></td>
          <td>
    [% PROCESS select sel = { name      => 'env_pick' }%]
          </td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <th align="right">Summary</th>
      <td  colspan="3"><input type="text" size="110" name="summary" value="[% run.summary FILTER html %]"></td>
    </tr>

    <tr>
      <th align="right" valign="top">Notes:</th>
      <td colspan="5">
<textarea rows="15" cols="80" name="notes">
[% run.notes FILTER none %]
</textarea> 
      </td>
    </tr>
  </table>
  <div class="submits">
    <input type="submit" name="action" id="action" value="[% action %]" />
  </div>
<script type="text/javascript">
  getProdEnvs(document.getElementById('prod_pick').value);
</script>
