[%# This Source Code Form is subject to the terms of the Mozilla Public
  # License, v. 2.0. If a copy of the MPL was not distributed with this
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  #
  # This Source Code Form is "Incompatible With Secondary Licenses", as
  # defined by the Mozilla Public License, v. 2.0.
  #%]

[% USE Bugzilla %]
[% cgi = Bugzilla.cgi %]

[% PROCESS global/header.html.tmpl
  title="Ожидание согласования"
  generate_api_token = 1
  onload="var f = document.request_form; selectProduct(f.product, f.component, null, null, 'Все');"
  javascript_urls=["js/productform.js", "js/field.js"]
  style_urls = ['skins/standard/buglist.css']
  yui = ['autocomplete']
%]

<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 Param('useclassification') %]
    [% 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 FILTER js %]'[% ", " UNLESS loop.last %] [%- END -%]];
  [% n = n+1 %]
[% END %]

<p>
Вошедшим в систему пользователям по умолчанию отображаются только
согласования, адресованные пользователю или запрошенные им. Критерии
отображения могут быть изменены ниже. Анонимным пользователям отображаются
все согласования, доступ к которым не ограничен членством в группах.
</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>Инициатор:</th>
      <td>
        [% INCLUDE global/userselect.html.tmpl
           id => "requester"
           name => "requester"
           value => cgi.param('requester')
           size => 20
           emptyok => 1
           field_title => "Email инициатора"
        %]
      </td>
      <th>Продукт:</th>
      <td>
        [% INCLUDE "global/product-select.html.tmpl"
           id       => "product"
           name     => "product"
           add      => "Все"
           onchange => "selectProduct(this, this.form.component, null, null, 'Все');"
        %]
      </td>
      <th>Вид согласования:</th>
      <td>
        [% PROCESS "global/select-menu.html.tmpl"
                    name="type"
                    options=types
                    default=cgi.param('type') %]
      </td>

      [%# We could let people see a "queue" of non-pending requests. %]
      <!--
      <th>Состояние:</th>
      <td>
        [%# PROCESS "global/select-menu.html.tmpl"
                    name="status"
                    options=["все", "?", "+-", "+", "-"]
                    default=cgi.param('status') %]
      </td>
      -->

    </tr>
    <tr>
      <th>Адресат:</th>
      <td>
        [% INCLUDE global/userselect.html.tmpl
           id => "requestee"
           name => "requestee"
           value => cgi.param('requestee')
           size => 20
           emptyok => 1
           hyphenok => 1
           field_title => "Email адресата запроса или \"-\" (дефис) для запросов без конкретного адресата"
        %]
      </td>
      <th>Компонент:</th>
      <td>
        <select name="component">
          <option value="">Все</option>
          [% FOREACH comp = components %]
            <option value="[% comp FILTER html %]" [% "selected" IF cgi.param('component') == comp %]>
              [% comp FILTER html %]</option>
          [% END %]
        </select>
      </td>
      <th>Группировать по:</th>
      <td>
        [% groups = {
            "Инициатору" => 'requester' ,
            "Адресату" => 'requestee',
            "Виду согласования" => 'type' ,
            "Продукту/Компоненту" => 'category'
          } %]
        [% PROCESS "global/select-menu.html.tmpl" name="group" options=groups default=cgi.param('group') %]
      </td>
    </tr>
    <tr>
      <th></th>
      <td>
        <select id="do_union" name="do_union">
          <option value="0">Соответствие инициатору И адресату</option>
          <option value="1" [% 'selected="selected"' IF cgi.param('do_union') %]>
            Соответствие инициатору ИЛИ адресату</option>
        </select>
      </td>
      <td colspan="3"></td>
      <td><input type="submit" id="filter" value="Выбрать"></td>
    </tr>
  </table>
</form>

[% column_headers = {
      "type"       => "Вид" ,
      "status"     => "Состояние" ,
      "bug"        => "$terms.Bug" ,
      "attachment" => "Приложение" ,
      "requester"  => "Инициатор" ,
      "requestee"  => "Адресат" ,
      "created"    => "Дата создания" ,
      "category"   => "Продукт/Компонент"    } %]

[% DEFAULT display_columns = ["requester", "requestee", "type", "bug", "attachment", "created"]
           group_field     = "Адресату"
           group_value     = ""
%]

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

[% IF requests.size == 0 %]
  <p>
    Нет незавершенных согласований.
  </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>
      [% FOREACH column = display_columns %]
        [% NEXT IF column == group_field || excluded_columns.contains(column) %]
        <td>
          [% PROCESS "display_$column" %]
          [% Hook.process('after_column') %]
        </td>
      [% END %]
    </tr>
  [% END %]
  [% PROCESS display_buglist %]
  <br><br>
  <a href="request.cgi?[% urlquerypart FILTER html %]&amp;ctype=csv">Просмотреть в формате CSV</a>
[% END %]

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

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

  <h3>[% column_headers.$group_field %]: 
    [%+ (request.$group_field || "Нет") FILTER email FILTER html %]</h3>
  <table class="requests">
    <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 FILTER html %]
[% END %]

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

[% BLOCK display_bug %]
  <a href="show_bug.cgi?id=[% request.bug_id %]"
     [%- ' class="bz_secure"' IF request.restricted %]>
    [% request.bug_id %]: [%+ request.bug_summary FILTER 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 FILTER html %]</a>
  [% ELSE %]
    N/A
  [% END %]
[% END %]

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

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

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

[% BLOCK display_buglist %]
  </table>
  [% NEXT UNLESS buglist.keys.size %]
  <a href="buglist.cgi?bug_id=
           [%- buglist.keys.nsort.join(",") FILTER html %]">Просмотреть как
  список [%+ terms.bugs_gen %]</a>
[% END %]
