2012-08-06 20:29:14 +08:00
|
|
|
{% extends base_template %}
|
2012-11-04 13:29:20 +08:00
|
|
|
{% load seahub_tags i18n %}
|
2012-08-06 20:29:14 +08:00
|
|
|
|
2012-09-13 16:36:23 +08:00
|
|
|
{% block extra_style %}
|
2012-11-20 16:28:33 +08:00
|
|
|
{% if filetype == 'Sf' %}
|
|
|
|
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}aloha-0.22.3/css/aloha.css" />
|
|
|
|
{% else %}
|
2012-09-13 16:36:23 +08: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 15:49:12 +08:00
|
|
|
.CodeMirror-scroll {
|
|
|
|
height:auto;
|
2012-12-03 11:34:32 +08:00
|
|
|
min-height:700px;
|
2012-10-15 15:49:12 +08:00
|
|
|
}
|
2012-09-13 16:36:23 +08:00
|
|
|
</style>
|
|
|
|
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}codemirror/monokai.css" />
|
2012-11-20 16:28:33 +08:00
|
|
|
{% endif %}
|
2012-11-27 15:47:08 +08:00
|
|
|
<style type="text/css">
|
|
|
|
#main {
|
|
|
|
width:100%;
|
|
|
|
}
|
|
|
|
#footer {
|
|
|
|
display:none;
|
|
|
|
}
|
|
|
|
#edit-hd, #path-op {
|
|
|
|
width:950px;
|
|
|
|
margin:0 auto;
|
|
|
|
}
|
|
|
|
#path-op {
|
|
|
|
padding-bottom:6px;
|
|
|
|
}
|
|
|
|
#path-op .path {
|
|
|
|
margin-top:1.2em
|
|
|
|
}
|
|
|
|
#file-edit {
|
2012-12-03 11:34:32 +08:00
|
|
|
min-height:700px;
|
|
|
|
padding:30px 0 60px;
|
2012-11-27 15:47:08 +08:00
|
|
|
background:#f4f4f4;
|
|
|
|
border-top:1px solid #ededed;
|
|
|
|
}
|
2012-11-28 15:24:11 +08:00
|
|
|
#sf, #md-view {
|
2012-11-27 15:47:08 +08:00
|
|
|
box-shadow:0 0 6px #ccc;
|
2012-12-03 11:34:32 +08:00
|
|
|
min-height:620px;
|
2012-11-27 15:47:08 +08:00
|
|
|
border:1px solid #ccc;
|
|
|
|
margin:0 auto;
|
|
|
|
}
|
|
|
|
.fixed-path-op {
|
|
|
|
position:fixed;
|
|
|
|
background:#fff;
|
|
|
|
border-bottom:1px solid #ededed;/*for ie*/
|
|
|
|
box-shadow:0 1px 3px #777;
|
|
|
|
z-index:1010;/*make seaf image show below path-op*/
|
|
|
|
}
|
|
|
|
.CodeMirror {
|
2012-12-03 11:34:32 +08:00
|
|
|
{% if filetype == 'Markdown' or fileext == 'txt' or fileext == 'text' %}
|
2012-11-28 15:24:11 +08:00
|
|
|
width:818px;
|
|
|
|
{% else %}
|
2012-11-27 15:47:08 +08:00
|
|
|
width:950px;
|
2012-11-28 15:24:11 +08:00
|
|
|
{% endif %}
|
2012-11-27 15:47:08 +08:00
|
|
|
margin:0 auto;
|
|
|
|
box-shadow:0 0 6px #272822;
|
|
|
|
}
|
|
|
|
</style>
|
2012-09-13 16:36:23 +08:00
|
|
|
{% endblock %}
|
|
|
|
|
2012-08-06 20:29:14 +08:00
|
|
|
{% block main_panel %}
|
2012-11-27 15:47:08 +08:00
|
|
|
<h2 id="edit-hd">{% trans "Edit" %} <span class="op-target">{{ u_filename }}</span></h2>
|
2012-11-21 15:10:42 +08:00
|
|
|
<div id="path-op" class="ovhd">
|
2012-11-20 16:28:33 +08:00
|
|
|
<p class="path fleft">
|
2012-11-04 13:29:20 +08:00
|
|
|
{% trans "Current path: " %}
|
2012-08-06 20:29:14 +08: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 17:24:15 +08:00
|
|
|
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/files/?p={{ path }}">{{ name }}</a>
|
2012-08-06 20:29:14 +08:00
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
2012-12-03 11:34:32 +08:00
|
|
|
</p>
|
|
|
|
<div id="op-after-edit" class="fright hide">
|
|
|
|
{% if filetype == 'Markdown' %}
|
|
|
|
<button id="source-code-btn" class="hide">{% trans "Continue editing" %}</button>
|
|
|
|
<button id="preview-btn">{% trans "Preview" %}</button>
|
|
|
|
{% endif %}
|
|
|
|
<button id="file-edit-submit">{% trans "Submit" %}</button>
|
|
|
|
<a href="{{ SITE_ROOT }}repo/{{ repo.id }}/files/?p={{ path }}" id="file-edit-cancel">{% trans "Cancel" %}</a>
|
|
|
|
</div>
|
2012-11-20 16:28:33 +08:00
|
|
|
</div>
|
2012-11-21 15:10:42 +08:00
|
|
|
<div id="file-edit">
|
2012-09-13 16:36:23 +08:00
|
|
|
{% ifnotequal file_content None %}
|
2012-11-20 16:28:33 +08:00
|
|
|
{% ifnotequal filetype 'Sf' %}
|
2012-09-13 16:36:23 +08:00
|
|
|
<textarea id="docu-view" class="hide">{{ file_content|escape }}</textarea>
|
2012-11-20 16:28:33 +08:00
|
|
|
{% else %}
|
|
|
|
<div id="sf" class="article">{{ file_content|safe }}</div>
|
|
|
|
{% endifnotequal %}
|
2012-09-13 16:36:23 +08:00
|
|
|
{% endifnotequal %}
|
|
|
|
{% if filetype == 'Markdown' %}
|
2012-08-22 14:41:36 +08:00
|
|
|
<div id="md-view" class="article hide"></div>
|
2012-08-22 12:07:51 +08:00
|
|
|
{% endif %}
|
2012-08-06 20:29:14 +08:00
|
|
|
</div>
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% block extra_script %}
|
2012-11-20 16:28:33 +08: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 19:38:31 +08: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 16:28:33 +08:00
|
|
|
{% else %}
|
2012-12-11 15:14:55 +08:00
|
|
|
<script type="text/javascript" src="{{MEDIA_URL}}codemirror/codemirror-2.36.js"></script>
|
2012-11-20 16:28:33 +08:00
|
|
|
{% endif %}
|
2012-09-13 16:36:23 +08:00
|
|
|
{% if filetype == 'Markdown' %}
|
2012-08-22 12:07:51 +08:00
|
|
|
<script type="text/javascript" src="{{MEDIA_URL}}js/showdown.js"></script>
|
2012-08-08 11:12:40 +08:00
|
|
|
{% endif %}
|
2012-08-06 20:29:14 +08:00
|
|
|
<script type="text/javascript">
|
2012-08-11 14:07:12 +08:00
|
|
|
{% ifnotequal file_content None %}
|
2012-11-27 15:47:08 +08:00
|
|
|
$(window).scroll(function() {
|
|
|
|
var offset = $('#edit-hd').offset();
|
|
|
|
if ($(window).scrollTop() > offset.top + $('#edit-hd').height()) {
|
|
|
|
$('#path-op').addClass('fixed-path-op').css({'left':0, 'top':0, 'padding-left':offset.left, 'padding-right':offset.left});
|
2012-12-03 11:34:32 +08:00
|
|
|
$('#edit-hd').css('margin-bottom', $('#path-op').outerHeight());
|
2012-11-27 15:47:08 +08:00
|
|
|
} else {
|
2012-12-03 11:34:32 +08:00
|
|
|
$('#path-op').removeClass('fixed-path-op').removeAttr('style');
|
|
|
|
$('#edit-hd').css('margin-bottom', 0);
|
2012-11-27 15:47:08 +08:00
|
|
|
}
|
|
|
|
});
|
2012-11-21 15:10:42 +08:00
|
|
|
{% if filetype == 'Sf' %}
|
2012-11-27 15:47:08 +08:00
|
|
|
Aloha.ready(function() {
|
|
|
|
if ($.browser.msie) {
|
|
|
|
$('#sf').aloha();
|
|
|
|
} else {
|
|
|
|
$('#sf').aloha().focus();
|
|
|
|
}
|
|
|
|
});
|
2012-11-20 16:28:33 +08:00
|
|
|
{% else %}
|
2012-09-13 16:36:23 +08: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,
|
2012-12-03 11:34:32 +08:00
|
|
|
lineWrapping: true,
|
|
|
|
onCursorActivity: function() {
|
|
|
|
var cursor = editor.cursorCoords(true, 'page');
|
|
|
|
if (cursor.yBot >= $(window).height() + $(window).scrollTop() - 60) {
|
|
|
|
$(window).scrollTop($(window).scrollTop() + parseInt($('#file-edit').css('padding-bottom')));
|
|
|
|
}
|
|
|
|
},
|
2012-09-13 16:36:23 +08:00
|
|
|
autofocus: true
|
|
|
|
});
|
2012-11-20 16:28:33 +08:00
|
|
|
{% endif %}
|
2012-11-21 15:10:42 +08:00
|
|
|
$('#op-after-edit').removeClass('hide');
|
2012-08-22 14:41:36 +08:00
|
|
|
|
2012-09-13 16:36:23 +08: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 12:07:51 +08:00
|
|
|
});
|
2012-09-13 16:36:23 +08:00
|
|
|
$('#preview-btn').click(function() {
|
|
|
|
var content = editor.getValue();
|
2012-08-22 12:07:51 +08:00
|
|
|
var converter = new Showdown.converter();
|
2012-09-13 16:36:23 +08:00
|
|
|
$('.CodeMirror, #preview-btn').addClass('hide');
|
2012-08-22 12:07:51 +08:00
|
|
|
$('#md-view').html(converter.makeHtml(content)).removeClass('hide');
|
2012-08-22 14:41:36 +08:00
|
|
|
$('#md-view').children(':first').css('margin-top', '0');
|
2012-09-13 16:36:23 +08:00
|
|
|
$('#source-code-btn').removeClass('hide');
|
2012-08-22 12:07:51 +08:00
|
|
|
});
|
|
|
|
{% endif %}
|
2012-08-22 14:41:36 +08:00
|
|
|
|
2012-08-18 15:34:38 +08:00
|
|
|
$('#file-edit-submit').click(function () {
|
2012-11-23 11:29:02 +08:00
|
|
|
var submit_btn = $(this);
|
|
|
|
disable(submit_btn);
|
2012-11-20 16:28:33 +08:00
|
|
|
{% if filetype == 'Sf' %}
|
|
|
|
var content = $('#sf').html();
|
|
|
|
{% else %}
|
|
|
|
var content = editor.getValue();
|
|
|
|
{% endif %}
|
|
|
|
|
2012-08-08 18:35:48 +08:00
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
2012-11-04 13:06:30 +08:00
|
|
|
url: '{{ SITE_ROOT }}repo/{{repo.id}}/file/edit/?p={{path|urlencode}}&head={{head_id}}',
|
2012-08-08 18:35:48 +08:00
|
|
|
dataType: 'json',
|
|
|
|
cache: false,
|
|
|
|
contentType: 'application/json; charset=utf-8',
|
|
|
|
beforeSend: prepareCSRFToken,
|
2012-11-20 16:28:33 +08:00
|
|
|
data: {content: content, encoding: '{{ encoding }}'},
|
2012-08-08 18:35:48 +08:00
|
|
|
success: function(data) {
|
2012-11-27 15:47:08 +08:00
|
|
|
location.href = $('#file-edit-cancel').attr('href');
|
2012-08-08 18:35:48 +08:00
|
|
|
},
|
|
|
|
error: function(xhr, ajaxOptions, thrownError) {
|
|
|
|
var jsonVal = jQuery.parseJSON(xhr.responseText);
|
2012-09-01 20:32:43 +08:00
|
|
|
$('#op-after-edit').prepend('<p class="error">' + jsonVal['error'] + '</p>');
|
2012-11-23 11:29:02 +08:00
|
|
|
enable(submit_btn);
|
2012-08-08 18:35:48 +08:00
|
|
|
}
|
|
|
|
});
|
2012-08-06 20:29:14 +08:00
|
|
|
});
|
2012-08-11 14:07:12 +08:00
|
|
|
{% endifnotequal %}
|
2012-08-09 15:28:22 +08:00
|
|
|
|
|
|
|
{% if err %}
|
2012-11-23 11:29:02 +08:00
|
|
|
$('#file-edit').html('<div id="sf" class="article"><p class="error">{{ err }}</p></div>');
|
2012-08-09 15:28:22 +08:00
|
|
|
{% endif %}
|
2012-08-06 20:29:14 +08:00
|
|
|
</script>
|
|
|
|
{% endblock %}
|