{# standard macros for the 'members' page.  DO NOT OVERRIDE.  Instead, you
 should override 'members_macros.html'.
 This allow to override only some of the macros without copying all others.
#}
{% from "macros/user.html" import m_user_link, m_user_photo %}

{% macro std_thead() %}
  <tr>
    <th class="hide">Last Name</th>
    <th class="hide">First Name</th>
    <th>{{ _('Name') }}</th>
    <th class="hide">{# last activity seconds since epoch #}</th>
    <th>{{ _('Last activity in this community') }}</th>
    <th>{{ _('Role') }}</th>
    {% if is_manager %}
      <th>{{ _('Action') }}</th>
    {% endif %}
  </tr>
{% endmacro %}

{% macro std_table_config() %}
  {
    "aoColumns": [
        { "bVisible": false },
        { "bVisible": false },
        { "aDataSort": [0, 1], "asSorting": [ "asc", "desc" ] },
        { "bVisible": false },
        { "aDataSort": [3], "asSorting": [ "asc", "desc" ] },
        { "asSorting": [ "asc", "desc" ]}
      {%- if is_manager %}
        , { }
      {% endif %}
    ],
    "sPaginationType": "bootstrap",
    "bFilter":         true,
    "bLengthChange":   false
  }
{% endmacro %}


{% macro std_member_row(user, m_id, role, last_activity_date) %}
  <td class="hide">{{ user.last_name }}</td>
  <td class="hide">{{ user.first_name }}</td>
  <td>
    <div class="media">
      <div class="media-left">
        {% call m_user_link(user, css="media-object") %}
          {{ m_user_photo(user, size="32") }}
        {%- endcall %}
      </div>

      <div class="media-body">
        {%- if not user.can_login %}
          <i class="glyphicon glyphicon-lock" title="{{ _('account disabled') }}"></i><s>
        {%- endif %}
        {{ m_user_link(user) }}
        <br />
        (<i>{{ user.email }}</i>)
        {%- if not user.can_login %}</s>{%- endif %}
      </div>
    </div>
  </td>
  <td class="hide">{{ seconds_since_epoch(last_activity_date) }}</td>
  <td>{{ last_activity_date | age(add_direction=False, date_threshold='day') }}</td>
  {%- if not is_manager %}
    <td>{{ _(role) }}</td>
  {%- else %}
    <td>
      <form action="{{ url_for(".members_post", community_id=g.community.slug) }}"
            method="POST" style="display: inline;">
        {{ csrf_token }}
        <input type="hidden" name="user" value="{{ user.id }}" />
        <input type="hidden" name="action" value="set-user-role" />
        <select onchange="this.form.submit();" id="role-select" name="role" class="form-control" style="width: auto;">
          <option value="member" default="default" {%- if role == 'member' %} selected="selected"{%- endif %}>{{ _("Member") }}</option>
          <option value="manager" {%- if role == 'manager' %}selected="selected"{%- endif %}>{{ _("Manager") }}</option>
        </select>
      </form>
    </td>
    <td>
      <form action="{{ url_for(".members_post", community_id=g.community.slug) }}"
            method="POST" style="display: inline;">
        {{ csrf_token }}
        <input type="hidden" name="membership" value="{{ m_id }}">
        <input type="hidden" name="user" value="{{ user.id }}">
        <button type="submit" name="action" value="delete"
                class="btn btn-danger" data-original-title="" title=""><i
                                                                           class="fa fa-times"></i></button>
      </form>
    </td>
  {% endif %}

{% endmacro %}
