{% extends "myhome_base.html" %}
{% load i18n %}

{% block main_panel %}
<div class="text-panel">
    <p id="msg-wait">{% trans 'Preparing, please wait...' %}</p>
    <div id="msg-client"  class="hide">
        <p style="margin-bottom:.9em;"><span class="error">{% trans "No running Seafile client version 1.x is detected." %}</span><br />{% trans "If you're sure Seafile client is running, click the following link to continue downloading:" %}<br/><a href="{{ download_url }}">{{ download_url|slice:"40" }}...</a></p>
        <p>{% trans "If you're using Seafile client version 2.0+, download the library from the client directly." %}</p>
        <img src="{{MEDIA_URL}}img/client-v2-download-lib.png" alt="" />
    </div>
    <p id="msg-version" class="error hide">{% trans "Your Seafile client is out of date, please upgrade to latest version." %}<a href="http://www.seafile.com/download">{% trans "Click to download." %}</a></p>
</div>
{% endblock %}

{% block extra_script %}
<script type="text/javascript">
$(function() {
    var req_success = false;
    var version_mismatch = false;
    $.ajax({
        url: '{{ applet_root }}/seafile_access_check/',
        dataType: 'jsonp',
        jsonpCallback: 'xx',
        crossDomain: true,
        success: function(version) {
            if (version < 2) {
                version_mismatch = true;
            } else {
                req_success = true;
                location.href = '{{ download_url }}';
            }
        }
    });

    setTimeout(function() {
        $('#msg-wait').addClass('hide');
        if (version_mismatch) {
            $('#msg-version').removeClass('hide');
        } else if (!req_success) {
            $('#msg-client').removeClass('hide');
        }
    }, 3000);
});
</script>
{% endblock %}
