
{% extends "base.html" %}

{% block title %}Migration from {{ migration.from_email }}{% endblock %}
{% block h1 %}Migration from {{ migration.from_email }}{% endblock %}

{% block left_content %}
<div class="box box-50">
    <div class="boxin">
        <div class="header">
            <h3>Migration details</h3>
        </div>
        <div class="content">
            <table class="calendar" cellspacing="0">
                <thead>
                    <tr>
                        <th class="month first last" colspan="2">
                            Migrating all mail:
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="first">
                        <th>Since:</th>
                        <td>{{ migration.since }}</td>
                    </tr>
                    <tr>
                        <th>From:</th>
                        <td>{{ migration.from_email }}</td>
                    </tr>
                    <tr class="last">
                        <th>To:</th>
                        <td>{{ migration.to_username }}@{{ migration.domain }}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}

{% block right_content %}
<div class="box box-50">
    <div class="boxin">
        <div class="header">
            <h3>Migration process</h3>
        </div>
        <div class="boxcontent">
            <div id="result">
                <span class="loading" style="display: none"></span>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
function get_data() {
    $('.loading').fadeIn();
    $.ajax({
        url: "{% url migrate_mail.migrate_process migration=migration.id %}",
        success: function(data) {
            if (data == 'FINISHED') {
                document.location.href = "{% url migrate_mail.migrate_results migration=migration.id %}";
            } else {
                $('#result').html(data);
                setTimeout(get_data, 10000);
            }
        },
        error: function() {
            $('#loading').html("Error. Will try again in 30 seconds.");
            setTimeout(get_data, 30000);
        }
    });
}
$(function() {
    get_data();
});
</script>
{% endblock %}