{% extends "myhome_base.html" %}

{% load i18n avatar_tags seahub_tags %}

{% block sub_title %}{{repo.name}} - {% endblock %}

{% block left_panel %}
<div class="side-textnav">
    <h3 class="hd"><span class="op-target">{{ repo.name }}</span> {% trans "Settings" %}</h3>
    <ul class="side-textnav-tabs">
        <li class="tab"><a href="{% url 'repo_basic_info' repo.id %}">{% trans "Basic Info" %}</a></li>
        <li class="tab"><a href="{% url 'repo_transfer_owner' repo.id %}">{% trans "Transfer Ownership" %}</a></li>
        {% if repo.encrypted and repo.enc_version == 2 %}
        <li class="tab"><a href="{% url 'repo_change_password' repo.id %}">{% trans "Change Password" %}</a></li>
        {% endif %}
        {% if not repo.encrypted %}
        <li class="tab tab-cur"><a href="{% url 'repo_shared_link' repo.id %}">{% trans "Shared Links" %}</a></li>
        {% endif %}
        <li class="tab"><a href="{% url 'repo_share_manage' repo.id %}">{% trans "Sharing Permission" %}</a></li>
        {% if ENABLE_FOLDER_PERM %}
        <li class="tab"><a href="{% url 'repo_folder_perm' repo.id %}">{% trans "Folder Permission" %}</a></li>
        {% endif %}
    </ul>
</div>
{% endblock %}

{% block right_panel %}
<div class="lib-setting">
        <div id="tabs" class="tab-tabs">
            <ul class="tab-tabs-nav hd ovhd">
                <li class="tab"><a href="#upload-links" class="a">{% trans "Upload Links" %}</a></li>
                <li class="tab"><a href="#download-links" class="a">{% trans "Download Links" %}</a></li>
            </ul>
            <div id="upload-links">
                <table>
                    <tr>
                        <th width="5%"><!--icon--></th>
                        <th width="40%">{% trans "Name"%}</th>
                        <th width="15%">{% trans "Created By"%}</th>
                        <th width="15%">{% trans "Size"%}</th>
                        <th width="12%">{% trans "Visits"%}</th>
                        <th width="13%">{% trans "Operations"%}</th>
                    </tr>
                    {% if uploadlinks %}
                    {% for link in uploadlinks %}
                    <tr>
                        <td class="alc"><img src="{{ MEDIA_URL }}img/folder-icon-24.png" alt="{% trans "Directory icon"%}" /></td>
                        <td><a href="{% url 'view_common_lib_dir' repo.id link.path|urlencode|strip_slash %}">{{ link.dir_name }}</a></td>
                        <td><a href="{% url 'user_profile' link.username %}">{{ link.username|email2nickname }}</a></td>
                        <td>--</td>
                        <td>{{ link.view_cnt }}</td>
                        <td>
                            <span class="icon-trash op-icon vh rm-link" data-token={{ link.token }} data-type="upload" title="{% trans "Remove"%}"></span>
                        </td>
                    </tr>
                    {% endfor %}
                    {% endif %}
                </table>
            </div>
            <div id="download-links" class="hide">
                <table>
                    <tr>
                        <th width="5%"><!--icon--></th>
                        <th width="40%">{% trans "Name"%}</th>
                        <th width="15%">{% trans "Created By"%}</th>
                        <th width="15%">{% trans "Size"%}</th>
                        <th width="12%">{% trans "Visits"%}</th>
                        <th width="13%">{% trans "Operations"%}</th>
                    </tr>
                    {% if fileshares %}
                    {% for link in fileshares %}
                    <tr>
                        {% if link.s_type == 'd'%}
                        <td class="alc"><img src="{{ MEDIA_URL }}img/folder-icon-24.png" alt="{% trans "Directory icon"%}" /></td>
                        <td><a href="{% url 'view_common_lib_dir' repo.id link.path|urlencode|strip_slash %}">{{ link.filename }}</a></td>
                        <td><a href="{% url 'user_profile' link.username %}">{{ link.username|email2nickname }}</a></td>
                        {% else %}
                        <td class="alc"><img src="{{ MEDIA_URL }}img/file/{{ link.filename|file_icon_filter }}" alt="{% trans "File"%}" /></td>
                        <td><a href="{% url 'view_lib_file' repo.id link.path|urlencode %}">{{ link.filename }}</a></td>
                        <td><a href="{% url 'user_profile' link.username %}">{{ link.username|email2nickname }}</a></td>
                        {% endif %}
                        <td>{{ link.filesize|filesizeformat}}</td>
                        <td>{{ link.view_cnt }}</td>
                        <td>
                            <span class="icon-trash op-icon vh rm-link" data-token={{ link.token }} data-type="download" title="{% trans "Remove"%}"></span>
                        </td>
                    </tr>
                    {% endfor %}
                    {% endif %}
                </table>
            </div>
        </div>
</div>
{% endblock %}

{% block extra_script %}
<script type="text/javascript">
$('.rm-link').click(function() {
    var op = $(this),
        link_token = op.attr('data-token'),
        link_type = op.data('type'),
        ajax_url;
    if (link_type == 'upload') {
        ajax_url = '{% url 'ajax_remove_shared_upload_link' %}';
    } else {
        ajax_url = '{% url 'ajax_remove_shared_link' %}';
    }
    $.ajax({
        url: ajax_url,
        type: 'POST',
        data: {'t': link_token},
        cache: false,
        dataType: 'json',
        beforeSend: prepareCSRFToken,
        success: function(data) {
            op.parents('tr').remove();
            feedback("{% trans "Removed successfully." %}", 'success');
        },
        error: ajaxErrorHandler
    });
    return false;
});
</script>
{% endblock %}
