{% extends "eventum_admin.html" %}
{% import "eventum_macros.html" as macros %}

{% block js %}
{{ super() }}
<script type="text/javascript" src="{{ url_for('eventum.static', filename='js/users/users.js') }}"></script>
{% endblock %}

{% block title %}Manage your Whitelist{% endblock %}
{% block pagetitle %}Users{% endblock %}

{% set active_page='Users' %}

{% block barright %}
{% if current_user.can('admin') %}
<a title="Add to the Whitelist" href="#show-modal" data-modal="new-user">
    <i class="fa fa-plus fa-2x"></i>
</a>
{% endif %}
{% endblock %}

{% block main %}
{% call macros.modal(modal="new-user") %}
<h2>Choose Your User Type:</h2>
<form class="whitelist-add-form" method="POST" action="{{ url_for('whitelist.add') }}">
    {{ whitelist_form.csrf_token }}
    <div class="for-whitelist hidden">
    {{ macros.render_field(whitelist_form.email, placeholder="Email Address", autofocus="", label=False)}}
    </div>
    <div class="for-fake-user hidden">
        {{ macros.render_field(whitelist_form.name, placeholder="Name", autofocus="", label=False)}}
        {{ macros.render_field(whitelist_form.fake_user_image, hidden="hidden")}}
        <div class="set-image fake-user-image">
            <a href="#show-modal" data-modal="image">
                <i class="fa fa-plus fa-3x"></i>
            </a>
        </div>
        <div class="display-image fake-user-image image hidden">
            <a href="#remove-image">
                <i></i>
            </a>
        </div>
    </div>
    <div class="display-feature-table">
        <table>
            <tr>
                <th>&nbsp;</th>
                {% for subfield in whitelist_form.user_type %}
                    <td><small>{{subfield.label}}</small>
                    {{ subfield }}</td>
                {% endfor %}
            </tr>
            {% set features = [
                ('Author blog posts',          [True, True, True, True]),
                ('Create and edit blog posts', [False, True, True, True]),
                ('Create and edit events',     [False, True, True, True]),
                ('Publish blog posts and events', [False, False, True, True]),
                ('View and manage users',      [False, False, False, True]),
                ('Add users to the whitelist', [False, False, False, True]),
            ] %}
            {% for description, bools in features %}
            <tr>
                <th>{{description}}</th>
                {% for bool in bools %}
                <td>
                    {% if bool %}
                        <i class="fa fa-check"></i>
                    {% else %}
                        <i class="fa fa-times"></i>
                    {% endif %}
                </td>
                {% endfor %}
            </tr>
            {% endfor %}
        </table>
    </div>
    <input class="big" type="submit" value="Add">
</form>
{% endcall %}
{% call macros.modal(modal="image") %}
<h3>Add an Image</h3>
{{ macros.upload_form(upload_form, uploaded_from=url_for('posts.new')) }}
<ul class="image-grid clearfix">
{% for image in images %}
<li class="image" data-filename="{{ image.filename }}">
    <a data-filename="{{ image.filename }}" data-url="{{ image.url() }}" href="#set-image">
        <i style="background-image:url({{ image.url() }});"></i>
        <div class="select"><i class="fa fa-plus fa-3x"></i></div>
    </a>
</li>
{% endfor %}
</ul>
{% endcall %}

{{ super() }}
{% endblock %}

{% block content %}
{% if current_user.can("admin") %}
<h2>Whitelist</h2>
<small>Only emails on this whitelist can be used to make an account.</small>
{% if whitelist %}
<table class="whitelist table">
    <thead>
        <th class="user-type with-image">User Type</th>
        <th class="email" >Email</th>
        <th class="actions"></th>
    </thead>
    <tbody>
        {% for user in whitelist %}
        {% if not user.redeemed %}
        <tr class="whitelist-item" data-email="{{ user.email }}">
            <td class="role with-image">
                <p>{{ user.user_type }}</p>
            </td>
            <td class="email">
                <p>{{ user.email }}</p>
            </td>
            <td class="actions right">
                {{ macros.confirm("Revoke", url_for('whitelist.delete', email=user.email)) }}
            </td>
        </tr>
        {% endif %}
        {% endfor%}
    </tbody>
</table>
{% else %}
<p class="no-elements">Click the plus button to add a user to the whitelist!</p>
{% endif %}
<h2>Users</h2>
<small>Currently registered users</small>
{% endif %}
<table class="users click table">
    <thead>
        <th class="with-image">Name</th>
        <th>Email</th>
        <th>User Type</th>
    </thead>
    <tbody>
        {% for user in users %}
        <tr class="user" data-email="{{ user.email }}">
            <td class="name with-image">
                <a class="tr-link" href="{{ url_for('users.user', slug=user.slug) }}"></a>
                <div class="image-wrapper">
                    <i style="background-image:url({{ user.get_profile_picture() }});"></i>
                </div>
                <p>{{user.name}}</p>
            </td>
            <td class="email">
                <p class="whitelist-email">{{ user.email }}</p>
            </td>
            <td class="user-type">{{user.user_type}}</td>
        </tr>
        {% endfor %}
    </tbody>
</table>
{% endblock %}
