editor.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /**
  2. * Created by lifei6671 on 2017/4/29 0029.
  3. */
  4. /**
  5. * 保存排序
  6. * @param node
  7. * @param parent
  8. */
  9. function jstree_save(node, parent) {
  10. var parentNode = window.treeCatalog.get_node(parent.parent);
  11. var nodeData = window.getSiblingSort(parentNode);
  12. if (parent.parent !== parent.old_parent) {
  13. parentNode = window.treeCatalog.get_node(parent.old_parent);
  14. var newNodeData = window.getSiblingSort(parentNode);
  15. if (newNodeData.length > 0) {
  16. nodeData = nodeData.concat(newNodeData);
  17. }
  18. }
  19. var index = layer.load(1, {
  20. shade: [0.1, '#fff'] //0.1透明度的白色背景
  21. });
  22. console.log(JSON.stringify(nodeData));
  23. $.ajax({
  24. url : window.sortURL,
  25. type :"post",
  26. data : JSON.stringify(nodeData),
  27. success : function (res) {
  28. layer.close(index);
  29. if (res.errcode === 0){
  30. layer.msg("保存排序成功");
  31. }else{
  32. layer.msg(res.message);
  33. }
  34. }
  35. })
  36. }
  37. /**
  38. * 创建文档
  39. */
  40. function openCreateCatalogDialog($node) {
  41. var $then = $("#addDocumentModal");
  42. var doc_id = $node ? $node.id : 0;
  43. $then.find("input[name='parent_id']").val(doc_id);
  44. $then.modal("show");
  45. }
  46. /**
  47. * 处理排序
  48. * @param node
  49. * @returns {Array}
  50. */
  51. function getSiblingSort (node) {
  52. var data = [];
  53. for(var key in node.children){
  54. var index = data.length;
  55. data[index] = {
  56. "id" : parseInt(node.children[key]),
  57. "sort" : parseInt(key),
  58. "parent" : Number(node.id) ? Number(node.id) : 0
  59. };
  60. }
  61. return data;
  62. };
  63. /**
  64. * 删除一个文档
  65. * @param $node
  66. */
  67. function openDeleteDocumentDialog($node) {
  68. var index = layer.confirm('你确定要删除该文档吗?', {
  69. btn: ['确定','取消'] //按钮
  70. }, function(){
  71. $.post(window.deleteURL,{"identify" : window.book.identify,"doc_id" : $node.id}).done(function (res) {
  72. layer.close(index);
  73. if(res.errcode === 0){
  74. window.treeCatalog.delete_node($node);
  75. resetEditor($node);
  76. }else{
  77. layer.msg("删除失败",{icon : 2})
  78. }
  79. }).fail(function () {
  80. layer.close(index);
  81. layer.msg("删除失败",{icon : 2})
  82. });
  83. });
  84. }
  85. /**
  86. * 打开文档编辑界面
  87. * @param $node
  88. */
  89. function openEditCatalogDialog($node) {
  90. var $then = $("#addDocumentModal");
  91. var doc_id = parseInt($node ? $node.id : 0);
  92. var text = $node ? $node.text : '';
  93. var parentId = $node && $node.parent !== '#' ? $node.parent : 0;
  94. $then.find("input[name='doc_id']").val(doc_id);
  95. $then.find("input[name='parent_id']").val(parentId);
  96. $then.find("input[name='doc_name']").val(text);
  97. for (var index in window.documentCategory){
  98. var item = window.documentCategory[index];
  99. if(item.id === doc_id){
  100. $then.find("input[name='doc_identify']").val(item.identify);
  101. break;
  102. }
  103. }
  104. $then.modal({ show : true });
  105. }
  106. /**
  107. * 将一个节点推送到现有数组中
  108. * @param $node
  109. */
  110. function pushDocumentCategory($node) {
  111. for (var index in window.documentCategory){
  112. var item = window.documentCategory[index];
  113. if(item.id === $node.id){
  114. window.documentCategory[index] = $node;
  115. console.log( window.documentCategory[index]);
  116. return;
  117. }
  118. }
  119. window.documentCategory.push($node);
  120. }
  121. //实现小提示
  122. $("[data-toggle='tooltip']").hover(function () {
  123. var title = $(this).attr('data-title');
  124. var direction = $(this).attr("data-direction");
  125. var tips = 3;
  126. if(direction === "top"){
  127. tips = 1;
  128. }else if(direction === "right"){
  129. tips = 2;
  130. }else if(direction === "bottom"){
  131. tips = 3;
  132. }else if(direction === "left"){
  133. tips = 4;
  134. }
  135. index = layer.tips(title, this, {
  136. tips: tips
  137. });
  138. }, function () {
  139. layer.close(index);
  140. });
  141. //弹出创建文档的遮罩层
  142. $("#btnAddDocument").on("click",function () {
  143. $("#addDocumentModal").modal("show");
  144. });
  145. //用于还原创建文档的遮罩层
  146. $("#addDocumentModal").on("hidden.bs.modal",function () {
  147. $(this).find("form").html(window.addDocumentModalFormHtml);
  148. }).on("shown.bs.modal",function () {
  149. $(this).find("input[name='doc_name']").focus();
  150. });
  151. function showError($msg,$id) {
  152. if(!$id){
  153. $id = "#form-error-message"
  154. }
  155. $($id).addClass("error-message").removeClass("success-message").text($msg);
  156. return false;
  157. }
  158. function showSuccess($msg,$id) {
  159. if(!$id){
  160. $id = "#form-error-message"
  161. }
  162. $($id).addClass("success-message").removeClass("error-message").text($msg);
  163. return true;
  164. }