[%# 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 Bug Tracking System.
  #
  # The Initial Developer of the Original Code is Netscape Communications
  # Corporation. Portions created by Netscape are
  # Copyright (C) 1998 Netscape Communications Corporation. All
  # Rights Reserved.
  #
  # Contributor(s): Myk Melez <myk@mozilla.org>
  #%]

[% PROCESS global/header.html.tmpl
  title="Request Queue"
  onload="var f = document.request_form; selectProduct(f.product, f.component, null, null, 'Any');"
  javascript_urls=["js/productform.js"]
%]

<script type="text/javascript">
  var useclassification = false; // No classification level in use
  var first_load = true; // Is this the first time we load the page?
  var last_sel = []; // Caches last selection
  var cpts = new Array();
  [% n = 1 %]
  [% IF Bugzilla.get_field('classification').enabled %]
    [% FOREACH clas = user.get_selectable_classifications %]
      [% FOREACH prod = user.get_selectable_products(clas.id) %]
        [%+ PROCESS js_comp %]
      [% END %]
    [% END %]
  [% ELSE %]
    [% FOREACH prod = user.get_selectable_products %]
      [%+ PROCESS js_comp %]
    [% END %]
  [% END %]
</script>

[% BLOCK js_comp %]
  cpts['[% n %]'] = [
    [%- FOREACH comp = prod.components %]'[% comp.name | js %]'[% ", " UNLESS loop.last %] [%- END -%]];
  [% n = n+1 %]
[% END %]

<p>
When you are logged in, only requests made by you or addressed to you
are shown by default.  You can change the criteria using the form below.
When you are logged out, all pending requests that are not restricted
to some group are shown by default.
</p>

<form id="request_form" name="request_form" action="request.cgi" method="get">
  <input type="hidden" name="action" value="queue" />

  <table id="filtering">
    <tr>
      <th align="left">Requester:</th>
      <td><input type="text" name="requester" value="[% selected_requester | html %]" size="20" 
           title="Requester's email address"></td>
      <th align="right">Product:</th>
      <td>
        <select name="product" onchange="selectProduct(this, this.form.component, null, null, 'Any');">
          <option value="">Any</option>
          [% IF Bugzilla.get_field('classification').enabled %]
            [% FOREACH c = user.get_selectable_classifications %]
              <optgroup label="[% c.name | html %]">
                [% FOREACH p = user.get_selectable_products(c.id) %]
                  <option value="[% p.name | html %]"
                    [% " selected" IF selected_product == p.name %]>
                    [% p.name | html %]
                  </option>
                [% END %]
              </optgroup>
            [% END %]
          [% ELSE %]
            [% FOREACH p = user.get_selectable_products %]
              <option value="[% p.name | html %]"
                [% " selected" IF selected_product == p.name %]>
                [% p.name | html %]
              </option>
            [% END %]
          [% END %]
        </select>
      </td>
      <th align="right">Flag:</th>
      <td>
        [% PROCESS "global/select-menu.html.tmpl"
                    name="type"
                    options=types
                    default=selected_type %]
      </td>

    </tr>
    <tr>
      <th align="left">Requestee:</th>
      <td><input type="text" name="requestee" value="[% selected_requestee | html %]" size="20" 
           title="Requestee's email address or &quot;-&quot; (hyphen) for requests with no requestee"></td>
      <th align="right">Component:</th>
      <td>
        <select name="component">
          <option value="">Any</option>
          [% FOREACH comp = components %]
            <option value="[% comp | html %]" [% "selected" IF selected_component == comp %]>
              [% comp | html %]</option>
          [% END %]
        </select>
      </td>
      <th align="right">Group By:</th>
      <td>
        [% groups = {
            "Requester" => 'requester' ,
            "Requestee" => 'requestee',
            "Flag" => 'type' ,
            "Product/Component" => 'category'
          } %]
        [% PROCESS "global/select-menu.html.tmpl" name="group" options=groups default=selected_group %]
      </td>
      <th align="right">Status:</th>
      <td>
        [% PROCESS "global/select-menu.html.tmpl"
                    name="status"
                    options=["all", "?", "+-", "+", "-"]
                    default=selected_status %]
      </td>
      <td><input type="submit" id="filter" value="Filter" /></td>
    </tr>
  </table>

</form>

[% column_headers = {
      "type"       => "Flag" ,
      "status"     => "Status" ,
      "bug"        => "$terms.Bug" ,
      "attachment" => "Attachment" ,
      "requester"  => "Requester" ,
      "requestee"  => "Requestee" ,
      "created"    => "Created" ,
      "category"   => "Product/Component"    } %]

[% DEFAULT display_columns = ["requester", "requestee", "type", "bug", "attachment", "created"]
           group_field     = "Requestee"
           group_value     = ""
%]

[% IF debug %]
  <p>[% query | html %]</p>
[% END %]

[% IF requests.size == 0 %]
  <p>
    No requests.
  </p>
[% ELSE %]
  [% FOREACH request = requests %]
    [% IF request.$group_field != group_value || loop.first %]
      [% group_value = request.$group_field %]
      [% PROCESS display_buglist UNLESS loop.first %]
      [% PROCESS start_new_table %]
    [% END %]
    [% buglist.${request.bug_id} = 1 %]
    <tr class="[% loop.index % 2 ? 'even_row' : 'odd_row' %]">
      [% FOREACH column = display_columns %]
        [% NEXT IF column == group_field || excluded_columns.contains(column) %]
        <td>[% PROCESS "display_$column" %]</td>
      [% END %]
    </tr>
  [% END %]
  [% PROCESS display_buglist %]
[% END %]

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

[% BLOCK start_new_table %]
  [% buglist = {} %]

  <h3>[% column_headers.$group_field %]: 
    [%+ (request.$group_field || "None") | email | html %]</h3>
  <table class="admin_table">
    <tr>
      [% FOREACH column = display_columns %]
        [% NEXT IF column == group_field || excluded_columns.contains(column) %]
        <th>[% column_headers.$column %]</th>
      [% END %]
    </tr>
[% END %]

[% BLOCK display_type %]
  [% request.type | html %]
[% END %]

[% BLOCK display_status %]
  [% request.status %]
[% END %]

[% BLOCK display_bug %]
  <a href="show_bug.cgi?id=[% request.bug_id %]">
    [% request.bug_id %]: [%+ request.bug_summary | html %]</a>
[% END %]

[% BLOCK display_attachment %]
  [% IF request.attach_id %]
    <a href="attachment.cgi?id=[% request.attach_id %]&amp;action=edit">
      [% request.attach_id %]: [%+ request.attach_summary | html %]</a>
  [% ELSE %]
    N/A
  [% END %]
[% END %]

[% BLOCK display_requestee %]
  [% request.requestee | email | html %]
[% END %]

[% BLOCK display_requester %]
  [% request.requester | email | html %]
[% END %]

[% BLOCK display_created %]
  [% request.created | time %]
[% END %]

[% BLOCK display_buglist %]
  </table>
  [% NEXT UNLESS buglist.keys.size %]
  <a href="buglist.cgi?bug_id_type=anyexact&bug_id=
           [%- buglist.keys.nsort.join(",") | html %]">(view as
  [%+ terms.bug %] list)</a>
[% END %]
