[%# Totally redesigned Edit Group Controls for product page
  # License: Dual-license GPL 3.0+ or MPL 1.1+
  # Contributor(s): Vitaliy Filippov <vitalif@mail.ru>
  #                 Joel Peshkin <bugreport@peshkin.net>
  #%]

[% title = BLOCK %]
    Edit Group Controls for [% product.name FILTER html %]
[% END %]

[% PROCESS global/header.html.tmpl
  title = title
  style_urls = ['skins/standard/admin_groupcontrol.css']
  javascript_urls = ["js/admin_groupcontrol.js"]

%]

[% control_options = [
  constants.CONTROLMAPNA,
  constants.CONTROLMAPSHOWN,
  constants.CONTROLMAPDEFAULT,
  constants.CONTROLMAPMANDATORY,
] %]

[% all_groups = product.group_controls_full_data.values.sort("name") %]
[% groups = product.group_controls.values.sort("name") %]

[% BLOCK group_select %]
  <select name="[% id %]" id="[% id %]">
    [% FOR g = all_groups %]
    <option value="[% g.id %]" [% " selected=\"selected\"" IF group_id == g.id %]>[% g.name | html %]</option>
    [% END %]
  </select>
[% END %]

[% BLOCK control_select %]
  <select name="[% id %]" id="[% id %]" data-lastvalue="0">
    [% FOR i = control_options %]
    <option value="[% i %]" [% " selected=\"selected\"" IF control == i %]>[% lc_messages.control_options.$i %]</option>
    [% END %]
  </select>
[% END %]

[% BLOCK group_list %]
<ul id="[% name %]_list" class="group_list">
  [% foundone = 0 %]
  [% FOR group = groups %]
  [% IF group.$name %]
  [% foundone = 1 %]
  <li id="li_[% name %]_[% group.id %]">
    <a href="#" class="icon-delete" title="Delete this group" onclick="deleteGroupCheckbox('[% name %]_[% group.id %]'); return false;"></a>
    <input type="checkbox" name="[% name %]_[% group.id %]" id="[% name %]_[% group.id %]" value="1" checked="checked" style="display: none;" />
    <label for="[% name %]_[% group.id %]">[% group.name | html %]</label>
  </li>
  [% END %]
  [% END %]
  [% IF NOT foundone %]
  <li id="li_[% name %]_empty" class="group_empty">
    &lt;no groups&gt;
  </li>
  [% END %]
</ul>
<p style="clear: both">
  Add a group:
  <select id="add_[% name %]" onkeydown="if (event.keyCode == 10 || event.keyCode == 13) { addListGroup('[% name %]'); }">
  [% FOR g = all_groups %]
    <option value="[% g.id %]">[% g.name | html %]</option>
  [% END %]
  </select>
  <a href="#" class="icon-add" onclick="addListGroup('[% name %]'); return false;">Add new group</a>
</p>
[% END %]


<form method="post" action="editproducts.cgi">
  <input type="hidden" name="action" value="updategroupcontrols">
  <input type="hidden" name="product" value="[% product.name | html %]">
  <input type="hidden" name="token" value="[% token | html %]">

  <h2>Group controls for product [% product.name | html %]</h2>

  <h3>Access control (Member/Other):</h3>

    [% PROCESS help_control %]

    [% foundone = 0 %]
    [% cnt_row = 1 %]
    <table id="control_list" class="table_group_list">
    [% FOR group = groups %]
    [% IF group.membercontrol OR group.othercontrol %]
    [% foundone = 1 %]
    <tr id="control_[% cnt_row %]">
        <td>[%+ PROCESS group_select id='group_' _ cnt_row, group_id=group.id  %]</td>
        <td>[%+ PROCESS control_select id='membercontrol_' _ cnt_row, control=group.membercontrol %]</td>
        <td>[%+ PROCESS control_select id='othercontrol_' _ cnt_row, control=group.othercontrol %]</td>
        <td>used in [% group.bug_count || 0 %] bugs</td>
        <td><a href="#" class="icon-delete" onclick="deleteGroup(this, [% cnt_row %]); return false;">Delete</a></td>
    </tr>
    [% cnt_row = cnt_row + 1 %]
    [% END %]
    [% END %]
    
    [% IF NOT foundone %]
    <tr id="control_empty" class="group_empty">
    <td colspan="5">
          &lt;no control groups&gt;
    </td>
    </tr>
    [% END %]
    </table>

    <div id="control_add">
        <a href="#" class="icon-add" onclick="addNewGroup(); return false;">Add new group</a>

        <select id="etalon_groups">
          [% FOR g = all_groups %]
          <option value="[% g.id %]">[% g.name | html %]</option>
          [% END %]
        </select>

        [%+ PROCESS control_select id='etalon_control', control=0 %]
    </div>

    <script language="JavaScript">
        var count_rows = [% cnt_row %];
    </script>

    <div class="control_column_left">
        <h3>Restrict bug entry to intersection of following groups:</h3>
        [% PROCESS help_entry %]
        [% PROCESS group_list name='entry' %]

        <h3>Restrict editing and commenting bugs to:</h3>
        [% PROCESS help_canedit %]
        [% PROCESS group_list name='canedit' %]
    </div>
    <div class="control_column_right">
        <h3>Allow product and component administration for members of any of the following groups:</h3>
        [% PROCESS help_editcomponents %]
        [% PROCESS group_list name='editcomponents' %]

        <h3>Allow to confirm bugs for:</h3>
        [% PROCESS help_canconfirm %]
        [% PROCESS group_list name='canconfirm' %]

        <h3>Allow to change any field of this product bugs for:</h3>
        [% PROCESS help_editbugs %]
        [% PROCESS group_list name='editbugs' %]
    </div>

    <div class="control_save">
        <span id="submit_group_control">
            <input type="submit" value="Save changes" />
        </span>
    </div>
</form>

[% BLOCK help_entry %]
<p>
If any group has <b>Entry</b> selected, then this product will
restrict [% terms.bug %] entry to only those users who are members of all the
groups with entry selected.
</p>
[% END %]

[% BLOCK help_canedit %]
If any group has <b>Canedit</b> selected, then this product
will be read-only for any users who are not members of all of
the groups with Canedit selected. ONLY users who are members of
all the canedit groups will be able to edit. This is an additional
restriction that further restricts what can be edited by a user.
</p>
[% END %]

[% BLOCK help_editcomponents %]
<p>
Any group having <b>editcomponents</b> selected allows users who are
in this group to edit all aspects of this product, including components,
milestones and versions.
</p>
[% END %]

[% BLOCK help_canconfirm %]
<p>
Any group having <b>canconfirm</b> selected allows users who are
in this group to confirm [% terms.bugs %] in this product.
</p>
[% END %]

[% BLOCK help_editbugs %]
<p>
Any group having <b>editbugs</b> selected allows users who are
in this group to edit all fields of [% terms.bugs %] in this product.
</p>
[% END %]

[% BLOCK help_control %]

<p>
  Help on Member/Other group control combinations:
  <input type="button" id="control_help_btn" value="Show &#x25BE;" onclick="helpToggle(this.id, 'control_help')" />
</p>

<div id="control_help" class="help_popup" style="display: none">
<p>
Every bug can be 'placed' into number of groups. The more groups bug is placed in,
the more secret it is.
</p>

<p>Some of these groups can be optional &mdash; in this case
some people will be able to decide about making the bug more or less secret.
"Some people" means "members of the group" for MemberControl and
"non-members of the group" for OtherControl.</p>

<p>
The <b>MemberControl</b> and <b>OtherControl</b> fields
indicate which [% terms.bugs %] will be placed in
this group according to the following definitions.
</p>

<table class="help_table">
  <tr>
    <th>
      MemberControl
    </th>
    <th>
      OtherControl
    </th>
    <th style="text-align: left">
      Interpretation
    </th>
  </tr>
  <tr>
    <td>
      NA
    </td>
    <td>
      NA
    </td>
    <td>
      [% terms.Bugs %] in this product are never associated with this group.
    </td>
  </tr>
  <tr>
    <td>
      Shown
    </td>
    <td>
      NA
    </td>
    <td>
      [% terms.Bugs %] in this product are permitted to be restricted to this
      group.  Users who are members of this group will be able to place [% terms.bugs %] in
      this group.
    </td>
  </tr>
  <tr>
    <td>
      Shown
    </td>
    <td>
      Shown
    </td>
    <td>
      [% terms.Bugs %] in this product can be placed in this group by anyone
      with permission to edit the [% terms.bug %] even if they are not a member
      of this group.
    </td>
  </tr>
  <tr>
    <td>
      Shown
    </td>
    <td>
      Default
    </td>
    <td>
      [% terms.Bugs %] in this product can be placed in this group by anyone
      with permission to edit the [% terms.bug %] even if they are not a member
      of this group. Non-members place [% terms.bugs %] in this group by default.
    </td>
  </tr>
  <tr>
    <td>
      Shown
    </td>
    <td>
      Mandatory
    </td>
    <td>
      [% terms.Bugs %] in this product are permitted to be restricted to this
      group.  Users who are members of this group will be able to place [% terms.bugs %]
       in this group.  Non-members will be forced to restrict [% terms.bugs %] to
       this group when they initially enter [% terms.abug %] in this product.
    </td>
  </tr>
  <tr>
    <td>
      Default
    </td>
    <td>
      NA
    </td>
    <td>
      [% terms.Bugs %] in this product are permitted to be restricted to this
      group and are placed in this group by default.  Users who are members of this
      group will be able to place [% terms.bugs %] in this group.
    </td>
  </tr>
  <tr>
    <td>
      Default
    </td>
    <td>
      Default
    </td>
    <td>
      [% terms.Bugs %] in this product are permitted to be restricted to this
      group and are placed in this group by default.  Users who are members of this group
      will be able to place [% terms.bugs %] in this group.  Non-members will be
      able to restrict [% terms.bugs %] to this group on entry and will do so by default.
    </td>
  </tr>
  <tr>
    <td>
      Default
    </td>
    <td>
      Mandatory
    </td>
    <td>
      [% terms.Bugs %] in this product are permitted to be restricted to this
      group and are placed in this group by default.  Users who are members of this group
      will be able to place [% terms.bugs %] in this group. Non-members will be forced
      to place [% terms.bugs %] in this group on entry.
    </td>
  </tr>
  <tr>
    <td>
      Mandatory
    </td>
    <td>
      Mandatory
    </td>
    <td>
      [% terms.Bugs %] in this product are required to be restricted to this
      group.  Users are not given any option.
    </td>
  </tr>
</table>
<p>
Please note that the above table delineates the only allowable combinations
for the <b>MemberControl</b> and <b>OtherControl</b> field settings.
Attempting to submit a combination not listed there (e.g. Mandatory/NA,
Default/Shown, etc.) will produce an error message.
</p>
</div>
[% END %]

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