2012-08-06 12:29:14 +00:00
|
|
|
{% extends base_template %}
|
2012-11-04 05:29:20 +00:00
|
|
|
{% load seahub_tags i18n %}
|
2012-08-06 12:29:14 +00:00
|
|
|
|
2012-09-13 08:36:23 +00:00
|
|
|
{% block extra_style %}
|
2012-11-20 08:28:33 +00:00
|
|
|
{% if filetype == 'Sf' %}
|
|
|
|
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}aloha-0.22.3/css/aloha.css" />
|
|
|
|
{% else %}
|
2012-09-13 08:36:23 +00:00
|
|
|
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}codemirror/codemirror.css" />
|
|
|
|
<style type="text/css">
|
|
|
|
.CodeMirror-focused pre.CodeMirror-cursor {
|
|
|
|
visibility: visible;
|
|
|
|
}
|
2012-10-15 07:49:12 +00:00
|
|
|
.CodeMirror-scroll {
|
|
|
|
height:auto;
|
|
|
|
}
|
2012-09-13 08:36:23 +00:00
|
|
|
</style>
|
|
|
|
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}codemirror/monokai.css" />
|
2012-11-20 08:28:33 +00:00
|
|
|
{% endif %}
|
2012-09-13 08:36:23 +00:00
|
|
|
{% endblock %}
|
|
|
|
|
2012-08-06 12:29:14 +00:00
|
|
|
{% block main_panel %}
|
2012-11-20 08:28:33 +00:00
|
|
|
<h2>{% trans "Edit" %} <span class="op-target">{{ u_filename }}</span></h2>
|
2012-11-21 07:10:42 +00:00
|
|
|
<div id="path-op" class="ovhd">
|
2012-11-20 08:28:33 +00:00
|
|
|
<p class="path fleft">
|
2012-11-04 05:29:20 +00:00
|
|
|
{% trans "Current 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-11-21 07:10:42 +00:00
|
|
|
<div id="op-after-edit" class="fright hide">
|
2012-11-23 03:29:02 +00:00
|
|
|
<button data="{{ SITE_ROOT }}repo/{{ repo.id }}/files/?p={{ path }}" id="file-edit-cancel">{% trans "Cancel" %}</button>
|
2012-11-21 07:10:42 +00:00
|
|
|
{% if filetype == 'Markdown' %}
|
|
|
|
<button id="source-code-btn" class="hide">{% trans "Continue editing" %}</button>
|
|
|
|
<button id="preview-btn">{% trans "Preview" %}</button>
|
|
|
|
{% endif %}
|
2012-11-23 03:29:02 +00:00
|
|
|
<button id="file-edit-submit">{% trans "Submit" %}</button>
|
2012-11-20 08:28:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2012-11-21 07:10:42 +00:00
|
|
|
<div id="file-edit">
|
2012-09-13 08:36:23 +00:00
|
|
|
{% ifnotequal file_content None %}
|
2012-11-20 08:28:33 +00:00
|
|
|
{% ifnotequal filetype 'Sf' %}
|
2012-09-13 08:36:23 +00:00
|
|
|
<textarea id="docu-view" class="hide">{{ file_content|escape }}</textarea>
|
2012-11-20 08:28:33 +00:00
|
|
|
{% else %}
|
|
|
|
<div id="sf" class="article">{{ file_content|safe }}</div>
|
|
|
|
{% endifnotequal %}
|
2012-09-13 08:36:23 +00:00
|
|
|
{% endifnotequal %}
|
|
|
|
{% if filetype == 'Markdown' %}
|
2012-08-22 06:41:36 +00:00
|
|
|
<div id="md-view" class="article hide"></div>
|
2012-08-22 04:07:51 +00:00
|
|
|
{% endif %}
|
2012-08-06 12:29:14 +00:00
|
|
|
</div>
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% block extra_script %}
|
2012-11-20 08:28:33 +00:00
|
|
|
{% if filetype == 'Sf' %}
|
|
|
|
<script type="text/javascript" src="{{MEDIA_URL}}aloha-0.22.3/lib/require.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
//settings must be before aloha.js
|
|
|
|
Aloha = window.Aloha || {};
|
|
|
|
Aloha.settings = Aloha.settings || {};
|
|
|
|
if ($('#lang-context').attr('data-lang') == 'zh-cn') {
|
|
|
|
Aloha.settings.locale = "zh-hans";
|
|
|
|
}
|
|
|
|
</script>
|
2012-11-20 11:38:31 +00:00
|
|
|
<script type="text/javascript" src="{{MEDIA_URL}}aloha-0.22.3/lib/aloha.js" data-aloha-plugins="common/format, common/abbr, common/align, common/characterpicker, common/image, common/link, common/list, common/table, common/undo, common/ui"></script>
|
2012-11-20 08:28:33 +00:00
|
|
|
{% else %}
|
2012-09-13 08:36:23 +00:00
|
|
|
<script type="text/javascript" src="{{MEDIA_URL}}codemirror/codemirror.js"></script>
|
2012-11-20 08:28:33 +00:00
|
|
|
{% endif %}
|
2012-09-13 08:36:23 +00:00
|
|
|
{% if filetype == 'Markdown' %}
|
2012-08-22 04:07:51 +00:00
|
|
|
<script type="text/javascript" src="{{MEDIA_URL}}js/showdown.js"></script>
|
2012-08-08 03:12:40 +00:00
|
|
|
{% 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-11-20 08:28:33 +00:00
|
|
|
$('#main').css('width','100%');
|
2012-11-21 07:10:42 +00:00
|
|
|
$('h2, #path-op').css({'width':950, 'margin':'0 auto'});
|
|
|
|
$('#file-edit').css({'background':'#f4f4f4', 'border-top':'1px solid #ededed'});
|
|
|
|
$('#sf, #md-view').css({'width':690, 'margin':'35px auto', 'border':'1px solid #ccc', 'box-shadow':'0 0 6px #ccc', 'min-height':400});
|
|
|
|
$('#footer').addClass('hide');
|
|
|
|
{% if filetype == 'Sf' %}
|
2012-11-20 08:28:33 +00:00
|
|
|
Aloha.ready(function() { $('#sf').aloha().focus(); });
|
|
|
|
{% else %}
|
2012-09-13 08:36:23 +00:00
|
|
|
var editor = CodeMirror.fromTextArea($('#docu-view')[0], {
|
|
|
|
{% include "snippets/editor_set_mode.html" %}
|
|
|
|
{% if filetype == 'Markdown' %}
|
|
|
|
mode: 'markdown',
|
|
|
|
{% endif %}
|
|
|
|
theme: 'monokai',
|
|
|
|
indentUnit: 4,
|
|
|
|
lineNumbers: true,
|
|
|
|
autofocus: true
|
|
|
|
});
|
2012-11-21 07:10:42 +00:00
|
|
|
$('.CodeMirror').css({'width':950, 'margin':'35px auto', 'box-shadow':'0 0 6px #272822'});
|
|
|
|
$('.CodeMirror-scroll').css({'min-height':480});
|
2012-11-20 08:28:33 +00:00
|
|
|
{% endif %}
|
2012-11-21 07:10:42 +00:00
|
|
|
$('#op-after-edit').removeClass('hide');
|
2012-08-22 06:41:36 +00:00
|
|
|
|
2012-09-13 08:36:23 +00:00
|
|
|
{% if filetype == 'Markdown' %}
|
|
|
|
$('#source-code-btn').click(function() {
|
|
|
|
$('#md-view, #source-code-btn').addClass('hide');
|
|
|
|
$('.CodeMirror, #preview-btn').removeClass('hide');
|
|
|
|
editor.focus();
|
2012-08-22 04:07:51 +00:00
|
|
|
});
|
2012-09-13 08:36:23 +00:00
|
|
|
$('#preview-btn').click(function() {
|
|
|
|
var content = editor.getValue();
|
2012-08-22 04:07:51 +00:00
|
|
|
var converter = new Showdown.converter();
|
2012-09-13 08:36:23 +00:00
|
|
|
$('.CodeMirror, #preview-btn').addClass('hide');
|
2012-08-22 04:07:51 +00:00
|
|
|
$('#md-view').html(converter.makeHtml(content)).removeClass('hide');
|
2012-08-22 06:41:36 +00:00
|
|
|
$('#md-view').children(':first').css('margin-top', '0');
|
2012-09-13 08:36:23 +00:00
|
|
|
$('#source-code-btn').removeClass('hide');
|
2012-08-22 04:07:51 +00:00
|
|
|
});
|
|
|
|
{% endif %}
|
2012-08-22 06:41:36 +00:00
|
|
|
|
2012-08-18 07:34:38 +00:00
|
|
|
$('#file-edit-submit').click(function () {
|
2012-11-23 03:29:02 +00:00
|
|
|
var submit_btn = $(this);
|
|
|
|
disable(submit_btn);
|
2012-11-20 08:28:33 +00:00
|
|
|
{% if filetype == 'Sf' %}
|
|
|
|
var content = $('#sf').html();
|
|
|
|
{% else %}
|
|
|
|
var content = editor.getValue();
|
|
|
|
{% endif %}
|
|
|
|
|
2012-08-08 10:35:48 +00:00
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
2012-11-04 05:06:30 +00:00
|
|
|
url: '{{ SITE_ROOT }}repo/{{repo.id}}/file/edit/?p={{path|urlencode}}&head={{head_id}}',
|
2012-08-08 10:35:48 +00:00
|
|
|
dataType: 'json',
|
|
|
|
cache: false,
|
|
|
|
contentType: 'application/json; charset=utf-8',
|
|
|
|
beforeSend: prepareCSRFToken,
|
2012-11-20 08:28:33 +00:00
|
|
|
data: {content: content, encoding: '{{ encoding }}'},
|
2012-08-08 10:35:48 +00:00
|
|
|
success: function(data) {
|
2012-08-18 07:34:38 +00:00
|
|
|
location.href = $('#file-edit-cancel').attr('data');
|
2012-08-08 10:35:48 +00:00
|
|
|
},
|
|
|
|
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-11-23 03:29:02 +00:00
|
|
|
enable(submit_btn);
|
2012-08-08 10:35:48 +00:00
|
|
|
}
|
|
|
|
});
|
2012-08-06 12:29:14 +00:00
|
|
|
});
|
2012-08-18 07:34:38 +00:00
|
|
|
$('#file-edit-cancel').click(function() {
|
|
|
|
location.href = $(this).attr('data');
|
|
|
|
});
|
2012-08-11 06:07:12 +00:00
|
|
|
{% endifnotequal %}
|
2012-08-09 07:28:22 +00:00
|
|
|
|
|
|
|
{% if err %}
|
2012-11-23 03:29:02 +00:00
|
|
|
$('#file-edit').html('<div id="sf" class="article"><p class="error">{{ err }}</p></div>');
|
2012-08-09 07:28:22 +00:00
|
|
|
{% endif %}
|
2012-08-06 12:29:14 +00:00
|
|
|
</script>
|
|
|
|
{% endblock %}
|