[%# 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 this 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=constants.CONTROLMAPMANDATORY %]
    </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 %]
<p>
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>
Access to <i>every particular [% terms.bug %]</i> may be restricted by number of groups.
The more groups bug is restricted by, the more secret it is.
</p>

<p>Some of these groups may be optional &mdash; in this case <i>some people</i>
will be able to decide about making the bug more or less secret by setting or clearing
the checkboxes shown on the [% terms.bug %] entry/edit form for such groups.<br />
Group is optional when it has "Shown" or "Default" MemberControl or OtherControl.<br />
"Some people" means "members of the group" for MemberControl and
"everyone else" for OtherControl.</p>

<table class="admin_table">
  <tr>
    <th>
      MemberControl
    </th>
    <th>
      OtherControl
    </th>
    <th style="text-align: left">
      Interpretation
    </th>
  </tr>
  <tr>
    <td>
      Mandatory
    </td>
    <td>
      Mandatory
    </td>
    <td>
      Simplest case: all [% terms.bugs %] in this product are always restricted by this group.
    </td>
  </tr>
  <tr>
    <td>
      Default
    </td>
    <td>
      Mandatory
    </td>
    <td>
      Members of this group are able to restrict or not to restrict [% terms.bugs %] in this product by this group.
      <br />Non-members are forced to restrict their new [% terms.bugs %] by this group and
      may not change the restriction of existing [% terms.bugs %] by this group.
      <br />[% terms.Bug %] entry form has the group checkbox checked by default for group members.
    </td>
  </tr>
  <tr>
    <td>
      Default
    </td>
    <td>
      Default
    </td>
    <td>
      Everyone is able to restrict or not to restrict [% terms.bugs %] in this product by this group.
      <br />[% terms.Bug %] entry form has the group checkbox checked by default for everyone.
    </td>
  </tr>
  <tr>
    <td>
      Default
    </td>
    <td>
      NA
    </td>
    <td>
      Members of this group are able to restrict or not to restrict [% terms.bugs %] in this product by this group.
      <br />Non-members may not restrict [% terms.bugs %] by this group.
      <br />[% terms.Bug %] entry form has the group checkbox checked by default for group members.
    </td>
  </tr>
  <tr>
    <td>
      Shown
    </td>
    <td>
      Mandatory
    </td>
    <td>
      Members of this group are able to restrict or not to restrict [% terms.bugs %] in this product by this group.
      <br />Non-members are forced to restrict their new [% terms.bugs %] by this group and
      may not change the restriction of existing [% terms.bugs %] by this group.
      <br />[% terms.Bug %] entry form has the group checkbox unchecked by default for group members.
    </td>
  </tr>
  <tr>
    <td>
      Shown
    </td>
    <td>
      Default
    </td>
    <td>
      Everyone is able to restrict or not to restrict [% terms.bugs %] in this product by this group.
      <br />[% terms.Bug %] entry form has the group checkbox
      unchecked by default for members of this group, and checked by default
      for non-members of this group.
    </td>
  </tr>
  <tr>
    <td>
      Shown
    </td>
    <td>
      Shown
    </td>
    <td>
      Everyone is able to restrict or not to restrict [% terms.bugs %] in this product by this group.
      <br />[% terms.Bug %] entry form has the group checkbox unchecked by default for everyone.
    </td>
  </tr>
  <tr>
    <td>
      Shown
    </td>
    <td>
      NA
    </td>
    <td>
      Members of this group are able
      to restrict or not to restrict [% terms.bugs %] in this product by this group.
      <br />Non-members may not restrict [% terms.bugs %] by this group.
      <br />[% terms.Bug %] entry form has the group checkbox unchecked by default.
    </td>
  </tr>
  <tr>
    <td>
      NA
    </td>
    <td>
      NA
    </td>
    <td>
      [% terms.Bugs %] in this product are never restricted by this group.
      Equivalent to removing the group from the list.
    </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 %]
