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

[%# INTERFACE:
  # product: object; the new product.
  # versions: array; versions for the new product.
  # components: array; components for the new product.
  # milestones: array; milestones for the new product.
  # defaults: hash; keys are names of fields, values are defaults for
  #   those fields
  #
  # verify_bug_groups: If groups need to be confirmed in addition to fields.
  #%]

[% PROCESS global/header.html.tmpl
  title = 'Изменения при смене продукта...'
  style_urls = ['skins/standard/buglist.css']
%]

<form action="process_bug.cgi" method="post">

[% SET exclude_items = ['version', 'component', 'target_milestone'] %]
[% IF verify_bug_groups %]
  [% exclude_items.push('groups', 'defined_groups') %]
[% END %]
[% Hook.process('exclude') %]

[% PROCESS "global/hidden-fields.html.tmpl"
     exclude = '^' _ exclude_items.join('|') _ '$' %]

<input type="hidden" name="confirm_product_change" value="1">
    
[%# Verify the version, component, and target milestone fields. %]
<h3>Подтвердите версию, компонент
  [%- ", план" 
      IF Param("usetargetmilestone")
         && bug.check_can_change_field('target_milestone', 0, 1) %]</h3>

<p>
[% IF Param("usetargetmilestone") 
   && bug.check_can_change_field('target_milestone', 0, 1) 
%]
  Вы перемещаете [% terms.bug %] в продукт 
  <b>[% product.name FILTER html %]</b>,
  в результате версия, компонент и/или план должны быть приведены 
  в соответствие. Установите значения для нового продукта:
[% ELSE %]
  Вы перемещаете [% terms.bug %] в продукт
  <b>[% product.name FILTER html %]</b>,
  в результате версия и компонент должны быть приведены 
  в соответствие.  Установите значения для нового продукта:
[% END %]
</p>

<table>
  <tr>
    <td>
      <b>Версия:</b><br>
      [% IF versions.size == 1 %]
        [% SET default_version = versions.0 %]
      [% ELSE %]
        [% SET default_version = defaults.version %]
      [% END %]
      [% PROCESS "global/select-menu.html.tmpl" 
                 name="version"
                 options=versions
                 default=default_version
                 size=10 %]
    </td>
    <td>
      <b>Компонент:</b><br>
      [% IF components.size == 1 %]
        [% SET default_component = components.0 %]
      [% ELSE %]
        [% SET default_component = defaults.component %]
      [% END %]
      [% PROCESS "global/select-menu.html.tmpl"
                 name="component"
                 options=components
                 default=default_component
                 size=10 %]
    </td>
    [% IF Param("usetargetmilestone") 
          && bug.check_can_change_field('target_milestone', 0, 1) 
    %]
      <td>
        <b>Запланировано:</b><br>
      [% PROCESS "global/select-menu.html.tmpl"
                 name="target_milestone"
                 options=milestones
                 default=defaults.milestone
                 size=10 %]
      </td>
    [% END %]
    [% Hook.process('field') %]
  </tr>
</table>

[% IF verify_bug_groups %]
  [% mandatory_groups = [] %]
  [% optional_groups = [] %]

  [% FOREACH gid = product.group_controls.keys %]
    [% group = product.group_controls.$gid %]
    [% NEXT UNLESS group.group.is_active %]

    [% IF group.membercontrol == constants.CONTROLMAPMANDATORY
          || (group.othercontrol ==  constants.CONTROLMAPMANDATORY && !user.in_group(group.group.name)) %]
      [% mandatory_groups.push(group) %]
    [% ELSIF (group.membercontrol != constants.CONTROLMAPNA && user.in_group(group.group.name))
              || group.othercontrol != constants.CONTROLMAPNA %]
      [% optional_groups.push(group) %]
    [% END %]
  [% END %]
  
  [% IF old_groups.size || optional_groups.size || mandatory_groups.size %]
    <h3>Подтвердите права доступа [% terms.Bug %]</h3>
  [% END %]
  
  [% IF old_groups.size %]
    <p>Перечисленные группы недопустимы для продукта '[% product.name FILTER html %]'
    или недостаточно прав доступа для назначения этих групп [% terms.bugs %].
    Доступ к [%+ terms.Bugs %] не будет в дальнейшем ограничен этими группами и может 
    стать общедоступными, если не будут указаны другие группы::<br>
    [% FOREACH group = old_groups %]
      <input type="checkbox" id="group_[% group.id FILTER html %]"
             name="groups" disabled="disabled" value="[% group.name FILTER html %]">
      <label for="group_[% group.id FILTER html %]">
        [% group.name FILTER html %]: [% group.description FILTER html %]
      </label>
      <br>
    [% END %]
    </p>
  [% END %]


  [% IF optional_groups.size %]
    <p>Следующие группы не обязательны. Вы можете ограничить видимость [% terms.bugs %]
    членами следующих групп:<br>
    [% IF multiple_bugs %]
      <script type="text/javascript">
        function turn_off(myself, id) {
            var other_checkbox = document.getElementById(id);
            if (myself.checked && other_checkbox) {
                other_checkbox.checked = false;
            }
        }
      </script>

      <table id="groups_edit_multiple">
        <tr>
          <th class="narrow_column">Удалить [% terms.bugs %] из этой группы</th>
          <th class="narrow_column">Добавить [% terms.bugs %] в эту группу</th>
          <th>Имя группы</th>
        </tr>

        [% FOREACH group = optional_groups %]
        <tr>
          <td class="center">
            <input type="checkbox" name="defined_groups"
                   id="defined_group_[% group.group.id FILTER html %]"
                   value="[% group.group.name FILTER html %]"
                   [% IF cgi.param("defined_groups").contains(group.group.name) %] checked="checked"[% END %]
                   onchange="turn_off(this, 'group_[% group.group.id FILTER html %]')">
          </td>
          <td class="center">
            <input type="checkbox" name="groups"
                   id="group_[% group.group.id FILTER html %]"
                   value="[% group.group.name FILTER html %]"
                   [% IF cgi.param("groups").contains(group.group.name) %] checked="checked"[% END %]
                   onchange="turn_off(this, 'defined_group_[% group.group.id FILTER html %]')">
          </td>
          <td>
            [% group.group.description FILTER html %]
          </td>
        </tr>
        [% END %]
      </table>
    [% ELSE %]
      [% FOREACH group = optional_groups %]
        <input type="hidden" name="defined_groups"
               value="[% group.group.name FILTER html %]">
        <input type="checkbox" id="group_[% group.group.id FILTER html %]"
               name="groups"
               [% ' checked="checked"' IF ((group.membercontrol == constants.CONTROLMAPDEFAULT && user.in_group(group.group.name))
                   || (group.othercontrol == constants.CONTROLMAPDEFAULT && !user.in_group(group.group.name))
                   || cgi.param("groups").contains(group.group.name)) %]
               value="[% group.group.name FILTER html %]">
        <label for="group_[% group.group.id FILTER html %]">
          [% group.group.name FILTER html %]: [% group.group.description FILTER html %]
        </label>
        <br>
      [% END %]
    [% END %]
    </p>
  [% END %]

  [% IF mandatory_groups.size %]
    <p>Следующие группы обязательны. Видимость [% terms.bugs %] автоматически
    ограничена членами следующих групп:<br>
    [% FOREACH group = mandatory_groups %]
      <input type="checkbox" id="group_[% group.group.id FILTER html %]"
              checked="checked" disabled="disabled"
             name="groups" value="[% group.group.name FILTER html %]">
      <label for="group_[% group.group.id FILTER html %]">
        [% group.group.name FILTER html %]: [% group.group.description FILTER html %]
      </label>
      <br>
    [% END %]
    </p>
  [% END %]
[% END %]

<input type="submit" id="change_product" value="Сохранить">

</form>
<hr>

[%# If 'id' is defined, then we are editing a single bug.
  # Else we are editing several bugs at once. %]

[% IF cgi.param('id') AND cgi.param('id').match('^\d+$') %]
  [% id = cgi.param('id') %]
  Отменить и вернуться к [% "$terms.bug $id" FILTER bug_link(id) FILTER none %]
[% ELSE %]
  Отменить и вернуться к <a href="buglist.cgi?regetlastlist=1">результатам последнего поиска</a>
[% END %]

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