* 保存文档到服务器 * @param $is_cover 是否强制覆盖
($is_cover,callback)
| 102 | * @param $is_cover 是否强制覆盖 |
| 103 | */ |
| 104 | function saveDocument($is_cover,callback) { |
| 105 | var index = null; |
| 106 | var node = window.selectNode; |
| 107 | |
| 108 | var html = window.editor.$txt.html() ; |
| 109 | |
| 110 | var content = ""; |
| 111 | if($.trim(html) !== ""){ |
| 112 | content = toMarkdown(html, { gfm: true }); |
| 113 | } |
| 114 | var version = ""; |
| 115 | |
| 116 | if(!node){ |
| 117 | layer.msg("获取当前文档信息失败"); |
| 118 | return; |
| 119 | } |
| 120 | var doc_id = parseInt(node.id); |
| 121 | |
| 122 | for(var i in window.documentCategory){ |
| 123 | var item = window.documentCategory[i]; |
| 124 | |
| 125 | if(item.id === doc_id){ |
| 126 | version = item.version; |
| 127 | break; |
| 128 | } |
| 129 | } |
| 130 | $.ajax({ |
| 131 | beforeSend : function () { |
| 132 | index = layer.load(1, {shade: [0.1,'#fff'] }); |
| 133 | }, |
| 134 | url : window.editURL, |
| 135 | data : {"identify" : window.book.identify,"doc_id" : doc_id,"markdown" : content,"html" : html,"cover" : $is_cover ? "yes":"no","version": version}, |
| 136 | type :"post", |
| 137 | dataType :"json", |
| 138 | success : function (res) { |
| 139 | layer.close(index); |
| 140 | if(res.errcode === 0){ |
| 141 | for(var i in window.documentCategory){ |
| 142 | var item = window.documentCategory[i]; |
| 143 | |
| 144 | if(item.id === doc_id){ |
| 145 | window.documentCategory[i].version = res.data.version; |
| 146 | break; |
| 147 | } |
| 148 | } |
| 149 | // 更新内容备份 |
| 150 | window.source = res.data.content; |
| 151 | // 触发编辑器 onchange 回调函数 |
| 152 | window.editor.onchange(); |
| 153 | if(typeof callback === "function"){ |
| 154 | callback(); |
| 155 | } |
| 156 | }else if(res.errcode === 6005){ |
| 157 | var confirmIndex = layer.confirm('文档已被其他人修改确定覆盖已存在的文档吗?', { |
| 158 | btn: ['确定','取消'] //按钮 |
| 159 | }, function(){ |
| 160 | layer.close(confirmIndex); |
| 161 | saveDocument(true,callback); |
no test coverage detected