<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      lang="en"
      metal:use-macro="context/prefs_main_template/macros/master"
      i18n:domain="plone">

<body>

<metal:main fill-slot="prefs_configlet_content"
     tal:define="errors python:request.get('errors', {});
                portal_roles python:context.portal_membership.getPortalRoles();
                Batch python:modules['Products.CMFPlone'].Batch;
                b_start python:request.get('b_start',0);
                b_size python:20;
                groupname request/groupname|nothing;
                grouproles python:request.set('grouproles', []);
                gtool context/portal_groups;
                mtool context/portal_membership;
                group python:gtool.getGroupById(groupname);
                grouptitle group/getGroupTitleOrName|groupname;
                groupMembers python:[mtool.getMemberById(m) for m in gtool.getGroupMembers(groupname)];
                isGroup nocall:gtool/isGroup;
                mq python:modules['ZTUtils'].make_query;
                groupquery python:mq(groupname=groupname);
                groupkeyquery python:mq(key=groupname);
                portal_url context/portal_url;">

    <tal:conditional condition="group">
        <tal:defines define="dummy python:request.set('grouproles', group.getRoles())" />
    </tal:conditional>

    <div class="documentEditable">
    <div id="edit-bar">
        <ul class="contentViews" id="content-views">
          <li class="selected">
                <a href=""
               tal:attributes="href string:$portal_url/${template/getId}?${groupquery}"
               i18n:translate="label_group_members">Group Members</a>
          </li>
          <li>
                <a href=""
               tal:attributes="href string:${portal_url}/prefs_group_details?${groupquery}"
                   i18n:translate="label_group_properties">Group Properties</a>
          </li>
          <li>
            <a href=""
               tal:attributes="href string:${portal_url}/@@manage-group-portlets?${groupkeyquery}"
               i18n:translate="label_group_portlets">Group Portlets</a>
          </li>
          <li>
            <a href=""
               tal:attributes="href string:${portal_url}/@@manage-group-dashboard?${groupkeyquery}"
               i18n:translate="label_group_dashboard">Group Dashboard</a>
          </li>
        </ul>

        <div class="contentActions">
          &nbsp;
        </div>
    </div>

    <div metal:use-macro="context/global_statusmessage/macros/portal_message">
      Portal status message
    </div>

    <div id="content">
        <tal:ifnogroups tal:condition="not:group | nothing">
          <h1 class="documentFirstHeading"
              i18n:translate="heading_group_members">Group Members</h1>

          <div id="content-core">
              <a href=""
                 class="link-parent"
                 tal:attributes="href string:$portal_url/@@usergroup-groupprefs"
                 i18n:translate="label_up_to_groups_overview">
                Up to Groups Overview
              </a>

              <p i18n:translate="label_no_group_specified">No group was specified.</p>

              <p>
                <a href="@@usergroup-groupprefs" i18n:translate="label_find_group">Find a group here</a>
              </p>
          </div>
        </tal:ifnogroups>

        <tal:ifgroups tal:condition="group | nothing">
          <h1 class="documentFirstHeading"
              i18n:translate="heading_group_members_of">
              Members of the <span tal:content="grouptitle" tal:omit-tag="" i18n:name="groupname">Groupname</span> group
          </h1>

          <div id="content-core">
              <a href=""
                 class="link-parent"
                 tal:attributes="href string:$portal_url/@@usergroup-groupprefs"
                 i18n:translate="label_up_to_groups_overview">
                Up to Groups Overview
              </a>

              <p i18n:translate="description_group_members_of">
                You can add or remove groups and users from this particular group here. Note that this
                doesn't actually delete the group or user, it is only removed from this group.
              </p>

              <form action=""
                        name="groups"
                        method="post"
                        tal:attributes="action string:$portal_url/${template/getId}"
                        tal:define="searchstring request/searchstring | nothing;
                                    findAll python:'form.button.FindAll' in request.keys();
                                    ignoreUsersGroups python: group.getAllGroupMembers() + [group,];
                                    results python:(searchstring or findAll) and context.prefs_user_group_search(searchstring, 'all', ignore=ignoreUsersGroups) or [];
                                    batch python:Batch(results, b_size, int(b_start), orphan=1);
                                    many_users context/portal_properties/site_properties/many_users">
                    <h2 i18n:translate="heading_groupmembers_current">Current group members</h2>
                    <table class="listing" summary="Group Members Listing"
                       tal:condition="groupMembers">

                        <tr>
                            <th>
                                <input class="noborder"
                                       type="checkbox"
                                       src="select_all_icon.png"
                                       name="selectButton"
                                       title="Select all items"
                                       onClick="toggleSelect(this, 'delete:list');"
                                       tal:attributes="src string:$portal_url/select_all_icon.png"
                                       alt="Select all items"
                                       i18n:attributes="title label_select_all_items; alt label_select_all_items;"/>
                                       <!--Remove user from this group-->
                            </th>
                            <th i18n:translate="listingheader_group_user_name">Group/User name</th>
                            <th i18n:translate="listingheader_email_address">E-mail Address</th>
                        </tr>

                        <tal:block tal:repeat="this_user groupMembers">
                          <tr tal:condition="python:this_user is not None"
                              tal:define="oddrow repeat/this_user/odd"
                              tal:attributes="class python:test(oddrow,'odd','even')">
                              <td class="listingCheckbox">
                                  <input
                                         type="checkbox"
                                         class="noborder notify"
                                         name="delete:list"
                                         tal:attributes="value this_user/getId;
                                                         disabled python:this_user.canRemoveFromGroup(groupname) and default or 'disabled'" />
                              </td>

                              <tal:block tal:condition="python: isGroup(this_user)">
                                <td>
                                  <img src="group.png" alt="" />
                                  <a href="" tal:attributes="href python:'prefs_group_details?' + mq(groupname=this_user.getGroupName())"
                                               tal:content="this_user/getGroupTitleOrName | default">
                                    <span i18n:translate="link_groupname_not_available">
                                        groupname not available
                                    </span>
                                  </a>
                                </td>
                              </tal:block>

                              <tal:block tal:condition="python: not isGroup(this_user)">
                                <td>
                                  <img src="user.png" alt="" />
                                  <a href="" tal:attributes="href python:'prefs_user_details?' + mq(userid=this_user.getId())"
                                      tal:content="this_user/getId | default">
                                      <span i18n:translate="link_username_not_available">
                                          username not available
                                      </span>
                                  </a>
                                </td>
                              </tal:block>

                              <td tal:define="email python: this_user.getProperty('email')">
                                  <a  href="#"
                                      tal:attributes="href string:mailto:${email}"
                                      title="Send a mail to this user"
                                      i18n:attributes="title title_send_mail_to_user;"
                                      tal:condition="email">
                                      <span tal:replace="email" />
                                  </a>
                              </td>
                          </tr>
                        </tal:block>
                    </table>


                    <p tal:condition="not:groupMembers" i18n:translate="decription_no_members_assigned">There is no group or user attached to this group.</p>

                    <input class="destructive"
                           type="submit"
                           name="form.button.Edit"
                           value="Remove selected groups / users"
                           i18n:attributes="value label_remove_selected_users;"
                           tal:condition="groupMembers" />

                    <h2 i18n:translate="heading_search_newmembers">Search for new group members</h2>

                    <input type="hidden" name="groupname" value="groupname" tal:attributes="value groupname" />
                    <input type="hidden" name="form.submitted" value="1" />

                    <table class="listing" summary="Groups">
                      <tr>
                        <th colspan="2">
                          <span tal:omit-tag="" i18n:translate="label_quick_search">Quick search</span>:
                            <input class="quickSearch"
                                   type="text"
                                   name="searchstring"
                                   value=""
                                   tal:attributes="value searchstring;"
                                   />

                            <input type="submit"
                                   class="searchButton"
                                   name="form.button.Search"
                                   value="Search"
                                   i18n:attributes="value label_search;" />
                            <input type="submit"
                                   class="searchButton"
                                   name="form.button.FindAll"
                                   value="Show all"
                                   i18n:attributes="value label_search_large;"
                                   tal:condition="not:many_users" />
                        </th>
                      </tr>
                      <tr tal:condition="batch">
                        <th>
                            <input class="noborder"
                                   type="checkbox"
                                   src="select_all_icon.png"
                                   name="selectButton"
                                   title="Select all items"
                                   onClick="toggleSelect(this, 'add:list');"
                                   tal:attributes="src string:$portal_url/select_all_icon.png"
                                   alt="Select all items"
                                   i18n:attributes="title label_select_all_items; alt label_select_all_items;"/>
                        </th>

                        <th i18n:translate="listingheader_group_user_name">Group/User name</th>
                      </tr>

                      <tal:block repeat="this_user batch">
                        <tr tal:define="oddrow repeat/this_user/odd"
                            tal:attributes="class python:test(oddrow,'odd','even')">

                          <td class="listingCheckbox">
                            <input type="checkbox"
                                   class="noborder"
                                   name="add:list"
                                   value="value"
                                     tal:attributes="value this_user/getId" />
                          </td>

                          <td>
                              <tal:block tal:condition="python:not isGroup(this_user)">
                                  <img src="user.png" alt="" />
                                  <a href="" tal:attributes="href python:'prefs_user_details?' + mq(userid=this_user.getId())"
                                           tal:content="this_user/getId | default">
                                           <span i18n:translate="link_username_not_available">username not available</span>
                                  </a>
                              </tal:block>
                              <tal:block tal:condition="python: isGroup(this_user)">
                                  <img src="group.png" alt="" />
                                  <a href="" tal:attributes="href python:'prefs_group_details?' + mq(groupname=this_user.getGroupName())"
                                             tal:content="this_user/getGroupTitleOrName | default">
                                             <span i18n:translate="link_groupname_not_available">
                                             groupname not available</span>
                                  </a>
                              </tal:block>
                          </td>
                        </tr>
                      </tal:block>

                      <tr tal:condition="not:batch">

                        <td tal:condition="searchstring"
                          i18n:translate="text_nomatches"
                          style="text-align:center;">No matches</td>

                        <tal:block tal:condition="not:searchstring">
                          <td tal:condition="site_properties/many_users"
                            class="discreet"
                            i18n:translate="text_no_searchstring_large"
                            style="text-align:center; font-size: 100%;">
                            Enter a group or user name to search for.
                          </td>
                          <td tal:condition="not:site_properties/many_users"
                            class="discreet"
                            i18n:translate="text_no_searchstring"
                            style="text-align:center; font-size: 100%;">
                            Enter a group or user name to search for or click 'Show All'.
                          </td>
                        </tal:block>

                      </tr>

                    </table>

                    <input type="hidden" value="b_start" name="b_start"
                             tal:attributes="value b_start"/>

                    <div metal:use-macro="context/batch_macros/macros/navigation" />

                    <input class="context"
                            type="submit"
                            name="form.button.Add"
                            value="Add selected groups and users to this group"
                            tal:condition="batch"
                            i18n:attributes="value label_add_users_to_group;" />

                    <input tal:replace="structure context/@@authenticator/authenticator" />

              </form>
          </div>
        </tal:ifgroups>
    </div>
    </div>

</metal:main>
</body>
</html>

