{% load seahub_tags i18n %}
<div id="repos-shared-to-me">
    {% if shared_repos %}
    <table>
        <tr>
            <th width="4%"><!--icon--></th>
            <th width="20%">{% trans "Name" %}</th>
            <th width="33%">{% trans "Description" %}</th>
            <th width="15%">{% trans "Last Update" %}</th>
            <th width="15%">{% trans "Shared By" %}</th>
            <th width="13%">{% trans "Operations" %}</th>
        </tr>

        {% for repo in shared_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.repo_id %}">{{ repo.repo_name }}</a></td>
            <td>{{ repo.repo_desc }}</td>
            {% if repo.last_modified %}
            <td>{{ repo.last_modified|translate_seahub_time }}</td>
            {% else %}
            <td>--</td>
            {% endif %}
            <td>{{ repo.user|email2nickname }}</td>
            <td>
                {% if show_repo_download_button %}
                <span data="{{ repo.repo_id }}" class="icon-cloud-download download-btn op-icon vh" title="{% trans "Download and Sync" %}"></span>
                {% endif %}
                {% if repo.share_type == 'personal' %}
                <span data-url="{% url 'repo_remove_share' %}?repo_id={{ repo.repo_id }}&from={{ repo.user|urlencode }}&to={{ request.user.username|urlencode }}" data-target="{{repo.repo_name}}" class="icon-trash unshare-btn op-icon vh" title="{% trans "Leave Share" %}"></span>
                {% endif %}
            </td>
        </tr>
        {% endfor %}

    </table>
    {% else %}
    <div class="empty-tips">
        <h2 class="alc">{% trans "No library is shared to you" %}</h2>
    </div>
    {% endif %}
</div>

<script type="text/javascript">
$("tr:gt(0)", $('table')).hover(
    function() {
		$(this).addClass('hl');
        $(this).find('.op-icon, .op').removeClass('vh');
    },  
    function() {
        $(this).find('.op-icon, .op').addClass('vh');
		$(this).removeClass('hl');
    }   
);

$(".download-btn").click(function() {
    var repo_id = $(this).parents('td').data('id');
    window.open('{{ SITE_ROOT }}seafile_access_check/?repo_id=' + e(repo_id));
    });
$('.unshare-btn').click(function() {
    location.href = $(this).data('url');
});

</script>

