mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-02 07:47:32 +00:00
366 lines
13 KiB
HTML
366 lines
13 KiB
HTML
{% extends base_template %}
|
||
{% load seahub_tags avatar_tags%}
|
||
{% load url from future %}
|
||
|
||
{% block main_panel %}
|
||
{% if messages %}
|
||
{% autoescape off %}
|
||
<ul class="messages hide">
|
||
{% for message in messages %}
|
||
<li class="info">{{ message }}</li>
|
||
{% endfor %}
|
||
</ul>
|
||
{% endautoescape %}
|
||
{% endif %}
|
||
|
||
<h2>
|
||
{% if not view_history %}
|
||
{{ u_filename }}
|
||
{% else %}
|
||
{{repo.props.name}} 历史浏览<span class="latest-commit-time-author">({{ current_commit.props.ctime|tsstr_sec }})</span>
|
||
{% endif %}
|
||
</h2>
|
||
<div class="w100 ovhd">
|
||
<p class="path fleft">
|
||
当前路径:
|
||
{% for name, link in zipped %}
|
||
{% if not forloop.last %}
|
||
{% if view_history %}
|
||
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/?commit_id={{ current_commit.id }}&p={{ link|urlencode }}">{{ name }}</a> / {% else %}
|
||
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/?p={{ link|urlencode }}">{{ name }}</a> /
|
||
{% endif %}
|
||
{% else %}
|
||
{{ name }}
|
||
{% endif %}
|
||
{% endfor %}
|
||
</p>
|
||
|
||
<div class="file-op fright">
|
||
{% if not view_history %}
|
||
<input id="shared-link" class="hide" type="text" readonly="readonly" value="{{ file_shared_link }}" />
|
||
<button data="{{ SITE_ROOT }}sharedlink/get/?repo_id={{ repo.id }}&p={{ path|urlencode }}&file_name={{ file_name }}" id="get-shared-link">获取分享地址</button>
|
||
<button id="send-shared-link" class="hide">发送</button>
|
||
<button data="{{ SITE_ROOT }}sharedlink/remove/?t={{ fileshare.token }}" id="rm-shared-link" class="hide">删除</button>
|
||
{% endif %}
|
||
</div>
|
||
</div>
|
||
|
||
<div id="file">
|
||
<div id="file-op">
|
||
<button id="open-local" data="{{path}}{{dirent.obj_name}}">打开本地文件</button>
|
||
{% if filetype == 'Text' or filetype == 'Image' or filetype == 'SVG' or filetype == 'Markdown' %}
|
||
<button data="{{ SITE_ROOT }}repo/{{ repo.id }}/{{ obj_id }}/?file_name={{ file_name }}&op=view" id="view-original">原始文件</button>
|
||
{% endif %}
|
||
<button data="{{ SITE_ROOT }}repo/{{ repo.id }}/{{ obj_id }}/?file_name={{ file_name }}&op=download" id="download">下载</button>
|
||
{% if not view_history and request.user.is_authenticated %}
|
||
<button data="{{ SITE_ROOT }}repo/file_revisions/{{ repo.id }}/?p={{ path }}" id="history">历史</button>
|
||
{% if filetype == 'Text' or filetype == 'Markdown' %}
|
||
<button data="{{ SITE_ROOT }}repo/{{ repo.id }}/file/edit/?p={{ path }}" id="edit">编辑</button>
|
||
{% endif %}
|
||
{% endif %}
|
||
</div>
|
||
<div id="file-view">
|
||
<p>文件内容读取中...</p>
|
||
</div>
|
||
</div>
|
||
|
||
{% if not view_history %}
|
||
<form id="link-send-form" action="" method="post" name="link-send-form" class="hide">
|
||
<label>邮箱(多个邮箱以,分隔):</label><br />
|
||
<textarea id="email" name="email"></textarea><br />
|
||
<input type="hidden" name="file_shared_link" value="{{ file_shared_link }}" />
|
||
<p id="error" class="hide">输入不能为空。</p>
|
||
<input type="submit" value="提交" class="submit" />
|
||
<p id="sending" class="hide">发送中...</p>
|
||
<p id="success" class="hide"></p>
|
||
</form>
|
||
|
||
{% with attach_type='file' %}
|
||
{% include "snippets/group_recommend_form.html" %}
|
||
{% endwith %}
|
||
{% endif %}
|
||
|
||
<div id="open-local-file-error-dlg" class="hide">
|
||
<p id="open-local-file-error" class=""></p>
|
||
</div>
|
||
|
||
<div id="redirect-download" class="hide">
|
||
<p class="error">您还没有将同步目录 {{repo.name}} 同步到本地</p>
|
||
<button data="{{ SITE_ROOT }}download/repo/?repo_id={{ repo.id }}" id="download-repo">点此同步</button>
|
||
</div>
|
||
|
||
{% if request.user.is_authenticated %}
|
||
<div id="file-comment">
|
||
<h3>评论</h3>
|
||
<form id="file-comment-form" action="" method="post">
|
||
<input name="repo_id" type="hidden" value="{{ repo.id }}"/>
|
||
<input name="file_path" type="hidden" value="{{ path|urlencode }}" />
|
||
<textarea name="message" id="message">{{ form.data.message }}</textarea><br />
|
||
{% for error in form.message.errors %}
|
||
<p class="error">{{ error|escape }}</p>
|
||
{% endfor %}
|
||
<input type="submit" value="提交" class="submit" />
|
||
</form>
|
||
</div>
|
||
{% endif %}
|
||
|
||
{% if comments %}
|
||
<!-- file comments list -->
|
||
<ul class="msg-list">
|
||
{% for comment in comments %}
|
||
<li class="msg w100 ovhd">
|
||
<div class="pic fleft">
|
||
<a href="{% url 'user_profile' comment.from_email %}">{% avatar comment.from_email 48 %}</a>
|
||
</div>
|
||
<div id="filecomment-{{comment.id}}" class="txt fright">
|
||
<div class="msg-hd">
|
||
<span class="time">{{ comment.timestamp|translate_commit_time }}</span>
|
||
<a href="{% url 'user_profile' comment.from_email %}" title="{{ comment.from_email }}">{{ comment.from_email|email2nickname }}</a>
|
||
</div>
|
||
<div class="msg-bd">
|
||
<p>
|
||
{{ comment.message|seahub_urlize|find_at|linebreaksbr }}
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</li>
|
||
{% endfor %}
|
||
</ul>
|
||
{% endif %}
|
||
<div id="paginator">
|
||
{% if current_page != 1 %}
|
||
<a href="{% url 'repo_view_file' repo.id %}?p={{ path|urlencode }}&page={{ prev_page }}&per_page={{ per_page }}">上一页</a>
|
||
{% endif %}
|
||
{% if page_next %}
|
||
<a href="{% url 'repo_view_file' repo.id %}?p={{ path|urlencode }}&page={{ next_page }}&per_page={{ per_page }}">下一页</a>
|
||
{% endif %}
|
||
</div>
|
||
|
||
{% endblock %}
|
||
|
||
{% block extra_script %}
|
||
{% include "snippets/file_view_js.html" %}
|
||
<script type="text/javascript">
|
||
{% include "snippets/repo_file_get.html" %}
|
||
$('#view-original, #download').click(function() {
|
||
window.open($(this).attr('data'));
|
||
});
|
||
{% if not view_history %}
|
||
$('#edit, #history').click(function() {
|
||
location.href = $(this).attr('data');
|
||
});
|
||
function showLink() {
|
||
$('#get-shared-link').addClass('hide');
|
||
$('#shared-link, #send-shared-link, #rm-shared-link').removeClass('hide');
|
||
}
|
||
function hideLink() {
|
||
$('#shared-link, #send-shared-link, #rm-shared-link').addClass('hide');
|
||
$('#get-shared-link').removeClass('hide');
|
||
}
|
||
function setLinkWidth() {
|
||
var link = $('#shared-link');
|
||
link.before('<p class="hide">' + link.val() + '</p>');
|
||
link.css('width', link.prev().width() + 2);
|
||
link.prev().remove();
|
||
}
|
||
if ($.trim($('#shared-link').val())) {
|
||
setLinkWidth();
|
||
}
|
||
|
||
{% if fileshare.token %}
|
||
showLink();
|
||
{% else %}
|
||
hideLink();
|
||
{% endif %}
|
||
|
||
$('#get-shared-link').click(function() {
|
||
var url = $(this).attr('data');
|
||
$.ajax({
|
||
url: url,
|
||
dataType: 'json',
|
||
cache: false,
|
||
contentType: 'application/json; charset=utf-8',
|
||
success: function(data) {
|
||
if (data.length > 0) {
|
||
var t = data[0]['token'],
|
||
shared_link = '{{ protocol }}://{{ domain }}{{ SITE_ROOT }}f/' + t + '/';
|
||
$('#shared-link').val(shared_link);
|
||
setLinkWidth();
|
||
$('#rm-shared-link').attr('data', '{{ SITE_ROOT }}sharedlink/remove/?t='+t);
|
||
$('input[name="file_shared_link"]').val(shared_link);
|
||
showLink();
|
||
}
|
||
},
|
||
error: function(xhr, ajaxOptions, thrownError) {
|
||
var jsonVal = jQuery.parseJSON(xhr.responseText);
|
||
$('#get-shared-link').replaceWith('<span class="error">' + jsonVal[0]['error'] + '</span>');
|
||
}
|
||
});
|
||
});
|
||
|
||
$('#rm-shared-link').click(function() {
|
||
var url = $(this).attr('data');
|
||
$.ajax({
|
||
url: url,
|
||
dataType: 'json',
|
||
cache: false,
|
||
contentType: 'application/json; charset=utf-8',
|
||
success: function(data) {
|
||
hideLink();
|
||
$('#shared-link').val('');
|
||
}
|
||
});
|
||
});
|
||
|
||
$('#send-shared-link').click(function() {
|
||
$("#link-send-form").modal({appendTo: "#main"});
|
||
|
||
// link-send-form email autocomplete
|
||
var share_list = [];
|
||
{% for contact in contacts %}
|
||
share_list.push('{{ contact.contact_email }}');
|
||
{% endfor %}
|
||
addAutocomplete('#email', '#link-send-form', share_list);
|
||
});
|
||
|
||
$("#link-send-form").submit(function(event) {
|
||
$('#error, #sending, #success').attr('class', 'hide');
|
||
var form = $(this),
|
||
file_shared_link = form.children('input[name="file_shared_link"]').val(),
|
||
email = $.trim(form.children('textarea[name="email"]').val());
|
||
|
||
if (!email) {
|
||
$('#error').attr('class', 'error');
|
||
$('#simplemodal-container').css('height', $('#link-send-form').height());
|
||
return false;
|
||
}
|
||
|
||
$('#sending').removeClass('hide');
|
||
$('#simplemodal-container').css('height', $('#link-send-form').height());
|
||
|
||
if (email.length <= 512) {
|
||
$.ajax({
|
||
type: "POST",
|
||
url: "{{ SITE_ROOT }}sharedlink/send/",
|
||
dataType: 'json',
|
||
cache: false,
|
||
contentType: 'application/json; charset=utf-8',
|
||
beforeSend: prepareCSRFToken,
|
||
data: {file_shared_link: file_shared_link, email: email},
|
||
success: function(data) {
|
||
$('#sending').attr('class', 'hide');
|
||
$('#success').html(data[0]['msg']).removeClass('hide');
|
||
$('#simplemodal-container').css('height', $('#link-send-form').height());
|
||
},
|
||
error: function(xhr, ajaxOptions, thrownError) {
|
||
var jsonVal = jQuery.parseJSON(xhr.responseText);
|
||
$('#sending').attr('class', 'hide');
|
||
$('#error').html(jsonVal[0]['error']).attr('class','error');
|
||
$('#simplemodal-container').css('height', $('#link-send-form').height());
|
||
}
|
||
});
|
||
}
|
||
return false;
|
||
});
|
||
|
||
$('#shared-link').click(function() {
|
||
$(this).select();
|
||
});
|
||
|
||
{% include "snippets/bottom_bar.html" %}
|
||
{% endif %}
|
||
|
||
function send_open_local_file_request(path) {
|
||
var callback = 'xx';
|
||
url = '{{ applet_root }}/open-local-file/?repo_id={{ repo.id }}&commit_id={{current_commit.id}}';
|
||
url += '&path=' + encodeURIComponent(path);
|
||
url += '&callback=' + callback;
|
||
$.ajax({
|
||
url: url,
|
||
dataType: 'jsonp',
|
||
jsonpCallback: callback,
|
||
crossDomain: true,
|
||
success: function(data) {
|
||
if (data['exists'] === false) {
|
||
// repo doesn't exist on local machine
|
||
$('#redirect-download').modal({appendTo:'#main'});
|
||
|
||
} else if (data['no_assoc'] === true) {
|
||
// no application to open the file
|
||
$('#open-local-file-error').removeClass();
|
||
$('#open-local-file-error').addClass('notification');
|
||
$('#open-local-file-error').html('找不到打开该类型文件的程序。\nSeafile 将为你打开该文件所在目录');
|
||
$('#open-local-file-error-dlg').modal({appendTo:'#main'});
|
||
|
||
} else if (data['outdated'] === true) {
|
||
// local repo not in sync yet
|
||
$('#open-local-file-error').removeClass();
|
||
$('#open-local-file-error').addClass('notification');
|
||
|
||
if (data['auto-sync'] === false) {
|
||
hint = '本地文件尚未与服务器同步。\n请打开本地目录的自动同步,或者手动进行同步';
|
||
} else {
|
||
hint = '本地文件尚未与服务器同步,请稍后再试';
|
||
}
|
||
|
||
$('#open-local-file-error').html(hint);
|
||
$('#open-local-file-error-dlg').modal({appendTo:'#main'});
|
||
|
||
} else if (data['error']) {
|
||
// other error
|
||
$('#open-local-file-error').removeClass();
|
||
$('#open-local-file-error').addClass('error');
|
||
$('#open-local-file-error').html('打开本地文件时出错');
|
||
$('#open-local-file-error-dlg').modal({appendTo:'#main'});
|
||
|
||
} else {
|
||
// open file successfully, nothing to do
|
||
}
|
||
}
|
||
});
|
||
}
|
||
$('#download-repo').click(function() {
|
||
location.href = $(this).attr('data');
|
||
});
|
||
|
||
// When user clicks 'open local file':
|
||
//
|
||
// - First, check client version to determine is this operation supported by client
|
||
// - second check whether repo exists on local machine, then:
|
||
// - if exists, send an open local file requst
|
||
// - if not exits, redirect to repo download page
|
||
|
||
|
||
$('#open-local').click(function () {
|
||
var path = $(this).attr('data');
|
||
var local_applet_running = false;
|
||
|
||
$.ajax({
|
||
url: '{{ applet_root }}/seafile_rpc_version/',
|
||
dataType: 'jsonp',
|
||
jsonpCallback: 'xx',
|
||
crossDomain: true,
|
||
success: function(version) {
|
||
local_applet_running = true;
|
||
if (version < 1) {
|
||
update_url = '<a href="http://www.seafile.com/download/">升级</a>';
|
||
$('#open-local-file-error').html('您的 Seafile 客户端版本太低,请' + update_url + '到最新版本');
|
||
$('#open-local-file-error-dlg').modal({appendTo:'#main'});
|
||
} else {
|
||
send_open_local_file_request(path);
|
||
}
|
||
}
|
||
});
|
||
|
||
// if jsonp response doesn't arrive in 2 seconds, we can say local client
|
||
// is not running yet.
|
||
setTimeout(function() {
|
||
if (!local_applet_running) {
|
||
$('#open-local-file-error').html('Seafile 客户端程序未启动或者版本过低');
|
||
$('#open-local-file-error-dlg').modal({appendTo:'#main'});
|
||
}
|
||
}, 2000);
|
||
});
|
||
</script>
|
||
{% endblock %}
|