{% extends "base.html" %}
{% load i18n avatar_tags %}

{% block main_panel %}
<div class="avatar-op">
    <h2>修改头像</h2>
    <div class="avatar-op-con">
    <h3>{% trans "Your current avatar: " %}</h3>
    {% avatar user %}
    
    {% comment %}
    {% if not avatars %}
        <p>{% trans "You haven't uploaded an avatar yet. Please upload one now." %}</p>
    {% else %}
        <form method="POST" action="{% url avatar_change %}">
            <label>从已有头像中选择：</label>
            {% for boundfield in primary_avatar_form %}
            {{ boundfield }}
            {% endfor %}
            <p>{% csrf_token %}<input type="submit" value="{% trans "Choose new Default" %}" /></p>
        </form>
    {% endif %}
    {% endcomment %}
    
    <h3 class="upload-new-avatar-hd">上传新头像：</h3>
    <form enctype="multipart/form-data" method="POST" action="{% url avatar_add %}">{% csrf_token %}
        {{ upload_avatar_form.avatar }}<br />
        <p class="error hide">您还没有上传新头像。</p>
        <input type="submit" value="{% trans "Upload New Image" %}" />
    </form>
    </div>
</div>
{% endblock %}

{% block extra_script %}
<script type="text/javascript">
$('input[type="submit"]').on('click', function() {
    if (!$.trim($('#id_avatar').val())) {
        $('.error').removeClass('hide');
        return false;
    }
});
</script>
{% endblock %}
