{% extends 'group/group_base.html' %}

{% load seahub_tags i18n %}

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

{% block right_panel %}
<div id="tabs" class="tab-tabs">
    <div class="hd ovhd">
        <ul class="tab-tabs-nav fleft">
            <li class="tab"><a href="#grp-repos" class="a">{% trans "Libraries" %}</a></li>
            <li class="tab long-tab"><a href="#grp-repos-commits" class="a">{% trans "Recent Changes" %}</a></li>
        </ul>
        <button id="repo-create" class="fright"><span class="add icon-plus-sign-alt"></span>{% trans "New Library" %}</button>
    </div>
    <div id="grp-repos" class="hide">
    {% if repos %}
    <table>
    <tr>
        <th width="4%"><!--icon--></th>
        <th width="20%">{% trans "Name" %}</th>
        <th width="33%">{% trans "Description" %}</th>
        <th width="16%">{% trans "Last Update" %}</th>
        <th width="14%">{% trans "Shared By" %}</th>
        <th width="13%">{% trans "Operations" %}</th>
    </tr>
    {% for repo in 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="{{ SITE_ROOT }}repo/{{ repo.props.id }}/">{{ repo.props.name }}</a></td>
        <td>{{ repo.props.desc }}</td>
        <td>
        {% if repo.latest_modify %}
        {{ repo.latest_modify|translate_seahub_time }}
        {% else %}
        --
        {% endif %}
        </td>
        <td>{{ repo.owner|email2nickname }}</td>
        <td data-id="{{ repo.props.id }}" data-owner="{{ repo.owner }}" data-name="{{ repo.props.name }}">
            {% if show_repo_download_button %}
            <span class="icon-cloud-download download op-icon vh" title="{% trans "Download and Sync" %}"></span>
            {% endif %}
            {% if is_staff or repo.share_from_me %}
            <span class="icon-trash cancel-share op-icon vh" title="{% trans "Unshare" %}"></span>
            {% endif %}
        </td>
    </tr>
    {% endfor %}
    </table>
    {% else %}
    <div class="empty-tips" style="margin-bottom:150px;">
        <h2 class="alc">{% trans "No library is sharing to this group" %}</h2>
        <p>{% blocktrans %}You can share libraries by clicking the "New Library" button above or the "Share" icon on your libraries list.{% endblocktrans %}</p>
        <p>{% trans "Libraries shared as writable can be downloaded and synced by other group members. Read only libraries can only be downloaded, updates by others will not be uploaded." %}</p>
    </div>
    {% endif %}
    </div>

    <div id="grp-repos-commits" class="hide">
    {% if recent_commits|length > 0 %}
    <table>
    <tr>
        <th width="5%"></th>
        <th width="17%">{% trans "Library" %}</th>
        <th width="48%">{% trans "Description" %}</th>
        <th width="15%">{% trans "Modified at" %}</th>
        <th width="15%">{% trans "Modifier" %}</th>
    </tr>

    {% for cmt in recent_commits %}
    <tr>
        <td>
            {% if cmt.tp == 'Added' or cmt.tp == 'Deleted' or cmt.tp == 'Removed' %}
                {% if cmt.tp == 'Added' %}
                <span class="icon-plus"></span>
                {% else %}
                <span class="icon-minus"></span>
                {% endif %}
            {% else %}
                <span class="icon-pencil"></span>
            {% endif %}
        </td>
        <td><a href="{{ SITE_ROOT }}repo/{{ cmt.repo.props.id }}/">{{ cmt.repo.props.name }}</a></td>
        <td>
            {{cmt.props.desc|translate_commit_desc}}
            {% if cmt.repo.encrypted %}
                <a class="lsch-encrypted"{% if cmt.repo.password_set %} data-passwordset="true"{% endif %} href="#" data-url="{% url 'repo_history_changes' cmt.repo.id %}?commit_id={{ cmt.id }}" data-repoid="{{cmt.repo.id}}" data-reponame="{{cmt.repo.name}}" data-time="{{ cmt.props.ctime|tsstr_sec }}">{% trans 'Details' %}</a>
            {% else %}
                <a class="lsch" href="#" data-url="{% url 'repo_history_changes' cmt.repo.id %}?commit_id={{ cmt.id }}" data-time="{{ cmt.props.ctime|tsstr_sec }}">{% trans 'Details' %}</a>
            {% endif %}
        </td>
        <td>{{cmt.props.ctime|translate_seahub_time}}</td>
        <td>
        {% if cmt.creator_name %}
            {% if cmt.second_parent_id %}
                {% trans "None" %}
            {% else %}
                {{cmt.creator_name|email2nickname}}
            {% endif %}
        {% else %}
            {% trans "Unknown"%}
        {% endif %}
        </td>
    </tr>
    {% endfor %}
    </table>
    {% endif %}
    </div>
</div>

{% include "snippets/repo_create_form.html" %}
<form id="repo-decrypt-form" class="hide">
    <h3>{% trans 'Library' %} <span class="op-target"></span> {% trans 'is encrypted' %}</h3>
    <input type="hidden" name="repo_id" value="" />
    <label>{% trans 'Password：' %}</label><br />
    <input type="password" name="password" class="input" />
    <p class="tip">{% trans "The password will be kept in the server for only 1 hour." %}</p>
    <p class="error"></p>
    <input type="submit" class="submit" value="{% trans 'Submit' %}" />
    <button class="simplemodal-close">{% trans 'Cancel' %}</button>
</form>

{% endblock %}

{% block extra_script %}{{block.super}}
{% include 'snippets/repo_create_js_files.html' %}
<script type="text/javascript">
$('.cancel-share').click(function() {
    var btn_ct = $(this).parent(),
        repo_id = btn_ct.data('id'),
        repo_owner = btn_ct.attr('data-owner'),
        repo_name = btn_ct.attr('data-name');
    $(this).data('url', '{% url 'repo_remove_share' %}?repo_id=' + e(repo_id) + '&from=' + e(repo_owner) + '&gid={{ group.id }}').attr('data-target', repo_name);
});
addConfirmTo($('.cancel-share'), {
        'title':'{% trans "Unshare Library" %}',
        'con':'{% trans "Are you sure you want to unshare %s ?" %}'
});

$('.download').click(function() {
    var repo_id = $(this).parent().data('id');
    window.open('{{ SITE_ROOT }}seafile_access_check/?repo_id=' + e(repo_id));
});

function repoCreateSuccessCallback() {
    location.reload();
}
{% url 'create_group_repo' group.id as repo_create_url %}
{% with post_url=repo_create_url %}
    {% include 'snippets/repo_create_js.html' %}
{% endwith %}

{% if recent_commits %}
{% include 'snippets/list_commit_detail.html' %}
$('.lsch-encrypted').click(function() {
    if ($(this).data('passwordset')) {
        listCommitDetails($(this).data('url'), $(this).data('time'));
    } else {
        var form = $('#repo-decrypt-form');
        form.find('input[name="repo_id"]').val($(this).data('repoid'));
        form.find('.op-target').html($(this).data('reponame'));
        form.data({'url':$(this).data('url'), 'time':$(this).data('time')}).modal({appendTo:'#main'});
        $('#simplemodal-container').css({'width':'auto'});
        $(window).resize();
    }   
    return false;
}); 
{% include 'snippets/repo_decrypt_js.html' %}
{% endif %}
</script>
{% endblock %}
