1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-22 16:56:57 +00:00
seahub/templates/repo_edit_file.html

106 lines
4.3 KiB
HTML
Raw Normal View History

2012-08-06 12:29:14 +00:00
{% extends base_template %}
{% load seahub_tags %}
{% block main_panel %}
2012-08-07 03:47:10 +00:00
<h2>编辑 {{ u_filename }}</h2>
2012-08-17 09:24:15 +00:00
<p class="path">
2012-08-06 12:29:14 +00:00
当前路径:
{% for name, link in zipped %}
{% if not forloop.last %}
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/?p={{ link|urlencode }}">{{ name }}</a> /
{% else %}
2012-08-17 09:24:15 +00:00
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/files/?p={{ path }}">{{ name }}</a>
2012-08-06 12:29:14 +00:00
{% endif %}
{% endfor %}
</p>
2012-08-17 09:24:15 +00:00
<div id="file">
<p id="file-fetching-tip">文件内容读取中...</p>
<div id="docu-view" class="hide"></div>
2012-08-22 06:41:36 +00:00
{% if fileext == 'markdown' or fileext == 'md' %}
<div id="md-view" class="article hide"></div>
{% endif %}
2012-08-06 12:29:14 +00:00
</div>
<div id="op-after-edit" class="w100 ovhd hide">
2012-08-22 06:41:36 +00:00
{% if fileext == 'markdown' or fileext == 'md' %}
<div class="fleft">
<button id="file-edit-submit">提交</button>
2012-08-22 08:31:06 +00:00
<button id="source-code" class="hide">原文件</button>
2012-08-22 06:41:36 +00:00
<button id="preview">预览</button>
</div>
{% else %}
<button id="file-edit-submit" class="fleft">提交</button>
2012-08-22 06:41:36 +00:00
{% endif %}
<button data="{{ SITE_ROOT }}repo/{{ repo.id }}/files/?p={{ path }}" id="file-edit-cancel" class="fright">取消修改</button>
</div>
2012-08-06 12:29:14 +00:00
{% endblock %}
{% block extra_script %}
<script type="text/javascript" src="{{MEDIA_URL}}ace/ace.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}ace/theme-twilight.js"></script>
{% include "snippets/file_view_js.html" %}
{% if fileext == 'markdown' or fileext == 'md' %}
<script type="text/javascript" src="{{MEDIA_URL}}ace/mode-markdown.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}js/showdown.js"></script>
{% endif %}
2012-08-06 12:29:14 +00:00
<script type="text/javascript">
2012-08-11 06:07:12 +00:00
{% ifnotequal file_content None %}
2012-08-17 09:24:15 +00:00
var editor = ace.edit("docu-view");
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/twilight");
{% include "snippets/editor_set_mode.html" %}
editor.session.getDocument().setValue('{{ file_content|escapejs }}');
2012-08-22 09:08:52 +00:00
editor.session.getDocument().setNewLineMode('{{ newline_mode }}');
2012-08-24 02:58:29 +00:00
$('#docu-view').css({'position': 'relative', 'height': (editor.session.getScreenLength() + 1) * parseInt($('#docu-view').css('line-height')), 'min-height': '400px'}); // '+ 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-17 09:24:15 +00:00
$('#file-fetching-tip').addClass('hide');
$('#docu-view, #op-after-edit').removeClass('hide');
2012-08-22 06:41:36 +00:00
{% if fileext == 'markdown' or fileext == 'md' %}
2012-08-22 06:41:36 +00:00
$('#file-edit-submit').css('margin-right', '8px');
$('#source-code').click(function() {
2012-08-22 06:41:36 +00:00
$('#md-view, #source-code').addClass('hide');
$('#docu-view, #preview').removeClass('hide');
});
$('#preview').click(function() {
var content = editor.session.getValue();
var converter = new Showdown.converter();
2012-08-22 06:41:36 +00:00
$('#docu-view, #preview').addClass('hide');
$('#md-view').html(converter.makeHtml(content)).removeClass('hide');
2012-08-22 06:41:36 +00:00
$('#md-view').children(':first').css('margin-top', '0');
$('#source-code').removeClass('hide');
});
{% endif %}
2012-08-22 06:41:36 +00:00
$('#file-edit-submit').click(function () {
var content = editor.session.getValue();
$.ajax({
type: "POST",
2012-09-01 12:32:43 +00:00
url: '{{ SITE_ROOT }}repo/{{repo.id}}/file/edit/?p={{path|urlencode}}',
dataType: 'json',
cache: false,
contentType: 'application/json; charset=utf-8',
beforeSend: prepareCSRFToken,
data: {content: content, encoding: '{{ encoding }}'},
success: function(data) {
location.href = $('#file-edit-cancel').attr('data');
},
error: function(xhr, ajaxOptions, thrownError) {
var jsonVal = jQuery.parseJSON(xhr.responseText);
2012-09-01 12:32:43 +00:00
$('#op-after-edit').prepend('<p class="error">' + jsonVal['error'] + '</p>');
}
});
2012-08-06 12:29:14 +00:00
});
$('#file-edit-cancel').click(function() {
location.href = $(this).attr('data');
});
2012-08-11 06:07:12 +00:00
{% endifnotequal %}
{% if err %}
2012-09-01 12:32:43 +00:00
$('#file').html('<p class="error">{{ err }}</p>');
{% endif %}
2012-08-06 12:29:14 +00:00
</script>
{% endblock %}