refactor and update i18n, to be continue

pull/680/head
shiqstone 2021-04-15 19:25:02 +08:00
parent cbe47213d7
commit 78e35ad8a9
3 changed files with 106 additions and 43 deletions

View File

@ -4,12 +4,63 @@ $(function () {
css : window.katex.css
};
window.editormdLocales = {
'zh-CN': {
placeholder: ' Markdown ',
contentUnsaved: '',
noDocNeedPublish: '',
loadDocFailed: '',
fetchDocFailed: '',
cannotAddToEmptyNode: '',
overrideModified: '',
confirm: '',
cancel: '',
contentsNameEmpty: '',
addDoc: '',
edit: '',
delete: '',
loadFailed: '',
tplNameEmpty: '',
tplContentEmpty: '',
saveSucc: '',
serverExcept: '',
paramName: '',
paramType: '',
example: '',
remark: '',
},
'en': {
placeholder: 'This editor supports Markdown editing, writing on the left and previewing on the right.',
contentUnsaved: 'The edited content is not saved, need to save it?',
noDocNeedPublish: 'No Document need to be publish',
loadDocFailed: 'Load Document failed',
fetchDocFailed: 'Fetch Document info failed',
cannotAddToEmptyNode: 'Cannot add content to empty node',
overrideModified: 'The document has been modified by someone else, are you sure to overwrite the document?',
confirm: 'Confirm',
cancel: 'Cancel',
contentsNameEmpty: 'Document Name cannot be empty',
addDoc: 'Add Document',
edit: 'Edit',
delete: 'Delete',
loadFailed: 'Failed to load, please try again',
tplNameEmpty: 'Template name cannot be empty',
tplContentEmpty: 'Template content cannot be empty',
saveSucc: 'Save success',
serverExcept: 'Server Exception',
paramName: 'Parameter',
paramType: 'Type',
example: 'Example',
remark: 'Remark',
}
};
window.editor = editormd("docEditor", {
width: "100%",
height: "100%",
path: window.editormdLib,
toolbar: true,
placeholder: "本编辑器支持 Markdown 编辑,左边编写,右边预览。",
placeholder: window.editormdLocales[window.lang].placeholder,
imageUpload: true,
imageFormats: ["jpg", "jpeg", "gif", "png","svg", "JPG", "JPEG", "GIF", "PNG","SVG"],
imageUploadURL: window.imageUploadURL,
@ -57,6 +108,7 @@ $(function () {
}
}
});
window.isLoad = true;
},
onchange: function () {
@ -110,7 +162,7 @@ $(function () {
} else if (name === "release") {
if (Object.prototype.toString.call(window.documentCategory) === '[object Array]' && window.documentCategory.length > 0) {
if ($("#markdown-save").hasClass('change')) {
var confirm_result = confirm("编辑内容未保存,需要保存吗?");
var confirm_result = confirm(editormdLocales[lang].contentUnsaved);
if (confirm_result) {
saveDocument(false, releaseBook);
return;
@ -119,7 +171,7 @@ $(function () {
releaseBook();
} else {
layer.msg("没有需要发布的文档")
layer.msg(editormdLocales[lang].noDocNeedPublish)
}
} else if (name === "tasks") {
// 插入 GFM 任务列表
@ -175,11 +227,11 @@ $(function () {
pushVueLists(res.data.attach);
setLastSelectNode($node);
} else {
layer.msg("文档加载失败");
layer.msg(editormdLocales[lang].loadDocFailed);
}
}).fail(function () {
layer.close(index);
layer.msg("文档加载失败");
layer.msg(editormdLocales[lang].loadDocFailed);
});
};
@ -195,11 +247,11 @@ $(function () {
var version = "";
if (!node) {
layer.msg("获取当前文档信息失败");
layer.msg(editormdLocales[lang].fetchDocFailed);
return;
}
if (node.a_attr && node.a_attr.disabled) {
layer.msg("空节点不能添加内容");
layer.msg(editormdLocales[lang].cannotAddToEmptyNode);
return;
}
@ -246,8 +298,8 @@ $(function () {
}
} else if(res.errcode === 6005) {
var confirmIndex = layer.confirm('', {
btn: ['', ''] // 按钮
var confirmIndex = layer.confirm(editormdLocales[lang].overrideModified, {
btn: [editormdLocales[lang].confirm, editormdLocales[lang].cancel] // 按钮
}, function() {
layer.close(confirmIndex);
saveDocument(true, callback);
@ -257,7 +309,7 @@ $(function () {
}
},
error : function (XMLHttpRequest, textStatus, errorThrown) {
layer.msg("服务器错误:" + errorThrown);
layer.msg(window.editormdLocales[window.lang].serverExcept + errorThrown);
},
complete :function () {
layer.close(index);
@ -287,7 +339,7 @@ $(function () {
beforeSubmit: function () {
var doc_name = $.trim($("#documentName").val());
if (doc_name === "") {
return showError("目录名称不能为空", "#add-error-message")
return showError(editormdLocales[lang].contentsNameEmpty, "#add-error-message")
}
$("#btnSaveDocument").button("loading");
return true;
@ -347,7 +399,7 @@ $(function () {
"separator_before": false,
"separator_after": true,
"_disabled": false,
"label": "添加文档",
"label": window.editormdLocales[window.lang].addDoc,//"添加文档",
"icon": "fa fa-plus",
"action": function (data) {
var inst = $.jstree.reference(data.reference),
@ -360,7 +412,7 @@ $(function () {
"separator_before": false,
"separator_after": true,
"_disabled": false,
"label": "编辑",
"label": window.editormdLocales[window.lang].edit,
"icon": "fa fa-edit",
"action": function (data) {
var inst = $.jstree.reference(data.reference);
@ -372,7 +424,7 @@ $(function () {
"separator_before": false,
"separator_after": true,
"_disabled": false,
"label": "删除",
"label": window.editormdLocales[window.lang].delete,
"icon": "fa fa-trash-o",
"action": function (data) {
var inst = $.jstree.reference(data.reference);
@ -390,7 +442,7 @@ $(function () {
}).on('select_node.jstree', function (node, selected) {
if ($("#markdown-save").hasClass('change')) {
if (confirm("编辑内容未保存,需要保存吗?")) {
if (confirm(window.editormdLocales[window.lang].contentUnsaved)) {
saveDocument(false, function () {
loadDocument(selected);
});
@ -446,7 +498,7 @@ $(function () {
$("#displayCustomsTemplateList").html($res);
},
error : function () {
layer.msg("加载失败请重试");
layer.msg(window.editormdLocales[window.lang].loadFailed);
},
complete : function () {
layer.close(index);
@ -464,11 +516,11 @@ $(function () {
beforeSubmit: function () {
var doc_name = $.trim($("#templateName").val());
if (doc_name === "") {
return showError("模板名称不能为空", "#saveTemplateForm .show-error-message");
return showError(window.editormdLocales[window.lang].tplNameEmpty, "#saveTemplateForm .show-error-message");
}
var content = $("#saveTemplateForm").find("input[name='content']").val();
if (content === ""){
return showError("模板内容不能为空", "#saveTemplateForm .show-error-message");
return showError(window.editormdLocales[window.lang].tplContentEmpty, "#saveTemplateForm .show-error-message");
}
$("#btnSaveTemplate").button("loading");
@ -478,7 +530,7 @@ $(function () {
success: function ($res) {
if($res.errcode === 0){
$("#saveTemplateModal").modal("hide");
layer.msg("保存成功");
layer.msg(window.editormdLocales[window.lang].saveSucc);
}else{
return showError($res.message, "#saveTemplateForm .show-error-message");
}
@ -521,7 +573,7 @@ $(function () {
resetEditorChanged(true);
$("#displayCustomsTemplateModal").modal("hide");
},error : function () {
layer.msg("服务器异常");
layer.msg(window.editormdLocales[window.lang].serverExcept);
}
});
}).on("click",".btn-delete",function () {
@ -541,7 +593,7 @@ $(function () {
$then.parents("tr").empty().remove();
}
},error : function () {
layer.msg("服务器异常");
layer.msg(window.editormdLocales[window.lang].serverExcept);
},
complete: function () {
$then.button("reset");
@ -555,7 +607,11 @@ $(function () {
try {
var jsonObj = $.parseJSON(content);
var data = foreachJson(jsonObj,"");
var table = "| 参数名称 | 参数类型 | 示例值 | 备注 |\n| ------------ | ------------ | ------------ | ------------ |\n";
var table = "| " + window.editormdLocales[window.lang].paramName
+ " | " + window.editormdLocales[window.lang].paramType
+ " | " + window.editormdLocales[window.lang].example
+ " | " + window.editormdLocales[window.lang].remark
+ " |\n| ------------ | ------------ | ------------ | ------------ |\n";
$.each(data,function (i,item) {
table += "|" + item.key + "|" + item.type + "|" + item.value +"| |\n";
});

View File

@ -26,6 +26,7 @@
window.removeAttachURL = "{{urlfor "DocumentController.RemoveAttachment"}}";
window.highlightStyle = "{{.HighlightStyle}}";
window.template = { "getUrl":"{{urlfor "TemplateController.Get"}}", "listUrl" : "{{urlfor "TemplateController.List"}}", "deleteUrl" : "{{urlfor "TemplateController.Delete"}}", "saveUrl" :"{{urlfor "TemplateController.Add"}}"}
window.lang = {{i18n $.Lang "common.js_lang"}};
</script>
<!-- Bootstrap -->
<link href="{{cdncss "/static/bootstrap/css/bootstrap.min.css"}}" rel="stylesheet">
@ -90,7 +91,7 @@
<a href="javascript:;" data-toggle="tooltip" data-title="{{i18n .Lang "doc.ref_link"}}"><i class="fa fa-anchor item" name="reference-link" unselectable="on"></i></a>
<a href="javascript:;" data-toggle="tooltip" data-title="{{i18n .Lang "doc.add_pic"}}"><i class="fa fa-picture-o item" name="image" unselectable="on"></i></a>
<a href="javascript:;" data-toggle="tooltip" data-title="{{i18n .Lang "doc.code"}}"><i class="fa fa-code item" name="code" unselectable="on"></i></a>
<a href="javascript:;" data-toggle="tooltip" data-title="{{i18n .Lang "doc.code_blck"}}" unselectable="on"><i class="fa fa-file-code-o item" name="code-block" unselectable="on"></i></a>
<a href="javascript:;" data-toggle="tooltip" data-title="{{i18n .Lang "doc.code_block"}}" unselectable="on"><i class="fa fa-file-code-o item" name="code-block" unselectable="on"></i></a>
<a href="javascript:;" data-toggle="tooltip" data-title="{{i18n .Lang "doc.table"}}"><i class="fa fa-table item" name="table" unselectable="on"></i></a>
<a href="javascript:;" data-toggle="tooltip" data-title="{{i18n .Lang "doc.quote"}}"><i class="fa fa-quote-right item" name="quote" unselectable="on"></i></a>
<a href="javascript:;" data-toggle="tooltip" data-title="{{i18n .Lang "doc.gfm_task"}}"><i class="fa fa-tasks item" name="tasks" aria-hidden="true"></i></a>
@ -122,7 +123,7 @@
<div class="manual-category" id="manualCategory" style="position:absolute;">
<div class="manual-nav">
<div class="nav-item active"><i class="fa fa-bars" aria-hidden="true"></i> {{i18n .Lang "doc.document"}}</div>
<div class="nav-plus pull-right" id="btnAddDocument" data-toggle="tooltip" data-title="{{i18n .Lang "doc.create_document"}}" data-direction="right"><i class="fa fa-plus" aria-hidden="true"></i></div>
<div class="nav-plus pull-right" id="btnAddDocument" data-toggle="tooltip" data-title="{{i18n .Lang "doc.create_doc"}}" data-direction="right"><i class="fa fa-plus" aria-hidden="true"></i></div>
<div class="clearfix"></div>
</div>
<div class="manual-tree" id="sidebar"> </div>
@ -148,14 +149,14 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">{{i18n .Lang "doc.create_document"}}</h4>
<h4 class="modal-title" id="myModalLabel">{{i18n .Lang "doc.create_doc"}}</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="col-sm-2 control-label">{{i18n .Lang "doc.doc_name"}} <span class="error-message">*</span></label>
<div class="col-sm-10">
<input type="text" name="doc_name" id="documentName" placeholder="{{i18n .Lang "doc.doc_name"}}" class="form-control" maxlength="50">
<p style="color: #999;font-size: 12px;">{{i18n .Lang "doc.doc_name_desc"}}</p>
<p style="color: #999;font-size: 12px;">{{i18n .Lang "doc.doc_name_tips"}}</p>
</div>
</div>
@ -163,7 +164,7 @@
<label class="col-sm-2 control-label">{{i18n .Lang "doc.doc_id"}} <span class="error-message">&nbsp;</span></label>
<div class="col-sm-10">
<input type="text" name="doc_identify" id="documentIdentify" placeholder="{{i18n .Lang "doc.doc_id"}}" class="form-control" maxlength="50">
<p style="color: #999;font-size: 12px;">{{i18n .Lang "doc.doc_id_desc"}}</p>
<p style="color: #999;font-size: 12px;">{{i18n .Lang "doc.doc_id_tips"}}</p>
</div>
</div>
@ -304,7 +305,6 @@
<h3><a data-type="customs" href="javascript:;">{{i18n .Lang "doc.custom_tpl"}}</a></h3>
<ul>
<li>{{i18n .Lang "doc.custom_tpl"}}</li>
<li>{{i18n .Lang "doc.any_type_doc"}}</li>
<li>{{i18n .Lang "doc.as_global_tpl"}}</li>
</ul>
@ -332,11 +332,11 @@
<thead>
<tr>
<td>#</td>
<td class="col-sm-3">{{i18n .Lang "doc.tpl_name"}}</td>
<td class="col-sm-2">{{i18n .Lang "doc.tpl_type"}}</td>
<td class="col-sm-2">{{i18n .Lang "doc.creator"}}</td>
<td class="col-sm-3">{{i18n .Lang "doc.create_time"}}</td>
<td class="col-sm-2">{{i18n .Lang "doc.operation"}}</td>
<td class="col-sm-3">{{i18n $.Lang "doc.tpl_name"}}</td>
<td class="col-sm-2">{{i18n $.Lang "doc.tpl_type"}}</td>
<td class="col-sm-2">{{i18n $.Lang "doc.creator"}}</td>
<td class="col-sm-3">{{i18n $.Lang "doc.create_time"}}</td>
<td class="col-sm-2">{{i18n $.Lang "doc.operation"}}</td>
</tr>
</thead>
<tbody>
@ -442,7 +442,14 @@
<script src="{{cdnjs "/static/js/markdown.js" "version"}}" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
lang = {{i18n $.Lang "common.js_lang"}};
editLangPath = {{cdnjs "/static/editor.md/languages/"}} + lang
if(lang != 'zh-CN') {
editormd.loadScript(editLangPath, function(){
window.editor.lang = editormd.defaults.lang;
window.editor.recreate()
});
}
$("#attachInfo").on("click",function () {
$("#uploadAttachModal").modal("show");
});

View File

@ -3,11 +3,11 @@
<thead>
<tr>
<td>#</td>
<td class="col-sm-3">模板名称</td>
<td class="col-sm-2">模板类型</td>
<td class="col-sm-2">创建人</td>
<td class="col-sm-3">创建时间</td>
<td class="col-sm-2">操作</td>
<td class="col-sm-3">{{i18n $.Lang "doc.tpl_name"}}</td>
<td class="col-sm-2">{{i18n $.Lang "doc.tpl_type"}}</td>
<td class="col-sm-2">{{i18n $.Lang "doc.creator"}}</td>
<td class="col-sm-3">{{i18n $.Lang "doc.create_time"}}</td>
<td class="col-sm-2">{{i18n $.Lang "doc.operation"}}</td>
</tr>
</thead>
<tbody>
@ -20,21 +20,21 @@
<tr>
<td>{{$item.TemplateId}}</td>
<td>{{$item.TemplateName}}</td>
<td>{{if $item.IsGlobal}}全局{{else}}项目{{end}}</td>
<td>{{if $item.IsGlobal}}{{i18n .Lang "doc.global_tpl"}}{{else}}{{i18n .Lang "doc.project_tpl"}}{{end}}</td>
<td>{{$item.CreateName}}</td>
<td>{{date_format $item.CreateTime "2006-01-02 15:04:05"}}</td>
<td>
<button class="btn btn-primary btn-sm btn-insert" data-id="{{$item.TemplateId}}">
插入
{{i18n .Lang "doc.insert"}}
</button>
<button class="btn btn-danger btn-sm btn-delete" data-id="{{$item.TemplateId}}" data-loading-text="删除中...">
删除
{{i18n .Lang "doc.delete"}}
</button>
</td>
</tr>
{{else}}
<tr>
<td colspan="6" class="text-center">暂无数据</td>
<td colspan="6" class="text-center">{{i18n .Lang "message.no_data"}}</td>
</tr>
{{end}}
{{end}}