1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-04 10:46:58 +00:00
seahub/templates/snippets/repo_file_get.html

182 lines
8.1 KiB
HTML
Raw Normal View History

2012-07-31 08:48:55 +00:00
{% if filetype == 'Text' %}
2012-08-11 06:07:12 +00:00
{% ifnotequal file_content None %}
$('#file-view').html('<div id="docu-view" class="vh">' + '</div>');
var editor = ace.edit("docu-view");
$('#docu-view').removeClass('vh');
editor.setReadOnly(true);
editor.setHighlightActiveLine(false);
$('#docu-view .ace_cursor-layer').hide(); // rm cursor
editor.setShowPrintMargin(false); // rm the vertical line in the center
editor.renderer.scrollBar.element.style.display = "none"; // hide right scrollbar
editor.renderer.scrollBar.width = 0; // enlarge ace_content width
editor.setTheme("ace/theme/chrome");
{% include "snippets/editor_set_mode.html" %}
editor.session.getDocument().setValue('{{ file_content|escapejs }}');
$('#docu-view').css({'position': 'relative', 'height': (editor.session.getScreenLength() + 1) * parseInt($('#docu-view').css('line-height'))}); // '+ 1': offer space for bottom scrollbar
editor.session.setScrollLeft(0); // make bottom scrollbar start from the left-most
editor.resize(); // fix some problem for showing some file in ie8
2012-08-11 06:07:12 +00:00
{% endifnotequal %}
{% if err %}
2012-08-10 13:35:58 +00:00
$('#file-view').html('<p class="error">{{ err }}</p>').addClass('file-view-tip');
{% endif %}
2012-07-31 08:48:55 +00:00
{% endif %}
2012-07-31 08:48:55 +00:00
{% if filetype == 'Image' %}
$('#file-view').html('<img src="{{ raw_path }}" alt="{{ u_filename}}" id="image-view" />').css({'text-align':'center', 'padding':'30px 0'});
2012-08-16 09:51:56 +00:00
window.onload = function() {
if ($('#image-view').width() > $('#file-view').width()) {
$('#image-view').css('width', $('#file-view').width() - 4);
}
}
2012-07-31 08:48:55 +00:00
{% endif %}
2012-07-31 08:48:55 +00:00
{% if filetype == 'SVG' %}
if (!$.browser.mozilla && !$.browser.safari && !($.browser.msie && parseInt($.browser.version) > 8)) {
2012-08-10 13:35:58 +00:00
$('#file-view').html('<p>在线查看请使用firefox, chrome 或 IE 9。</p>').addClass('file-view-tip');
} else {
$('#file-view').html('<div><iframe src="{{ raw_path }}" frameborder="0" id="svg-view"></iframe></div>');
}
2012-07-31 08:48:55 +00:00
{% endif %}
2012-07-31 08:48:55 +00:00
{% if filetype == 'Document' %}
var uuid = '',
obj_id = '';
function create_session() {
$.ajax({
url: '{{ SITE_ROOT }}crocodoc/session/?uuid=' + uuid,
cache: false,
contentType: 'application/json; charset=utf-8',
success: function(data) {
if (data.length > 0) {
2012-08-11 03:20:26 +00:00
$('#file-view').html('<div><iframe src="' + data[0]['doc_src'] + '" frameborder="0" id="doc-view"></iframe></div>').attr('class', '');
2012-07-31 08:48:55 +00:00
}
},
error: function(xhr, ajaxOptions, thrownError) {
var jsonVal = jQuery.parseJSON(xhr.responseText);
2012-08-11 03:20:26 +00:00
$('#file-view').html('<p class="error">' + jsonVal[0]['error'] + '</p>');
2012-07-31 08:48:55 +00:00
}
});
}
function check_status () {
$.ajax({
url: '{{ SITE_ROOT }}crocodoc/status/?uuids='+ uuid + '&obj_id=' + obj_id,
cache: false,
contentType: 'application/json; charset=utf-8',
success: function(data) {
if (data.length > 0) {
var status = data[0]['status'];
if (status == 'QUEUED') {
2012-08-11 03:20:26 +00:00
$('#file-view').html('<p class="msg">' + '文档转换任务正在排队,请稍后...' + '</p>');
2012-07-31 08:48:55 +00:00
setTimeout(check_status, 1000);
} else if (status == 'PROCESSING') {
2012-08-11 03:20:26 +00:00
$('#file-view').html('<p class="msg">' + '文档正在转换,请稍候...' + '</p>');
2012-07-31 08:48:55 +00:00
setTimeout(check_status, 1000);
} else {
2012-08-11 03:20:26 +00:00
$('#file-view').html('<p class="msg">' + '文档转换成功。正在打开...' + '</p>');
2012-07-31 08:48:55 +00:00
create_session();
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
var jsonVal = jQuery.parseJSON(xhr.responseText);
2012-08-11 03:20:26 +00:00
$('#file-view').html('<p class="error">' + jsonVal[0]['error'] + '</p>');
2012-07-31 08:48:55 +00:00
}
});
}
2012-08-04 09:59:30 +00:00
if (!$.browser.mozilla && !$.browser.safari) {
2012-08-10 13:35:58 +00:00
$('#file-view').html('<p>在线查看请使用firefox 或 chrome。</p>').addClass('file-view-tip');
2012-08-04 09:59:30 +00:00
} else {
2012-07-31 08:48:55 +00:00
$.ajax({
url: '{{ SITE_ROOT }}crocodoc/upload/?raw_path={{ raw_path|urlencode }}',
cache: false,
contentType: 'application/json; charset=utf-8',
success: function(data) {
if (data.length > 0) {
uuid = data[0]['uuid'];
obj_id = data[0]['obj_id'];
2012-08-10 13:35:58 +00:00
$('#file-view').html('<p class="msg">文档内容读取成功,开始转换...</p>').addClass('file-view-tip');
2012-07-31 08:48:55 +00:00
check_status();
}
},
error: function(xhr, ajaxOptions, thrownError) {
var jsonVal = jQuery.parseJSON(xhr.responseText);
2012-08-10 13:35:58 +00:00
$('#file-view').html('<p class="error">' + jsonVal[0]['error'] + '</p>').addClass('file-view-tip');
2012-07-31 08:48:55 +00:00
}
});
2012-08-04 09:59:30 +00:00
}
2012-07-31 08:48:55 +00:00
{% endif %}
2012-07-31 08:48:55 +00:00
{% if filetype == 'PDF' %}
2012-08-04 09:59:30 +00:00
if (!$.browser.mozilla && !$.browser.safari) {
2012-08-10 13:35:58 +00:00
$('#file-view').html('<p>在线查看请使用firefox 或 chrome。</p>').addClass('file-view-tip');
2012-08-04 04:04:34 +00:00
} else {
2012-07-31 08:48:55 +00:00
PDFJS.workerSrc = '{{MEDIA_URL}}js/pdf.js';
$('#file-view').html('<div id="pdf"><img src="{{ MEDIA_URL }}pdf_full_view/images/loading-icon.gif" alt="加载中..." id="pdf-loading" style="margin-top:20px;" /><div id="pdf-op-bar" class="vh"><button id="prev">上一页</button><button id="next">下一页</button><span id="pdf-page"><label for="page-number"></label> <input type="number" id="page-number" value="1" min="1"></input> / <span id="page-nums"></span></span><button id="full-screen">全屏</button></div><canvas data="{{ raw_path }}" id="pdf-view" class="vh"></canvas></div>').css({'text-align':'center'});
2012-08-15 02:44:15 +00:00
$('#pdf-op-bar').append($('#file-op').html());
2012-07-31 08:48:55 +00:00
var seahub_getPage = function (pdf, page_number) {
pdf.getPage(page_number).then(function(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
var canvas = $('#pdf-view')[0];
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
var renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext);
});
};
PDFJS.getDocument($('#pdf-view').attr('data')).then(function(pdf) {
$('#page-nums').html(pdf.numPages);
$('#page-number').attr('max', pdf.numPages).css('width', String(pdf.numPages).length * 6 + 10);
seahub_getPage(pdf, 1);
2012-08-15 02:44:15 +00:00
$('#file-op, #pdf-loading').addClass('hide');
2012-07-31 08:48:55 +00:00
$('#pdf-op-bar, #pdf-view').removeClass('vh');
$('#page-number').change(function() {
seahub_getPage(pdf, $(this).val());
});
$('#prev').click(function() {
var current = $('#page-number').val();
if (current > 1) {
seahub_getPage(pdf, --current);
$('#page-number').val(current);
}
});
$('#next').click(function() {
var current = $('#page-number').val();
if (current < pdf.numPages) {
seahub_getPage(pdf, ++current);
$('#page-number').val(current);
}
});
$('#full-screen').click(function() {
window.open('{{ SITE_ROOT }}pdf_full_view/?repo_id={{ repo.id }}&obj_id={{obj_id}}&file_name=' + e('{{ file_name }}'));
});
});
2012-08-04 04:04:34 +00:00
}
2012-07-31 08:48:55 +00:00
{% endif %}
2012-07-31 08:48:55 +00:00
{% if filetype == 'Markdown' %}
2012-08-11 06:07:12 +00:00
{% ifnotequal file_content None %}
var converter = new Showdown.converter();
$('#file-view').html('<div id="md-view" class="article">' + converter.makeHtml('{{ file_content|escapejs }}') + '</div>');
$('#md-view').children(':first').css('margin-top', '0');
2012-08-11 06:07:12 +00:00
{% endifnotequal %}
{% if err %}
2012-08-10 13:35:58 +00:00
$('#file-view').html('<p class="error">{{ err }}</p>').addClass('file-view-tip');
{% endif %}
2012-07-31 08:48:55 +00:00
{% endif %}
2012-07-31 08:48:55 +00:00
{% if filetype == 'Unknown' %}
$('#file-view').html('<p>该类型文件无法在线查看。</p>').addClass('file-view-tip');
2012-07-31 08:48:55 +00:00
{% endif %}