MrDoc/template/app_doc/editor/create_doctemp.html

103 lines
4.2 KiB
HTML
Raw Normal View History

2020-11-29 14:03:39 +08:00
{% extends 'app_doc/editor/create_base_2.html' %}
2020-10-18 08:05:41 +08:00
{% load static %}
2020-12-02 21:25:59 +08:00
{% load i18n %}
{% block title %}新建文档模板{% endblock %}
{% block head_toolbar %}
<a class="btn pull-left" aria-label="" href="{% url 'create_doc' %}?pid={{project.id}}" target="_blank">
<i class="fa fa-plus-square"></i> <span class="layui-hide-xs">新建模板</span>
</a>
<a class="btn pull-left" aria-label="" href="{% url 'manage_doctemp' %}?pid={{project.id}}" target="_blank">
<i class="fa fa-cubes"></i> <span class="layui-hide-xs">管理模板</span>
</a>
<a class="btn pull-left" aria-label="" href="{% url 'manage_project' %}" target="_blank">
<i class="fa fa-cubes"></i> <span class="layui-hide-xs">管理文集</span>
</a>
{% endblock %}
{% block left_opera %}
2020-12-07 20:58:59 +08:00
{% include 'app_doc/editor/tpl_left_create_doctemp_custom.html' %}
{% endblock %}
{% block content %}
2019-07-21 23:00:55 +08:00
<div class="create-doc-form">
<div class="layui-form" style="padding-bottom:10px;">
<div class="layui-input-block" style="margin-left:0px;">
<input type="text" name="doc-name" id="doctemp-name" required lay-verify="required" placeholder="请输入模板标题" autocomplete="off" class="layui-input">
2019-07-21 23:00:55 +08:00
</div>
</div>
</div>
<div id="editor-md">
<textarea style="display:none;"></textarea>
<textarea class="editormd-html-textarea" name="$id-html-code"></textarea>
</div>
{% endblock %}
2019-07-21 22:08:04 +08:00
2019-07-21 23:00:55 +08:00
{% block custom_script %}
<script>
//保存文档模板
createDocTemp = function(){
$('button.layui-btn').attr("disabled",true);
$('button.layui-btn').addClass('layui-btn-disabled');
layer.load();
2019-07-21 23:00:55 +08:00
var data = {
'name':$("#doctemp-name").val(),
'content':editor.getMarkdown(),
}
$.post("{% url 'create_doctemp' %}",data,function(r){
if(r.status){
//创建成功
layer.closeAll("loading");
window.localStorage.removeItem('mrdoc_doc_cache') // 清空文档缓存
2019-07-21 23:00:55 +08:00
layer.msg('保存成功',function(){
md_changed = false;
window.location.href = "{% url 'manage_doctemp' %}";
2019-07-21 23:00:55 +08:00
});
}else{
//创建失败
layer.closeAll("loading");
2019-07-21 23:00:55 +08:00
layer.msg('保存失败');
$('button.layui-btn').attr("disabled",false);
$('button.layui-btn').removeClass('layui-btn-disabled');
2019-07-21 23:00:55 +08:00
}
});
};
// 查看本地文档缓存
$("#doc-cache-btn").click(function(){
var editor_cache = window.localStorage.getItem('mrdoc_doc_cache') // 获取文档缓存内容
if(editor_cache === null){
var editor_cache_cnt = 0
}else{
var editor_cache_cnt = editor_cache.replace(/\s+|[\r\n]/g,"").length
}
if(editor_cache_cnt > 5){ // 文档缓存去除空格换行后长度大于5
console.log("存在文档缓存")
$("#doc-cache-content").val(editor_cache)
layer.open({
title:"浏览器文档缓存",
type:1,
id:'doc-cache',
area:['500px','500px'],
content:$('#doc-cache-div'),
btn:['使用缓存',"删除缓存"],
success : function(index, layero) { // 成功弹出后回调
form.render();
},
yes:function(index, layero){
editor.setValue(editor_cache)
window.localStorage.removeItem('mrdoc_doc_cache')
layer.closeAll()
autoCacheDoc();
},
btn2:function(index,layero){
window.localStorage.removeItem('mrdoc_doc_cache')
layer.closeAll()
}
})
}else{
layer.msg("暂无本地缓存")
}
})
2019-07-21 23:00:55 +08:00
</script>
{% endblock %}