2012-07-30 02:25:46 +00:00
{% extends base_template %}
2012-10-27 11:41:00 +00:00
{% load seahub_tags avatar_tags i18n %}
2012-08-13 07:58:54 +00:00
{% load url from future %}
2012-07-02 14:45:21 +00:00
2012-09-13 08:36:23 +00:00
{% block extra_style %}
2012-12-19 11:52:34 +00:00
{% include 'snippets/file_view_style.html' %}
2012-09-13 08:36:23 +00:00
{% endblock %}
2012-08-13 09:40:27 +00:00
{% block main_panel %}
2012-12-19 11:52:34 +00:00
< div id = "view-hd" >
2013-03-08 02:20:35 +00:00
< h2 > {{ filename }}< / h2 >
2012-11-27 07:47:08 +00:00
< / div >
< div id = "view-path-op" class = "w100 ovhd" >
2012-09-17 04:57:29 +00:00
< p class = "path fleft" >
2012-10-27 11:41:00 +00:00
{% trans "Current Path: "%}
2012-09-17 04:57:29 +00:00
{% for name, link in zipped %}
2012-09-21 12:36:53 +00:00
{% if not forloop.last %}
< a href = "{{ SITE_ROOT }}repo/{{ repo.id }}/?p={{ link|urlencode }}" > {{ name }}< / a > /
{% else %}
{{ name }}
{% endif %}
2012-09-17 04:57:29 +00:00
{% endfor %}
< / p >
< div class = "file-op fright" >
< input id = "shared-link" class = "hide" type = "text" readonly = "readonly" value = "{{ file_shared_link }}" / >
2013-01-08 09:43:29 +00:00
< button data = "{% url 'get_shared_link' %}?repo_id={{ repo.id }}&p={{ path|urlencode }}" id = "get-shared-link" class = "hide" > {% trans "Share link"%}< / button >
2012-10-27 11:41:00 +00:00
< button id = "send-shared-link" class = "hide" > {% trans "Send"%}< / button >
2012-11-06 03:12:49 +00:00
< button data = "{% url 'remove_shared_link' %}?t={{ fileshare.token }}" id = "rm-shared-link" class = "hide" > {% trans "Delete"%}< / button >
2012-10-26 11:50:36 +00:00
{% if is_starred %}
2013-01-07 09:04:02 +00:00
< button id = "star" data-status = "starred" > {% trans "Unstar"%}< / button >
2012-10-26 11:50:36 +00:00
{% else %}
2013-01-07 09:04:02 +00:00
< button id = "star" data-status = "unstarred" > {% trans "Star"%}< / button >
2012-10-26 11:50:36 +00:00
{% endif %}
2012-09-17 04:57:29 +00:00
< / div >
2012-07-13 09:26:33 +00:00
< / div >
2012-09-17 04:57:29 +00:00
2012-08-10 13:35:58 +00:00
< div id = "file" >
2012-08-15 02:44:15 +00:00
< div id = "file-op" >
2012-11-27 07:47:08 +00:00
< div class = "commit fleft" >
2012-12-31 09:32:13 +00:00
{% if latest_contributor %}
{% avatar latest_contributor 20 %} < a href = "{% url 'user_profile' latest_contributor %}" class = "name" > {{ latest_contributor|email2nickname }}< / a >
{% endif %}
{% if last_modified %}
< span class = "time" > {{ last_modified|translate_seahub_time}}< / span >
{% endif %}
2012-11-28 07:24:11 +00:00
2012-12-14 11:56:27 +00:00
{% if filetype == 'Markdown' or filetype == 'Text' %}
{% if last_commit_id %}
2013-02-27 07:19:24 +00:00
< span > {% trans "updated this file"%}, < a class = "file-diff" href = "{% url 'text_diff' repo.id %}?p={{path|urlencode}}&commit={{last_commit_id}}&file_enc={{file_enc}}" > {% trans "Detail"%}< / a > .< / span >
2012-12-14 11:56:27 +00:00
{% endif %}
{% else %}
2012-12-31 09:32:13 +00:00
{% if last_commit_id %}
< span > {% trans "updated this file"%}.< / span >
{% endif %}
2012-11-28 07:24:11 +00:00
{% endif %}
2012-12-14 11:56:27 +00:00
2012-11-27 07:47:08 +00:00
< 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 >
2012-12-14 11:56:27 +00:00
2012-11-27 07:47:08 +00:00
{% if user_perm == 'rw' %}
< button data-url = "{% url 'file_revisions' repo.id %}?p={{ path }}" class = "history" > {% trans "History"%}< / button >
{% endif %}
2012-12-14 11:56:27 +00:00
{% if request.user.is_authenticated %}
{% if filetype != 'Sf' %}
< button id = "open-local" data = "{{path}}{{dirent.obj_name}}" > {% trans "Open local file"%}< / button >
{% endif %}
2013-03-08 02:20:35 +00:00
{% if user_perm == 'rw' and not err%}
2012-12-14 11:56:27 +00:00
{% if filetype == 'Text' or filetype == 'Markdown' or filetype == 'Sf' %}
2013-02-24 08:52:10 +00:00
< button data = "{{ SITE_ROOT }}repo/{{ repo.id }}/file/edit/?p={{ path }}&file_enc={{file_enc}}" id = "edit" > {% trans "Edit"%}< / button >
2012-12-14 11:56:27 +00:00
{% endif %}
{% endif %}
2012-09-19 12:42:55 +00:00
{% endif %}
2012-12-14 11:56:27 +00:00
2012-12-20 11:50:56 +00:00
< button data = "{{ SITE_ROOT }}repo/{{ repo.id }}/{{ obj_id }}/?file_name={{ file_name }}&op=download" id = "download" > {% trans "Download"%}< / button >
2012-08-10 13:35:58 +00:00
< / div >
2013-01-31 05:17:28 +00:00
{% with page='file_view' %}
2012-12-20 11:50:56 +00:00
{% include 'snippets/file_content_html.html' %}
2013-01-31 05:17:28 +00:00
{% endwith %}
2012-07-02 14:45:21 +00:00
< / div >
2012-07-11 14:39:36 +00:00
2012-12-12 11:43:17 +00:00
< form id = "link-send-form" action = "" method = "post" class = "hide" >
2013-01-17 03:21:52 +00:00
< h3 > {% trans "Send Link" %}< / h3 >
2012-12-12 11:43:17 +00:00
< label > {% trans "Send to:"%}< / label > < br / >
2012-12-29 12:46:26 +00:00
< textarea id = "link-send-input" name = "email" placeholder = "{% trans " Emails , Seperated by ' , ' " % } " > < / textarea > < br / >
2012-07-13 09:26:33 +00:00
< input type = "hidden" name = "file_shared_link" value = "{{ file_shared_link }}" / >
2012-10-27 11:41:00 +00:00
< input type = "submit" value = "{% trans " Submit " % } " class = "submit" / >
2012-09-15 13:16:34 +00:00
< p class = "error hide" > < / p >
2012-10-27 11:41:00 +00:00
< p id = "sending" class = "hide" > {% trans "Sending..."%}< / p >
2012-07-11 14:39:36 +00:00
< / form >
2012-09-14 08:11:53 +00:00
< div id = "open-local-feedback" class = "hide" >
2012-10-29 13:43:52 +00:00
< p id = "open-local-handling-tip" > {% trans "Processing..."%}< / p >
2012-09-14 08:11:53 +00:00
< p id = "open-local-error" class = "error" > < / p >
< div id = "redirect-download" class = "hide" >
2012-11-27 09:17:35 +00:00
< p class = "error" > {% trans "You have not downloaded " %}"{{ repo.props.name }}"{% trans "." %} < / p >
2012-10-27 11:41:00 +00:00
< button data = "{{ SITE_ROOT }}download/repo/?repo_id={{ repo.id }}" id = "download-repo" > {% trans "Click to download"%}< / button >
2012-09-14 08:11:53 +00:00
< / div >
< / div >
2013-01-07 06:23:17 +00:00
< iframe class = "hide" id = "open-local-iframe" > < / iframe >
2012-08-13 07:58:54 +00:00
{% with attach_type='file' %}
{% include "snippets/group_recommend_form.html" %}
{% endwith %}
2012-08-12 03:22:42 +00:00
2012-09-19 12:42:55 +00:00
{% if request.user.is_authenticated %}
< div id = "file-comment" class = "hide" >
< form id = "file-comment-form" action = "" method = "post" >
2012-09-19 13:01:59 +00:00
< div class = "w100 ovhd" >
2012-09-19 12:42:55 +00:00
< a class = "pic fleft" href = "{% url 'user_profile' request.user.username %}" > {% avatar request.user.username 48 %}< / a >
2012-10-20 11:43:56 +00:00
< div id = "comment-container" class = "txt fright" >
2012-10-27 11:41:00 +00:00
< textarea name = "message" id = "comment-input" > {% trans "Leave a message~"%}< / textarea > < br / >
2012-09-19 13:01:59 +00:00
< p class = "error hide" > < / p >
2012-10-27 11:41:00 +00:00
< input type = "submit" value = "{% trans " Submit " % } " class = "submit hide" / >
2012-09-19 12:42:55 +00:00
< / div >
< / div >
< / form >
< ul id = "comment-list" >
2012-09-19 13:01:59 +00:00
{% if comments %}
2012-09-19 12:42:55 +00:00
{% 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 >
2012-11-05 09:27:57 +00:00
< span class = "time fright" > {{ comment.timestamp|translate_seahub_time }}< / span >
2012-09-19 12:42:55 +00:00
< / div >
< p class = "comment-bd" > {{ comment.message|seahub_urlize|find_at|linebreaksbr }}< / p >
< / div >
< / li >
{% endfor %}
{% endif %}
2012-09-19 13:01:59 +00:00
< / ul >
2012-08-26 03:48:43 +00:00
< / div >
2012-09-19 12:42:55 +00:00
< div id = "comment-caret" class = "hide" >
2012-10-22 09:15:35 +00:00
< div class = "outer-caret" >
< div class = "inner-caret" > < / div >
2012-09-19 12:42:55 +00:00
< / div >
2012-08-26 03:48:43 +00:00
< / div >
2012-09-19 12:42:55 +00:00
{% endif %}
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" >
2013-01-31 05:17:28 +00:00
{% if filetype == 'Image' %}
2013-02-27 10:34:39 +00:00
{% if img_prev or img_next %}
2013-02-28 10:07:05 +00:00
var input_focus = false;
$('input, textarea').focus(function() {
input_focus = true;
}).blur(function() {
input_focus = false;
});
2013-01-31 05:17:28 +00:00
$('body').bind('keydown', function(e) {
2013-02-28 10:07:05 +00:00
if (!input_focus) { // so cursor move in form input element can work normally
2013-02-27 10:34:39 +00:00
{% if img_prev %}
if (e.keyCode == 37) { // press '< - '
location.href = $('#img-prev').attr('href');
}
{% endif %}
{% if img_next %}
if (e.keyCode == 39) { // press '->'
location.href = $('#img-next').attr('href');
}
{% endif %}
2013-01-31 05:17:28 +00:00
}
})
{% endif %}
2013-02-27 10:34:39 +00:00
{% endif %}
2012-08-10 13:35:58 +00:00
$('#view-original, #download').click(function() {
window.open($(this).attr('data'));
});
2012-12-14 11:56:27 +00:00
2012-11-10 12:07:54 +00:00
$('#edit').click(function() {
2012-08-10 13:35:58 +00:00
location.href = $(this).attr('data');
});
2012-07-11 14:39:36 +00:00
2013-01-03 11:28:57 +00:00
//share link
{% include "snippets/shared_link_js.html" %}
2012-09-07 11:50:29 +00:00
2012-12-14 11:56:27 +00:00
//star
$('#star').click(function() {
var star_btn = $(this);
disable(star_btn);
2013-01-07 09:04:02 +00:00
var state = star_btn.data('status');
2012-12-14 11:56:27 +00:00
$.ajax({
2013-01-07 09:04:02 +00:00
url: '{% url 'repo_star_file' repo.id %}',
2012-12-14 11:56:27 +00:00
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');
2013-01-07 09:04:02 +00:00
star_btn.data('status', 'unstarred').text('{% trans "Star" %}');
2012-12-14 11:56:27 +00:00
} else {
feedback('{% trans "Starred successfully" %}', 'success');
2013-01-07 09:04:02 +00:00
star_btn.data('status', 'starred').text('{% trans "Unstar" %}');
2012-12-14 11:56:27 +00:00
}
2013-01-07 09:04:02 +00:00
enable(star_btn);
2012-12-14 11:56:27 +00:00
}
},
2013-01-07 09:04:02 +00:00
error:function(xhr, textStatus, errorThrown) {
if (xhr.responseText) {
feedback(jQuery.parseJSON(xhr.responseText).error, 'error');
} else {
feedback('{% trans "Failed. Please check the network." %}', 'error');
}
2012-12-14 11:56:27 +00:00
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.' %}');
2013-01-07 06:23:17 +00:00
$('#open-local-error a').attr('href', 'http://www.seafile.com/');
2012-12-14 11:56:27 +00:00
} else {
send_open_local_file_request(path);
}
}
});
2013-01-07 06:23:17 +00:00
var url = '{{ applet_root }}/open-local-file/?repo_id={{ repo.id }}& commit_id={{current_commit.id}}& path=' + e(path) + '&callback=xx';
var url_short = url.slice(0, 40) + '...';
2012-12-14 11:56:27 +00:00
setTimeout(function() {
if (!local_applet_running) {
$('#open-local-handling-tip').addClass('hide');
2013-01-10 05:21:08 +00:00
$('#open-local-error').html("{% trans 'No running Seafile client is detected. If you are sure Seafile client is running, click the following link to open the local file:' %}" + '< br / > < a href = "' + url + '" target = "open-local-iframe" > ' + url_short + '< / a > ');
2012-12-14 11:56:27 +00:00
}
2013-01-07 06:23:17 +00:00
}, 2000);
2012-12-14 11:56:27 +00:00
});
$('#file-op .history').click(function () {
location.href = $(this).data('url');
});
2012-12-20 11:50:56 +00:00
//places file_content_js here so that op-btns can work before file content is fully loaded.
{% include "snippets/file_content_js.html" %}
2012-12-14 11:56:27 +00:00
2012-12-20 11:50:56 +00:00
//bottom bar
2012-08-08 09:14:04 +00:00
{% include "snippets/bottom_bar.html" %}
2012-09-19 12:42:55 +00:00
{% if request.user.is_authenticated %}
2012-12-14 11:56:27 +00:00
$('#main-panel').css({'margin-bottom':0});
2012-11-13 08:22:35 +00:00
$('#bottom-bar').append('< button id = "comment" > {% trans "Comment" %}< / button > ');
2013-02-22 03:00:04 +00:00
$('#file-comment').css({'max-height':$(window).height() * 0.7 - $('#bottom-bar').height() - $('#comment-caret').height()});
2012-11-28 11:39:22 +00:00
{% if groups %}
2012-10-23 08:19:20 +00:00
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'});
2012-11-28 11:39:22 +00:00
{% endif %}
2012-10-23 08:19:20 +00:00
$('#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);
}
});
2012-09-20 02:45:09 +00:00
{% if comment_open %}
$('#file-comment, #comment-caret').removeClass('hide');
2012-11-13 08:22:35 +00:00
$(function() { $('#comment-caret').css({'left': $('#comment').offset().left}); });
2013-01-12 12:41:00 +00:00
$('#comment-list').css({'max-height':parseInt($('#file-comment').css('max-height')) - $('#file-comment-form').outerHeight(true), 'overflow':'auto'});
2012-09-20 02:45:09 +00:00
{% endif %}
2012-09-19 12:42:55 +00:00
$('#comment').click(function() {
if ($('#file-comment').hasClass('hide')) {
$('#file-comment, #comment-caret').removeClass('hide');
2012-11-13 08:22:35 +00:00
$('#comment-caret').css({'left':$('#comment').offset().left});
2012-10-23 08:19:20 +00:00
$('#comment-list').css({'max-height':parseInt($('#file-comment').css('max-height')) - $('#file-comment-form').outerHeight(true), 'overflow':'auto'});
2012-09-19 12:42:55 +00:00
} else {
$('#file-comment, #comment-caret').addClass('hide');
}
});
2012-09-20 03:55:19 +00:00
$(document).click(function(e) {
var target = e.target || event.srcElement;
2012-10-20 13:37:02 +00:00
if (!$('#comment, #file-comment, #comment-caret').is(target) & & !($('#file-comment, #comment-caret').find('*').is(target))) {
2012-09-20 03:55:19 +00:00
$('#file-comment, #comment-caret').addClass('hide');
}
});
2012-09-19 12:42:55 +00:00
var comment_input_pre_text = $('#comment-input').val();
$('#comment-input').css('color', '#999').click(function() {
2012-09-25 02:48:26 +00:00
if ($(this).val() == comment_input_pre_text) {
$(this).val('').css('color', '#000');
$('#file-comment-form .submit').removeClass('hide');
2012-10-23 08:19:20 +00:00
$('#comment-list').css({'max-height':parseInt($('#file-comment').css('max-height')) - $('#file-comment-form').outerHeight(true), 'overflow':'auto'});
2012-09-25 02:48:26 +00:00
}
2012-09-19 12:42:55 +00:00
});
$('#file-comment-form .submit').click(function() {
if (!$.trim($('#comment-input').val())) {
2013-01-07 09:04:02 +00:00
$('#file-comment-form .error').html('{% trans "Please input a message." %}').removeClass('hide');
2012-09-19 12:42:55 +00:00
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);
},
2013-01-07 09:04:02 +00:00
error: function() {
$('#file-comment-form .error').html('{% trans "Failed. Please check the network." %}').removeClass('hide');
2012-09-19 12:42:55 +00:00
}
});
return false;
});
{% endif %}
2012-07-02 14:45:21 +00:00
< / script >
{% endblock %}