1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-21 08:25:21 +00:00
seahub/templates/repo_view_file.html

366 lines
13 KiB
HTML
Raw Normal View History

2012-07-30 02:25:46 +00:00
{% extends base_template %}
2012-08-26 03:48:43 +00:00
{% load seahub_tags avatar_tags%}
2012-08-13 07:58:54 +00:00
{% load url from future %}
2012-07-02 14:45:21 +00:00
2012-08-13 09:40:27 +00:00
{% block main_panel %}
2012-08-10 13:16:55 +00:00
{% if messages %}
{% autoescape off %}
2012-08-13 09:40:27 +00:00
<ul class="messages hide">
2012-08-10 13:16:55 +00:00
{% for message in messages %}
2012-08-13 09:40:27 +00:00
<li class="info">{{ message }}</li>
2012-08-10 13:16:55 +00:00
{% endfor %}
</ul>
{% endautoescape %}
2012-08-10 13:16:55 +00:00
{% endif %}
2012-07-13 09:26:33 +00:00
<h2>
{% if not view_history %}
{{ u_filename }}
{% else %}
{{repo.props.name}} 历史浏览<span class="latest-commit-time-author">({{ current_commit.props.ctime|tsstr_sec }})</span>
2012-07-03 13:48:33 +00:00
{% endif %}
2012-07-02 14:45:21 +00:00
</h2>
2012-07-13 09:26:33 +00:00
<div class="w100 ovhd">
<p class="path fleft">
当前路径:
{% for name, link in zipped %}
2012-07-02 14:45:21 +00:00
{% if not forloop.last %}
2012-07-13 09:26:33 +00:00
{% 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 %}
2012-07-02 14:45:21 +00:00
{% else %}
2012-07-13 09:26:33 +00:00
{{ name }}
2012-07-02 14:45:21 +00:00
{% endif %}
2012-07-13 09:26:33 +00:00
{% 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 }}" />
2012-07-13 09:26:33 +00:00
<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>
2012-08-10 13:35:58 +00:00
<div id="file">
2012-08-15 02:44:15 +00:00
<div id="file-op">
2012-08-12 03:22:42 +00:00
<button id="open-local" data="{{path}}{{dirent.obj_name}}">打开本地文件</button>
2012-08-15 02:44:15 +00:00
{% if filetype == 'Text' or filetype == 'Image' or filetype == 'SVG' or filetype == 'Markdown' %}
2012-08-11 03:20:26 +00:00
<button data="{{ SITE_ROOT }}repo/{{ repo.id }}/{{ obj_id }}/?file_name={{ file_name }}&op=view" id="view-original">原始文件</button>
2012-08-15 02:44:15 +00:00
{% endif %}
2012-08-10 13:35:58 +00:00
<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>
2012-08-10 13:35:58 +00:00
{% 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>
2012-07-02 14:45:21 +00:00
</div>
{% if not view_history %}
<form id="link-send-form" action="" method="post" name="link-send-form" class="hide">
2012-07-13 09:26:33 +00:00
<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>
2012-08-13 07:58:54 +00:00
{% with attach_type='file' %}
{% include "snippets/group_recommend_form.html" %}
{% endwith %}
{% endif %}
2012-08-12 03:22:42 +00:00
<div id="open-local-file-error-dlg" class="hide">
<p id="open-local-file-error" class=""></p>
2012-08-12 03:22:42 +00:00
</div>
2012-08-18 09:27:48 +00:00
<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>
2012-08-18 09:27:48 +00:00
</div>
2012-08-26 03:48:43 +00:00
{% if request.user.is_authenticated %}
<div id="file-comment">
2012-08-27 03:06:32 +00:00
<h3>评论</h3>
2012-08-26 03:48:43 +00:00
<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 %}
2012-08-27 03:06:32 +00:00
<input type="submit" value="提交" class="submit" />
2012-08-26 03:48:43 +00:00
</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>
2012-07-02 14:45:21 +00:00
{% endblock %}
{% block extra_script %}
2012-07-31 08:48:55 +00:00
{% include "snippets/file_view_js.html" %}
2012-07-02 14:45:21 +00:00
<script type="text/javascript">
{% include "snippets/repo_file_get.html" %}
2012-08-10 13:35:58 +00:00
$('#view-original, #download').click(function() {
window.open($(this).attr('data'));
});
{% if not view_history %}
$('#edit, #history').click(function() {
2012-08-10 13:35:58 +00:00
location.href = $(this).attr('data');
});
function showLink() {
2012-07-13 09:26:33 +00:00
$('#get-shared-link').addClass('hide');
$('#shared-link, #send-shared-link, #rm-shared-link').removeClass('hide');
}
function hideLink() {
2012-07-13 09:26:33 +00:00
$('#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();
}
2012-08-06 12:29:14 +00:00
{% if fileshare.token %}
showLink();
{% else %}
hideLink();
{% endif %}
2012-07-13 09:26:33 +00:00
$('#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) {
2012-07-13 09:26:33 +00:00
var t = data[0]['token'],
shared_link = '{{ protocol }}://{{ domain }}{{ SITE_ROOT }}f/' + t + '/';
$('#shared-link').val(shared_link);
setLinkWidth();
2012-07-13 09:26:33 +00:00
$('#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);
2012-07-13 09:26:33 +00:00
$('#get-shared-link').replaceWith('<span class="error">' + jsonVal[0]['error'] + '</span>');
}
});
});
2012-07-13 09:26:33 +00:00
$('#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('');
}
});
});
2012-07-13 09:26:33 +00:00
$('#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) {
2012-07-13 09:26:33 +00:00
$('#error, #sending, #success').attr('class', 'hide');
var form = $(this),
file_shared_link = form.children('input[name="file_shared_link"]').val(),
2012-07-13 09:26:33 +00:00
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',
2012-07-17 09:54:05 +00:00
beforeSend: prepareCSRFToken,
2012-07-12 08:14:21 +00:00
data: {file_shared_link: file_shared_link, email: email},
success: function(data) {
2012-07-13 09:26:33 +00:00
$('#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);
2012-07-13 09:26:33 +00:00
$('#sending').attr('class', 'hide');
$('#error').html(jsonVal[0]['error']).attr('class','error');
$('#simplemodal-container').css('height', $('#link-send-form').height());
}
});
2012-07-13 09:26:33 +00:00
}
return false;
});
$('#shared-link').click(function() {
$(this).select();
});
{% include "snippets/bottom_bar.html" %}
{% endif %}
2012-08-12 03:22:42 +00:00
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}}';
2012-08-12 03:22:42 +00:00
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');
2012-08-12 03:22:42 +00:00
$('#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'});
2012-08-12 03:22:42 +00:00
} else if (data['error']) {
// other error
$('#open-local-file-error').removeClass();
$('#open-local-file-error').addClass('error');
2012-08-12 03:22:42 +00:00
$('#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');
});
2012-08-12 03:22:42 +00:00
// 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({
2012-08-16 09:37:18 +00:00
url: '{{ applet_root }}/seafile_rpc_version/',
2012-08-12 03:22:42 +00:00
dataType: 'jsonp',
jsonpCallback: 'xx',
crossDomain: true,
success: function(version) {
local_applet_running = true;
2012-08-16 09:37:18 +00:00
if (version < 1) {
2012-08-12 03:22:42 +00:00
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);
}
2012-08-23 02:52:53 +00:00
}
2012-08-12 03:22:42 +00:00
});
// if jsonp response doesn't arrive in 2 seconds, we can say local client
// is not running yet.
setTimeout(function() {
if (!local_applet_running) {
2012-08-16 09:37:18 +00:00
$('#open-local-file-error').html('Seafile 客户端程序未启动或者版本过低');
2012-08-12 03:22:42 +00:00
$('#open-local-file-error-dlg').modal({appendTo:'#main'});
}
}, 2000);
});
2012-07-02 14:45:21 +00:00
</script>
{% endblock %}