MCPcopy Index your code
hub / github.com/TruthHun/BookStack / saveDocument

Function saveDocument

static/js/markdown.js:263–327  ·  view source on GitHub ↗

* 保存文档到服务器 * @param $is_cover 是否强制覆盖

($is_cover,callback)

Source from the content-addressed store, hash-verified

261 * @param $is_cover 是否强制覆盖
262 */
263 function saveDocument($is_cover,callback) {
264 var index = null;
265 var node = window.selectNode;
266 var content = window.editor.getMarkdown();
267 var html = window.editor.getPreviewedHTML();
268 // var html = window.editor.getHTML();
269 var version = "";
270 var cm = window.editor.cm;
271
272 if(!node){
273 layer.msg("获取当前文档信息失败");
274 return;
275 }
276 var doc_id = parseInt(node.id);
277
278 for(var i in window.documentCategory){
279 var item = window.documentCategory[i];
280
281 if(item.id === doc_id){
282 version = item.version;
283 break;
284 }
285 }
286 $.ajax({
287 beforeSend : function () {
288 index = layer.load(1, {shade: [0.1,'#fff'] });
289 },
290 url : window.editURL,
291 data : {"identify" : window.book.identify,"doc_id" : doc_id,"markdown" : content,"html" : html,"cover" : $is_cover ? "yes":"no","version": version},
292 type :"post",
293 dataType :"json",
294 success : function (res) {
295 layer.close(index);
296 if(res.errcode === 0){
297 resetEditorChanged(false);
298 for(var i in window.documentCategory){
299 var item = window.documentCategory[i];
300
301 if(item.id === doc_id && res.data!=undefined && res.data.version!=undefined){
302 window.documentCategory[i].version = res.data.version;
303 break;
304 }
305 }
306 if(typeof callback === "function"){
307 callback();
308 }
309
310 if(res.message=="true"){//刷新页面显示最新的排序
311 location.href=location.origin+location.pathname+"?"+new Date();//刷新当前页面以获取新的排序
312 }else if(res.message=="auto"){
313 $(".jstree-wholerow-clicked").trigger("click");
314 }
315 }else if(res.errcode === 6005){
316 var confirmIndex = layer.confirm('文档已被其他人修改确定覆盖已存在的文档吗?', {
317 btn: ['确定','取消'] //按钮
318 }, function(){
319 layer.close(confirmIndex);
320 saveDocument(true,callback);

Callers 1

markdown.jsFile · 0.70

Calls 3

resetEditorChangedFunction · 0.85
callbackFunction · 0.50
$Function · 0.50

Tested by

no test coverage detected