<h1 tal:replace="structure here/manage_page_header">Header</h1>
<h2 tal:replace="structure here/manage_tabs"> TABS </h2>

<div tal:define="user_id request/user_id|options/user_id|nothing;
                 search_term request/search_term|options/search_term|nothing;
                 acl_users nocall: here/acl_users;
                 my_url here/absolute_url;"
     tal:omit-tag="">

<p class="form-help">
  Use this form to find specific users and manage their domain mapping
  settings.
</p>

<table width="98%" cellpadding="2">
  <tr class="list-header">
    <td class="list-header">
      <span class="form-label">
        Find user by login
      </span>
    </td>
  </tr>
</table>

<form method="post" action=""
      tal:attributes="action string:${my_url}/manage_map">
  &nbsp;<input type="text" name="user_id" size="30" />&nbsp;
  <input type="submit" value=" Search " />
</form>

<div tal:condition="search_term"
     tal:omit-tag="">
  <p><hr /></p>
</div>

<div tal:condition="user_id"
     tal:omit-tag="">
  <div tal:define="user_ob python: acl_users.getUser(user_id);
                   user_map python: here.listMappingsForUser(user_id)">

    <table width="98%" cellpadding="2">
      <tr class="list-header">
        <td class="list-header">
          <span class="form-label">
            Domain mappings for <span tal:replace="user_id">foo</span>
          </span>
        </td>
      </tr>
    </table>

    <p class="form-help"
       tal:condition="not: user_map">
      No data found for user <span tal:replace="user_id"> foo </span>.
    </p>

    <form method="post" action=""
          tal:condition="user_map"
          tal:attributes="action string:${my_url}/manage_removeMappings">
      <input type="hidden" name="user_id" value=""
             tal:attributes="value user_id" />

      <table width="98%">
        <tr>
          <td width="16"> &nbsp; </td>
          <td class="form-label"> Match Type </td>
          <td class="form-label"> Match String </td>
          <td class="form-label"> Roles </td>
        </tr>

        <tr tal:repeat="match_info python: here.listMappingsForUser(user_id)">
          <td width="16" class="form-element">
            <input type="checkbox" name="match_ids:list" value=""
                   tal:attributes="value match_info/match_id" />
          </td>
          <td class="form-text"
              tal:content="match_info/match_type">
            type
          </td>
          <td class="form-text"
              tal:content="match_info/match_string">
            string
          </td>
          <td class="form-text"
              tal:content="python: ', '.join(match_info.get('roles'))">
            foo, bar
          </td>
        </tr>

        <tr>
          <td width="16">&nbsp;</td>
          <td colspan="3" class="form-element">
            <input type="submit" value=" Delete " />
          </td>
        </tr>
      </table>

    </form>

    <div tal:condition="user_ob"
         tal:omit-tag="">
      <table width="98%" cellpadding="2">
        <tr class="list-header">
          <td class="list-header">
            <span class="form-label">
              Add new domain mapping for user 
              <span tal:replace="user_id"> foo </span>.
            </span>
          </td>
        </tr>
      </table>

      <form method="post" action=""
            tal:attributes="action string:${my_url}/manage_addMapping">
        <input type="hidden" name="user_id" value=""
               tal:attributes="value user_id" />
        <table width="98%" cellpaddding="2">
          <tr>
            <td class="form-label"> Match Type </td>
            <td class="form-element">
              <select name="match_type">
                <option tal:repeat="match here/listMatchTypes"
                        tal:attributes="value match"
                        tal:content="match">
                  foo match
                </option>
              </select>
            </td>
          </tr>
          <tr>
            <td class="form-label"> Match String </td>
            <td class="form-element">
              <input type="text" size="30" name="match_string" />
            </td>
          </tr>
          <tr>
            <td class="form-label" valign="top"> Roles to convey </td>
            <td class="form-element">
              <span tal:repeat="role here/valid_roles">
                <input type="checkbox" name="roles:list" value=""
                       tal:attributes="value role" />
                  <span tal:replace="role"> Foobar </span><br />
              </span>
            </td>
          </tr>
          <tr>
            <td colspan="2" class="form-element">
              <input type="submit" value=" Add " />
            </td>
          </tr>
        </table>
      </form>

    </div>

  </div>
</div>

</div>

<h1 tal:replace="structure here/manage_page_footer">Footer</h1>
