[%# 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 BMO Extension
  #
  # The Initial Developer of the Original Code is the Mozilla Foundation
  # Portions created by the Initial Developers are Copyright (C) 2011 the
  # Initial Developer. All Rights Reserved.
  #
  # Contributor(s):
  #   Byron Jones <bjones@mozilla.com>
  #%]

[% PROCESS global/variables.none.tmpl %]

[% js_data = BLOCK %]
var useclassification = false;
var first_load = true;
var last_sel = [];
var cpts = new Array();
[% n = 1 %]
[% FOREACH p = user.get_selectable_products %]
  cpts['[% n FILTER js %]'] = [
    [%- FOREACH comp = p.components %]'[% comp.name FILTER js %]'[% ", " UNLESS loop.last %] [%- END -%] ];
  [% n = n+1 %]
[% END %]

var selected_components = [
  [%- FOREACH comp = input.component %]'[% comp FILTER js %]'
  [%- ',' UNLESS loop.last %] [%- END ~%] ];

[% END %]

[% INCLUDE global/header.html.tmpl
  title = "Unconfirmed Reports"
  generate_api_token = 1
  javascript = js_data
  javascript_urls = [ "js/field.js", "js/productform.js",
                      "extensions/BMO/web/js/triage_reports.js" ]
  style_urls = [ "skins/standard/buglist.css",
                 "extensions/BMO/web/styles/triage_reports.css" ]
%]

<noscript>
<h2>JavaScript is required to use this report.</h2>
</noscript>

[% PROCESS "global/field-descs.none.tmpl" %]

<form id="activity_form" name="activity_form" action="[% basepath FILTER none %]page.cgi" method="get"
      onSubmit="return onGenerateReport()">
<input type="hidden" name="id" value="triage_reports.html">
<input type="hidden" name="action" value="run">

Show UNCONFIRMED [% terms.bugs %] with:
<table id="triage_form">

<tr>
  <th>Product:</th>
  <td>
    <select name="product" id="product" onChange="onSelectProduct()">
      <option value=""></option>
      [% FOREACH p = user.get_selectable_products %]
        <option value="[% p.name FILTER html %]"
          [% " selected" IF input.product == p.name %]>
          [% p.name FILTER html %]
        </option>
      [% END %]
    </select>
  </td>
  <td rowspan="2" valign="top">
    <b>Comment:</b><br>

    <input type="checkbox" name="filter_commenter" id="filter_commenter" value="1"
    [% 'checked' IF input.filter_commenter %]>
    <label for="filter_commenter">where the last commenter</label>
    <select name="commenter" id="commenter" onChange="onCommenterChange()">
      <option value="reporter" [% 'selected' IF input.commenter == 'reporter' %]>is the reporter</option>
      <option value="noconfirm" [% 'selected' IF input.commenter == 'noconfirm' %]>does not have canconfirm</option>
      <option value="is" [% 'selected' IF input.commenter == 'is' %]>is</option>
    </select>
    [%+ INCLUDE global/userselect.html.tmpl
       id => "commenter_is"
       name => "commenter_is"
       value => input.commenter_is
       size => 20
       emptyok => 0
       classes = input.commenter == "is" ? "" : "hidden"
    %]
    <br>

    <input type="checkbox" name="filter_last" id="filter_last" value="1"
    [% 'checked' IF input.filter_last %]>
    <label for="filter_last">where the last comment is older than</label>
    <select name="last" id="last" onChange="onLastChange()">
      <option value="30" [% 'selected' IF input.last == '30' %]>30 days</option>
      <option value="60" [% 'selected' IF input.last == '60' %]>60 days</option>
      <option value="90" [% 'selected' IF input.last == '90' %]>90 days</option>
      <option value="365" [% 'selected' IF input.last == '365' %]>one year</option>
      <option value="is" [% 'selected' IF input.last == 'is' %]>the date</option>
    </select>
    <span id="last_is_span" class="[% 'hidden' IF input.last != 'is' %]">
      <input type="text" id="last_is" name="last_is" size="11" maxlength="10"
             value="[% input.last_is FILTER html %]"
             onChange="updateCalendarLastIs(this)">
      <button type="button" class="calendar_button" id="button_calendar_last_is"
              onClick="showCalendar('last_is')"><span>Calendar</span>
      </button>
      <div id="con_calendar_last_is"></div>
    </span>
    <br>
  </td>
</tr>

<tr>
  <th>Component:</th>
  <td>
    <select name="component" id="component" multiple size="5">
    </select>
  </td>
</tr>

<tr>
  <td>&nbsp;</td>
  <td>
    <input type="submit" value="Generate Report">
  </td>
</tr>

</table>

</form>
<script [% script_nonce FILTER none %]>
  createCalendar('last_is');
</script>

[% IF input.action == 'run' %]
<hr>
[% IF bugs.size > 0 %]
  <p>
    Found [% bugs.size %] [%+ terms.bug %][% 's' IF bugs.size != 1 %]:
  </p>
  <table id="report" class="standard">
  <thead>
    <tr>
      <th>[% terms.Bug %] / Date</th>
      <th>Summary</th>
      <th>Reporter / Commenter</th>
      <th>Comment Date</th>
      <th>Last Comment</th>
    </tr>
  </thead>
  <tbody>
    [% FOREACH bug = bugs %]
      [% count = loop.count() %]
      <tr class="bz_bugitem [% count % 2 == 1 ? "bz_row_odd" : "bz_row_even" %]">
        <td>
          [% bug.id FILTER bug_link(bug.id) FILTER none %]<br>
          <time>[% bug.creation_ts.replace(' .*' '') FILTER html %]</time>
        </td>
        <td>
          [% bug.summary FILTER html %]
        </td>
        <td>
          [% INCLUDE global/user.html.tmpl who = bug.reporter %]
          [% IF bug.commenter.id != bug.reporter.id %]
          <br>[% INCLUDE global/user.html.tmpl who = bug.commenter %]
          [% END %]
        </td>
        <td>
          <time>[% bug.comment_ts FILTER html %]</time>
        </td>
        <td>
          [% bug.comment FILTER html %]
        </td>
      </tr>
    [% END %]
  </tbody>
  </table>

  <p>
    <a href="[% basepath FILTER none %]buglist.cgi?bug_id=
    [%- FOREACH bug = bugs %][% bug.id FILTER uri %],[% END -%]
    ">Show as a [% terms.Bug %] List</a>
  </p>

[% ELSE %]
  <p>
    No [% terms.bugs %] found.
  </p>
[% END %]

[% END %]

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