{% extends "pub_base.html" %}
{% load seahub_tags avatar_tags group_avatar_tags i18n %}
{% load url from future %}

{% block cur_lib %}tab-cur{% endblock %}

{% block right_panel %}
<div class="hd ovhd">
    <h3 class="fleft">{% trans "Libraries" %}</h3>
    <button id="repo-create" class="fright"><span class="add icon-plus-sign-alt"></span>{% trans "New Library"%}</button>
</div>
{% if public_repos %}
<table>
    <tr>
        <th width="4%"></th>
        <th width="20%">{% trans "Name"%}</th>
        <th width="33%">{% trans "Description"%}</th>
        <th width="15%">{% trans "Last Update"%}</th>
        <th width="15%">{% trans "Share From"%}</th>
        <th width="13%">{% trans "Operations"%}</th>
    </tr>
    {% for repo in public_repos %}
    <tr>
        <td>
          {% if repo.encrypted %}
            <img src="{{MEDIA_URL}}img/sync-folder-encrypt-20.png" title="{% trans "Read-Write"%}" alt="{% trans "Directory icon"%}" />
          {% else %}
            {% if repo.user_perm == 'rw' %}
            <img src="{{MEDIA_URL}}img/sync-folder-20.png?t=1387267140" title="{% trans "Read-Write"%}" alt="{% trans "Directory icon"%}" />
            {% else %}
            <img src="{{MEDIA_URL}}img/folder-no-write-20.png?t=1387267140" title="{% trans "Read-Only"%}" alt="{% trans "Directory icon"%}" />
            {% endif %}
          {% endif %}
        </td>
        <td><a href="{% url 'repo' repo.props.repo_id %}">{{ repo.props.repo_name }}</a></td>
        <td>{{ repo.props.repo_desc }}</td>
        <td>{% if repo.props.last_modified %}{{ repo.props.last_modified|translate_seahub_time }}{% else %}--{% endif %}</td>
        <td>{{ repo.props.user|email2nickname }}</td>
        <td>
            {% if show_repo_download_button %}
            <span data-id="{{ repo.props.repo_id }}" class="icon-cloud-download download-btn op-icon vh" title="{% trans "Download and Sync"%}"></span>
            {% endif %}
            {% if request.user.is_staff or repo.share_from_me %}
            <span data-href="{% url 'unsetinnerpub' repo.repo_id %}" class="icon-trash cancel-share op-icon vh" title="{% trans "Unshare" %}"></span>
            {% endif %}
            
        </td>
    </tr>
    {% endfor %}
</table>
{% else %}
<div class="empty-tips">
    <h2 class="alc">{% trans "No public library" %}</h2>
    <p>{% blocktrans %}You can create a public library by clicking "New Library" button, others can view and download this library.{% endblocktrans %}</p>
</div>
{% endif %}
{% include "snippets/repo_create_form.html" %}
{% endblock %}

{% block extra_script %}
{% include 'snippets/repo_create_js_files.html' %}
<script type="text/javascript">
$(".download-btn").click(function() {
    window.open('{{ SITE_ROOT }}seafile_access_check/?repo_id=' + $(this).data('id'));
});
$(".cancel-share").click(function() {
    location.href = $(this).data('href');
});

function repoCreateSuccessCallback() {
    location.reload();
}
{% url 'seahub.views.public_repo_create' as repo_create_url %}
{% with post_url=repo_create_url %}
    {% include "snippets/repo_create_js.html" %}
{% endwith %}
</script>
{% endblock %}
