mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-24 21:07:17 +00:00
479 lines
19 KiB
HTML
479 lines
19 KiB
HTML
{% extends base_template %}
|
|
{% load seahub_tags avatar_tags i18n %}
|
|
{% load url from future %}
|
|
|
|
{% block extra_style %}
|
|
{% include 'snippets/file_view_style.html' %}
|
|
{% endblock %}
|
|
|
|
{% block main_panel %}
|
|
<div id="view-hd">
|
|
<h2>{{ u_filename }}</h2>
|
|
</div>
|
|
|
|
<div id="view-path-op" class="w100 ovhd">
|
|
<p class="path fleft">
|
|
{% trans "Current Path: "%}
|
|
{% for name, link in zipped %}
|
|
{% if not forloop.last %}
|
|
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/?p={{ link|urlencode }}">{{ name }}</a> /
|
|
{% else %}
|
|
{{ name }}
|
|
{% endif %}
|
|
{% endfor %}
|
|
</p>
|
|
|
|
<div class="file-op fright">
|
|
<input id="shared-link" class="hide" type="text" readonly="readonly" value="{{ file_shared_link }}" />
|
|
<button data="{% url 'get_shared_link' %}?repo_id={{ repo.id }}&p={{ path|urlencode }}&file_name={{ file_name }}" id="get-shared-link">{% trans "Share link"%}</button>
|
|
<button id="send-shared-link" class="hide">{% trans "Send"%}</button>
|
|
<button data="{% url 'remove_shared_link' %}?t={{ fileshare.token }}" id="rm-shared-link" class="hide">{% trans "Delete"%}</button>
|
|
{% if is_starred %}
|
|
<button id="star" data="starred">{% trans "Unstar"%}</button>
|
|
{% else %}
|
|
<button id="star" data="unstarred">{% trans "Star"%}</button>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
|
|
<div id="file">
|
|
<div id="file-op">
|
|
<div class="commit fleft">
|
|
{% avatar latest_contributor 20 %} <a href="{% url 'user_profile' latest_contributor %}" class="name">{{ latest_contributor|email2nickname }}</a><span class="time">{{ last_modified|translate_seahub_time}}</span>
|
|
|
|
{% if filetype == 'Markdown' or filetype == 'Text' %}
|
|
{% if last_commit_id %}
|
|
<span>{% trans "updated this file"%}, <a class="file-diff" href="{% url 'text_diff' repo.id %}?p={{path|urlencode}}&commit={{last_commit_id}}">{% trans "Detail"%}</a>.</span>
|
|
{% endif %}
|
|
{% else %}
|
|
<span>{% trans "updated this file"%}.</span>
|
|
{% endif %}
|
|
|
|
<span class="contributors">{% blocktrans count counter=contributors|length %}one contributor{% plural %} {{ counter }} contributors {% endblocktrans %}</span>
|
|
{% for user in contributors %}
|
|
<a href="{% url 'user_profile' user %}" title="{{ user|email2nickname}}">{% avatar user 16 %}</a>
|
|
{% endfor %}
|
|
</div>
|
|
|
|
{% if user_perm == 'rw' %}
|
|
<button data-url="{% url 'file_revisions' repo.id %}?p={{ path }}" class="history">{% trans "History"%}</button>
|
|
{% endif %}
|
|
|
|
{% if request.user.is_authenticated %}
|
|
{% if filetype != 'Sf' %}
|
|
<button id="open-local" data="{{path}}{{dirent.obj_name}}">{% trans "Open local file"%}</button>
|
|
{% endif %}
|
|
|
|
{% if not read_only %}
|
|
{% if filetype == 'Text' or filetype == 'Markdown' or filetype == 'Sf' %}
|
|
<button data="{{ SITE_ROOT }}repo/{{ repo.id }}/file/edit/?p={{ path }}" id="edit">{% trans "Edit"%}</button>
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endif %}
|
|
|
|
{% 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">{% trans "Raw"%}</button>
|
|
{% endif %}
|
|
<button data="{{ SITE_ROOT }}repo/{{ repo.id }}/{{ obj_id }}/?file_name={{ file_name }}&op=download" id="download">{% trans "Download"%}</button>
|
|
</div>
|
|
{% include 'snippets/file_content_html.html' %}
|
|
</div>
|
|
|
|
<form id="link-send-form" action="" method="post" class="hide">
|
|
<h3>Send Link</h3>
|
|
<label>{% trans "Send to:"%}</label><br />
|
|
<textarea id="link-send-input" name="email" placeholder="{% trans "Emails, Seperate by ','"%}"></textarea><br />
|
|
<input type="hidden" name="file_shared_link" value="{{ file_shared_link }}" />
|
|
<input type="submit" value="{% trans "Submit"%}" class="submit" />
|
|
<p class="error hide"></p>
|
|
<p id="sending" class="hide">{% trans "Sending..."%}</p>
|
|
</form>
|
|
|
|
<div id="open-local-feedback" class="hide">
|
|
<p id="open-local-handling-tip">{% trans "Processing..."%}</p>
|
|
<p id="open-local-error" class="error"></p>
|
|
<div id="redirect-download" class="hide">
|
|
<p class="error">{% trans "You have not downloaded " %}"{{ repo.props.name }}"{% trans "." %} </p>
|
|
<button data="{{ SITE_ROOT }}download/repo/?repo_id={{ repo.id }}" id="download-repo">{% trans "Click to download"%}</button>
|
|
</div>
|
|
</div>
|
|
|
|
{% with attach_type='file' %}
|
|
{% include "snippets/group_recommend_form.html" %}
|
|
{% endwith %}
|
|
|
|
{% if request.user.is_authenticated %}
|
|
<div id="file-comment" class="hide">
|
|
<form id="file-comment-form" action="" method="post">
|
|
<div class="w100 ovhd">
|
|
<a class="pic fleft" href="{% url 'user_profile' request.user.username %}">{% avatar request.user.username 48 %}</a>
|
|
<div id="comment-container" class="txt fright">
|
|
<textarea name="message" id="comment-input">{% trans "Leave a message~"%}</textarea><br />
|
|
<p class="error hide"></p>
|
|
<input type="submit" value="{% trans "Submit"%}" class="submit hide" />
|
|
</div>
|
|
</div>
|
|
</form>
|
|
<ul id="comment-list">
|
|
{% if comments %}
|
|
{% for comment in comments %}
|
|
<li class="comment ovhd">
|
|
<a class="pic fleft" href="{% url 'user_profile' comment.from_email %}">{% avatar comment.from_email 48 %}</a>
|
|
<div class="txt fright">
|
|
<div class="comment-hd w100 ovhd">
|
|
<a href="{% url 'user_profile' comment.from_email %}" title="{{ comment.from_email }}" class="fleft">{{ comment.from_email|email2nickname }}</a>
|
|
<span class="time fright">{{ comment.timestamp|translate_seahub_time }}</span>
|
|
</div>
|
|
<p class="comment-bd">{{ comment.message|seahub_urlize|find_at|linebreaksbr }}</p>
|
|
</div>
|
|
</li>
|
|
{% endfor %}
|
|
{% endif %}
|
|
</ul>
|
|
</div>
|
|
<div id="comment-caret" class="hide">
|
|
<div class="outer-caret">
|
|
<div class="inner-caret"></div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
{% endblock %}
|
|
|
|
{% block extra_script %}
|
|
{% include "snippets/file_view_js.html" %}
|
|
<script type="text/javascript">
|
|
$('#view-original, #download').click(function() {
|
|
window.open($(this).attr('data'));
|
|
});
|
|
|
|
$('#edit').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();
|
|
var remove_link = '{% url 'remove_shared_link' %}';
|
|
$('#rm-shared-link').attr('data', remove_link + '?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", focus: false});
|
|
$('#simplemodal-container').css('height', 'auto');
|
|
// link-send-form email autocomplete
|
|
var share_list = [], contact_email;
|
|
{% for contact in contacts %}
|
|
contact_email = '{{ contact.contact_email }}';
|
|
share_list.push({value:contact_email, label:contact_email});
|
|
{% endfor %}
|
|
addAutocomplete('#link-send-input', '#link-send-form', share_list);
|
|
});
|
|
|
|
$("#link-send-form").submit(function(event) {
|
|
var form = $(this),
|
|
file_shared_link = form.children('input[name="file_shared_link"]').val(),
|
|
email = $.trim(form.children('textarea[name="email"]').val()),
|
|
submit_btn = form.children('input[type="submit"]');
|
|
|
|
if (!email) {
|
|
apply_form_error('link-send-form', '{% trans "Please input at least an email." %}');
|
|
return false;
|
|
}
|
|
|
|
disable(submit_btn);
|
|
$('#link-send-form .error').addClass('hide');
|
|
$('#sending').removeClass('hide');
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "{% url 'send_shared_link' %}",
|
|
dataType: 'json',
|
|
cache: false,
|
|
contentType: 'application/json; charset=utf-8',
|
|
beforeSend: prepareCSRFToken,
|
|
data: {file_shared_link: file_shared_link, email: email},
|
|
success: function(data) {
|
|
$.modal.close();
|
|
feedback('{% trans "Successfully sent." %}', "success");
|
|
},
|
|
error: function(data, textStatus, jqXHR) {
|
|
$('#sending').addClass('hide');
|
|
enable(submit_btn);
|
|
var errors = $.parseJSON(data.responseText);
|
|
$.each(errors, function(index, value) {
|
|
if (index == 'error') {
|
|
apply_form_error('link-send-form', value);
|
|
} else {
|
|
apply_form_error('link-send-form', value[0]);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
return false;
|
|
});
|
|
$('#shared-link').click(function() {
|
|
$(this).select();
|
|
});
|
|
|
|
//star
|
|
$('#star').click(function() {
|
|
var star_btn = $(this);
|
|
disable(star_btn);
|
|
var state = star_btn.attr('data');
|
|
$.ajax({
|
|
url: '{{ SITE_ROOT }}repo/star_file/{{ repo.id }}/',
|
|
type: 'POST',
|
|
cache: false,
|
|
contentType: 'application/json; charset=utf-8',
|
|
beforeSend: prepareCSRFToken,
|
|
dataType: 'json',
|
|
data: {
|
|
path: '{{ path }}',
|
|
state: state,
|
|
org_id: {% if org %} {{ org.org_id }} {% else %} -1 {% endif %}
|
|
},
|
|
success:function(data) {
|
|
if (data['success']) {
|
|
if (state == 'starred') {
|
|
feedback('{% trans "Unstarred successfully" %}', 'success');
|
|
star_btn.attr('data', 'unstarred').text('{% trans "Star" %}');
|
|
} else {
|
|
feedback('{% trans "Starred successfully" %}', 'success');
|
|
star_btn.attr('data', 'starred').text('{% trans "Unstar" %}');
|
|
}
|
|
} else {
|
|
feedback('{% trans "Failed:" %}' + data['err_msg'], 'error');
|
|
}
|
|
enable(star_btn);
|
|
},
|
|
error:function(jqXHR, textStatus, errorThrown) {
|
|
feedback(textStatus + '{% trans ", failed" %}', 'error');
|
|
enable(star_btn);
|
|
}
|
|
});
|
|
})
|
|
.hover(
|
|
function() {
|
|
$(this).css('background-color', '#fff');
|
|
},
|
|
function() {
|
|
$(this).css('background-color', '#efefef');
|
|
}
|
|
);
|
|
|
|
//open local
|
|
function send_open_local_file_request(path) {
|
|
var callback = 'xx';
|
|
$.ajax({
|
|
url: '{{ applet_root }}/open-local-file/?repo_id={{ repo.id }}&commit_id={{current_commit.id}}&path=' + e(path) + '&callback=' + callback,
|
|
dataType: 'jsonp',
|
|
jsonpCallback: callback,
|
|
crossDomain: true,
|
|
success: function(data) {
|
|
$('#open-local-handling-tip').addClass('hide');
|
|
if (data['exists'] === false) { // repo doesn't exist on local machine
|
|
$('#open-local-error').addClass('hide');
|
|
$('#redirect-download').removeClass('hide');
|
|
|
|
} else if (data['no_assoc'] === true) { // no application to open the file
|
|
$('#open-local-error').html('{% trans "Failed to find an application to open the file. Seafile will open the folder." %}');
|
|
|
|
} else if (data['outdated'] === true) { // local repo not in sync yet
|
|
if (data['auto-sync'] === false) {
|
|
$('#open-local-error').html('{% trans "The file is not synchronized, you can synchronize it manually." %}');
|
|
} else {
|
|
$('#open-local-error').html('{% trans "The file is not synchronized, please retry later." %}');
|
|
}
|
|
|
|
} else if (data['error']) { // other error
|
|
$('#open-local-error').html('{% trans "An error occurred when open the local file." %}');
|
|
|
|
} else { // open file successfully
|
|
$('#open-local-handling-tip').removeClass('hide');
|
|
setTimeout(function() { $.modal.close(); }, 1500);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
$('#download-repo').click(function() {
|
|
location.href = $(this).attr('data');
|
|
});
|
|
|
|
$('#open-local').click(function () {
|
|
var path = $(this).attr('data');
|
|
var local_applet_running = false;
|
|
$('#open-local-feedback').modal({appendTo: '#main', containerCss: { width: 300}});
|
|
$('#simplemodal-container').css('height', 'auto');
|
|
|
|
$.ajax({
|
|
url: '{{ applet_root }}/seafile_rpc_version/',
|
|
dataType: 'jsonp',
|
|
jsonpCallback: 'xx',
|
|
crossDomain: true,
|
|
success: function(version) {
|
|
local_applet_running = true;
|
|
if (version < 1) {
|
|
$('#open-local-handling-tip').addClass('hide');
|
|
$('#open-local-error').html('{% trans 'You are running an old version of Seafile client, please <a target="_blank">upgrade</a> it.' %}');
|
|
$('#open-local-error a').attr('href', 'http://www.seafile.com/{% if LANGUAGE_CODE == "en" %}en/{% endif %}download/');
|
|
} 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-handling-tip').addClass('hide');
|
|
$('#open-local-error').html('{% trans "Your Seafile client is not running or its version is too old. Please check it." %}');
|
|
}
|
|
}, 2000);
|
|
});
|
|
|
|
$('#file-op .history').click(function () {
|
|
location.href = $(this).data('url');
|
|
});
|
|
|
|
//places file_content_js here so that op-btns can work before file content is fully loaded.
|
|
{% include "snippets/file_content_js.html" %}
|
|
|
|
//bottom bar
|
|
{% include "snippets/bottom_bar.html" %}
|
|
{% if request.user.is_authenticated %}
|
|
$('#main-panel').css({'margin-bottom':0});
|
|
$('#bottom-bar').append('<button id="comment">{% trans "Comment" %}</button>');
|
|
$('#file-comment').css({'max-height':$(window).height() - parseInt($('#file-comment').css('bottom'))});
|
|
{% if groups %}
|
|
var gids = '';
|
|
{% for g in groups %}
|
|
gids += '{{ g.id }}_';
|
|
{% endfor %}
|
|
addAtAutocomplete('#comment-input', '#comment-container', gids, "{% url 'group_attention' %}", {'width':'315px','padding-left':'1px','height':'36px','margin':'0','font-size':'13px', 'font-family':'Arial, Helvetica, sans-serif', 'line-height': '1.5em', 'border':'1px solid #ddd'});
|
|
{% endif %}
|
|
$('#comment-input').bind('autocompleteopen', function(e, ui) {
|
|
var menu = $(this).autocomplete('widget');
|
|
if (parseInt(menu.css('top')) > 0) {
|
|
menu.css('max-height', $('#file-comment').height() - parseInt(menu.css('top')));
|
|
} else {
|
|
menu.css('max-height', $('#file-comment').offset().top);
|
|
}
|
|
});
|
|
{% if comment_open %}
|
|
$('#file-comment, #comment-caret').removeClass('hide');
|
|
$(function() { $('#comment-caret').css({'left': $('#comment').offset().left}); });
|
|
{% endif %}
|
|
$('#comment').click(function() {
|
|
if ($('#file-comment').hasClass('hide')) {
|
|
$('#file-comment, #comment-caret').removeClass('hide');
|
|
$('#comment-caret').css({'left':$('#comment').offset().left});
|
|
$('#comment-list').css({'max-height':parseInt($('#file-comment').css('max-height')) - $('#file-comment-form').outerHeight(true), 'overflow':'auto'});
|
|
} else {
|
|
$('#file-comment, #comment-caret').addClass('hide');
|
|
}
|
|
});
|
|
$(document).click(function(e) {
|
|
var target = e.target || event.srcElement;
|
|
if (!$('#comment, #file-comment, #comment-caret').is(target) && !($('#file-comment, #comment-caret').find('*').is(target))) {
|
|
$('#file-comment, #comment-caret').addClass('hide');
|
|
}
|
|
});
|
|
|
|
var comment_input_pre_text = $('#comment-input').val();
|
|
$('#comment-input').css('color', '#999').click(function() {
|
|
if ($(this).val() == comment_input_pre_text) {
|
|
$(this).val('').css('color', '#000');
|
|
$('#file-comment-form .submit').removeClass('hide');
|
|
$('#comment-list').css({'max-height':parseInt($('#file-comment').css('max-height')) - $('#file-comment-form').outerHeight(true), 'overflow':'auto'});
|
|
}
|
|
});
|
|
$('#file-comment-form .submit').click(function() {
|
|
if (!$.trim($('#comment-input').val())) {
|
|
$('#file-comment-form .error').html('{% trans "Please type a message" %}').removeClass('hide');
|
|
return false;
|
|
}
|
|
$.ajax({
|
|
url: '{% url 'views.file_comment' %}' + '?p={{path}}',
|
|
type: 'POST',
|
|
dataType: 'json',
|
|
contentType: 'application/json; charset=utf-8',
|
|
beforeSend: prepareCSRFToken,
|
|
data: {
|
|
'repo_id': '{{ repo.id }}',
|
|
'file_path': '{{ path|urlencode }}',
|
|
'message': $('#comment-input').val()
|
|
},
|
|
success: function(data) {
|
|
$('#comment-input').val(comment_input_pre_text).css('color', '#999');
|
|
$('#file-comment-form .submit, #file-comment-form .error').addClass('hide');
|
|
$('#comment-list').html(data.html);
|
|
},
|
|
error: function(data, textStatus, jqXHR) {
|
|
var errors = $.parseJSON(data.responseText);
|
|
$.each(errors, function(index, value) {
|
|
$('#file-comment-form .error').html(value[0]).removeClass('hide');
|
|
});
|
|
}
|
|
});
|
|
return false;
|
|
});
|
|
{% endif %}
|
|
</script>
|
|
{% endblock %}
|