{% extends "memberships/base-wide.html" %}
{% load membership_tags %}
{% load base_tags %}
{% load base_filters %}
{% load i18n %}

{% block title %}Import Memberships from CSV file{% endblock %}

{% block extra_head %}
{{ block.super }}
    <link rel="stylesheet" href="{{ STATIC_URL }}css/memberships.css">
    <link rel="stylesheet" href="{{ STATIC_URL }}css/memberships-import-preview.css">
{% endblock %}

{% block body %}

<div id="import-wrap" class="preview">
    
    <h1>{% trans "Membership Import Preview" %}</h1>
    
    <p class="timestamp">{% trans "Step 3/4" %} &middot; {{ datetime.now }}</p>
    
    <p class="msg">
        <em>{{ stats.all }}</em> membership{{ stats.all|pluralize }};
        <em>{{ stats.added }}</em> will be added,
        <em>{{ stats.updated }}</em> will be 
        {% if memport.override %}overridden,{% else %}updated,{% endif %}
        and <em>{{ stats.skipped }}</em> will be skipped.</p>
        <em><a title="Looks good!" href="{% url membership_import_confirm memport.id %}" id="import-confirm">Import Now &rarr;</a></em>
    </p>
    
    <div style="margin-top:10px;">
        <table>
            <tr class="header">
                <td></td>
                <td>{% trans "Name" %}</td>
                <td>{% trans "Number" %}</td>
                <td>{% trans "Email" %}</td>
                <td>{% trans "Type" %}</td>
                <td>{% trans "Join Date" %}</td>
                <td>{% trans "Expire Date" %}</td>
                <td>{% trans "Action" %}</td>
            </tr>

            {% for membership in memberships %}
                <tr class="{% cycle 'odd' 'even' as rowcolors %}">
                    <td>{{ forloop.counter }}</td>
                    <td><div>
                            {% if membership.fullname %}
                                {% if membership.username %}
                                <a href="{% url profile membership.username %}">
                                    {{ membership.fullname }}</a>
                                {% else %}
                                    {{ membership.fullname }}
                                {% endif %}
                            {% else %}
                                {% trans "No Name" %}
                            {% endif %}
                    </div></td>
                    <td><div>{{ membership.membernumber }}</div></td>
                    <td><div>{{ membership.email }}</div></td>
                    <td><div>{{ membership.membershiptype }}</div></td>
                    <td><div>{{ membership.subscribedt|date:"M d, Y" }}</div></td>
                    <td><div>{{ membership.expiredt|date:"M d, Y" }}</div></td>
                    <td><div>
                        {{ membership.status__action }}
                        {% if membership.status__reason %}: {{ membership.status__reason }}{% endif %}
                    </div></td>
                </tr>
            {% endfor %}
        </table>
    </div>
    
    <div style="display: none;">
        <form id="mapping-form" action="{% url membership_import_confirm memport.id %}" method="post">{% csrf_token %}
            {{ form.as_p }}
            <input type='submit' value='Submit'>
        </form>
    </div>
</div>
{% endblock %}

{% block extra_body %}
<script type="text/javascript">
    $(document).ready(function(){
        // import submit
        // this is used to resubmit the mapping form on confirmation
        $('#import-confirm').click(function(){
            $('#mapping-form').submit();
            return false;   // cancel
        });
    });
</script>
{% endblock %}