{% extends "institutions/base.html" %}
{% load seahub_tags i18n %}
{% block cur_users %}tab-cur{% endblock %}


{% block right_panel %}
<h3>{% trans "Search User"%}</h3>

<form id="search-user-form" method="get" action=".">
    <label>{% trans "Email" %}</label><br />
    <input type="text" name="q" class="input" value="{{q}}" /><br />
    <input type="submit" value="{% trans "Submit" %}" class="submit" />
</form>
<h3>{% trans "Result"%}</h3>

{% if users %}
<table>
    <tr>
        <th width="36%">{% trans "Email" %} / {% trans "Name" %} / {% trans "Contact Email" %}</th>
        <th width="12%">{% trans "Status" %}</th>
        <th width="16%">{% trans "Space Used" %}</th>
        <th width="22%">{% trans "Create At / Last Login" %}</th>
        <th width="14%">{% trans "Operations" %}</th>
    </tr>

    {% for user in users %}
    <tr data-userid="{{user.email}}">
        <td>
            <a href="{% url 'institutions:user_info' user.email %}">{{ user.email }}</a>
            {% if user.name %}<br />{{ user.name }}{% endif %}
            {% if user.contact_email %}<br />{{ user.contact_email }}{% endif %}
        </td>
        <td>
            <div class="user-status">
              {% if user.is_active %}
                <span class="user-status-cur-value">{% trans "Active" %}</span>
              {% else %}
                <span class="user-status-cur-value">{% trans "Inactive" %}</span>
              {% endif %}
            </div>
        </td>
        <td style="font-size:11px;">
            <p> {{ user.space_usage|seahub_filesizeformat }} {% if user.space_quota > 0 %} / {{ user.space_quota|seahub_filesizeformat }} {% endif %} </p>
        </td>
        <td>
            {% if user.source == "DB" %}
            {{ user.ctime|tsstr_sec }} /<br />
            {% else %}
            -- /
            {% endif %}
            {% if user.last_login %}{{user.last_login|translate_seahub_time}} {% else %} -- {% endif %}
        </td>
        <td>
          {% if not user.is_self and not user.is_staff and not user.is_institution_admin %}
          <a href="#" class="remove-user-btn op vh" data-url="{% url 'institutions:user_remove' user.email %}" data-target="{{ user.email }}">{% trans "Delete" %}</a>
          {% endif %}
        </td>
    </tr>
    {% endfor %}
</table>

{% else %}
<p>{% trans "Empty" %}</p>
{% endif %}

{% endblock %}

{% block extra_script %}
<script type="text/javascript">
 addConfirmTo($('.remove-user-btn'), {
     'title':"{% trans "Delete User" %}",
     'con':"{% trans "Are you sure you want to delete %s ?" %}",
     'post': true // post request
 });

</script>
{% endblock %}
