1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-02 07:47:32 +00:00
seahub/templates/repo_edit_file.html
2012-09-01 20:34:42 +08:00

106 lines
4.3 KiB
HTML

{% extends base_template %}
{% load seahub_tags %}
{% block main_panel %}
<h2>编辑 {{ u_filename }}</h2>
<p class="path">
当前路径:
{% for name, link in zipped %}
{% if not forloop.last %}
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/?p={{ link|urlencode }}">{{ name }}</a> /
{% else %}
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/files/?p={{ path }}">{{ name }}</a>
{% endif %}
{% endfor %}
</p>
<div id="file">
<p id="file-fetching-tip">文件内容读取中...</p>
<div id="docu-view" class="hide"></div>
{% if fileext == 'markdown' or fileext == 'md' %}
<div id="md-view" class="article hide"></div>
{% endif %}
</div>
<div id="op-after-edit" class="w100 ovhd hide">
{% if fileext == 'markdown' or fileext == 'md' %}
<div class="fleft">
<button id="file-edit-submit">提交</button>
<button id="source-code" class="hide">原文件</button>
<button id="preview">预览</button>
</div>
{% else %}
<button id="file-edit-submit" class="fleft">提交</button>
{% endif %}
<button data="{{ SITE_ROOT }}repo/{{ repo.id }}/files/?p={{ path }}" id="file-edit-cancel" class="fright">取消修改</button>
</div>
{% 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 %}
<script type="text/javascript">
{% ifnotequal file_content None %}
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 }}');
editor.session.getDocument().setNewLineMode('{{ newline_mode }}');
$('#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
$('#file-fetching-tip').addClass('hide');
$('#docu-view, #op-after-edit').removeClass('hide');
{% if fileext == 'markdown' or fileext == 'md' %}
$('#file-edit-submit').css('margin-right', '8px');
$('#source-code').click(function() {
$('#md-view, #source-code').addClass('hide');
$('#docu-view, #preview').removeClass('hide');
});
$('#preview').click(function() {
var content = editor.session.getValue();
var converter = new Showdown.converter();
$('#docu-view, #preview').addClass('hide');
$('#md-view').html(converter.makeHtml(content)).removeClass('hide');
$('#md-view').children(':first').css('margin-top', '0');
$('#source-code').removeClass('hide');
});
{% endif %}
$('#file-edit-submit').click(function () {
var content = editor.session.getValue();
$.ajax({
type: "POST",
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);
$('#op-after-edit').prepend('<p class="error">' + jsonVal['error'] + '</p>');
}
});
});
$('#file-edit-cancel').click(function() {
location.href = $(this).attr('data');
});
{% endifnotequal %}
{% if err %}
$('#file').html('<p class="error">{{ err }}</p>');
{% endif %}
</script>
{% endblock %}