{# 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 style="color:silver;">
    <th class="hide" style="">Last Name</th>
    <th class="hide">First Name</th>
    <th style="text-align: left !important;">{{ _('Name') }}</th>
    <th>{{ _('Posts') }}</th>
    <th class="hide">{# last activity seconds since epoch #}</th>
    <th width="20%">{{ _('Last activity in this community') }}</th>
    <th width="10%">
      <center>{{ _('Role') }}</center>
    </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" ] },
  { "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 style="width: 18%;"><span class="badge members-data">{{ threads_count[user] }}</span></td>
  <td class="hide">{{ seconds_since_epoch(last_activity_date) }}</td>
  <td><span class="members-data">{{ last_activity_date | age(add_direction=False, date_threshold='day') }}</span></td>
  <!-- bug jinja : do not use [not is_manager] -->
  {%- if is_manager == False %}
    <td>{{ _(role) }}</td>
  {%- else %}
    <td>
      <form action="{{ url_for('.members_post', community_id=g.community.slug) }}" method="POST"
            style="display: inline;">
        {{ csrf.field() }}
        <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.field() }}
        <input type="hidden" name="membership" value="{{ m_id }}">
        <input type="hidden" name="user" value="{{ user.id }}">
        <button style="position: relative;left: 4.5px;" 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 %}
