async_edit.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - async & edit</TITLE>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6. <link rel="stylesheet" href="../../../css/demo.css" type="text/css">
  7. <link rel="stylesheet" href="../../../css/zTreeStyle/zTreeStyle.css" type="text/css">
  8. <script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>
  9. <script type="text/javascript" src="../../../js/jquery.ztree.core.js"></script>
  10. <script type="text/javascript" src="../../../js/jquery.ztree.excheck.js"></script>
  11. <script type="text/javascript" src="../../../js/jquery.ztree.exedit.js"></script>
  12. <SCRIPT type="text/javascript">
  13. <!--
  14. var setting = {
  15. async: {
  16. enable: true,
  17. url:"../asyncData/getNodes.php",
  18. autoParam:["id", "name=n", "level=lv"],
  19. otherParam:{"otherParam":"zTreeAsyncTest"},
  20. dataFilter: filter
  21. },
  22. view: {expandSpeed:"",
  23. addHoverDom: addHoverDom,
  24. removeHoverDom: removeHoverDom,
  25. selectedMulti: false
  26. },
  27. edit: {
  28. enable: true
  29. },
  30. data: {
  31. simpleData: {
  32. enable: true
  33. }
  34. },
  35. callback: {
  36. beforeRemove: beforeRemove,
  37. beforeRename: beforeRename
  38. }
  39. };
  40. function filter(treeId, parentNode, childNodes) {
  41. if (!childNodes) return null;
  42. for (var i=0, l=childNodes.length; i<l; i++) {
  43. childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
  44. }
  45. return childNodes;
  46. }
  47. function beforeRemove(treeId, treeNode) {
  48. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  49. zTree.selectNode(treeNode);
  50. return confirm("Confirm delete node '" + treeNode.name + "' it?");
  51. }
  52. function beforeRename(treeId, treeNode, newName) {
  53. if (newName.length == 0) {
  54. setTimeout(function() {
  55. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  56. zTree.cancelEditName();
  57. alert("Node name can not be empty.");
  58. }, 0);
  59. return false;
  60. }
  61. return true;
  62. }
  63. var newCount = 1;
  64. function addHoverDom(treeId, treeNode) {
  65. var sObj = $("#" + treeNode.tId + "_span");
  66. if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
  67. var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
  68. + "' title='add node' onfocus='this.blur();'></span>";
  69. sObj.after(addStr);
  70. var btn = $("#addBtn_"+treeNode.tId);
  71. if (btn) btn.bind("click", function(){
  72. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  73. zTree.addNodes(treeNode, {id:(100 + newCount), pId:treeNode.id, name:"new node" + (newCount++)});
  74. return false;
  75. });
  76. };
  77. function removeHoverDom(treeId, treeNode) {
  78. $("#addBtn_"+treeNode.tId).unbind().remove();
  79. };
  80. $(document).ready(function(){
  81. $.fn.zTree.init($("#treeDemo"), setting);
  82. });
  83. //-->
  84. </SCRIPT>
  85. <style type="text/css">
  86. .ztree li span.button.add {margin-left:2px; margin-right: -1px; background-position:-144px 0; vertical-align:top; *vertical-align:middle}
  87. </style>
  88. </HEAD>
  89. <BODY>
  90. <h1>Editing Dynamic Tree</h1>
  91. <h6>[ File Path: exedit/async_edit.html ]</h6>
  92. <div class="content_wrap">
  93. <div class="zTreeDemoBackground left">
  94. <ul id="treeDemo" class="ztree"></ul>
  95. </div>
  96. <div class="right">
  97. <ul class="info">
  98. <li class="title"><h2>1, Explanation of editing dynamic tree</h2>
  99. <ul class="list">
  100. <li>1) This Demo is based on the "Advanced Edit Nodes" to modify, and open to drag and drop functionality, can be compared with that demo.</li>
  101. <li>2) At the same time set the editing mode and dynamic mode can be achieved editing dynamic tree.</li>
  102. <li class="highlight_red">3) zTree improved editing capabilities in dynamic mode, if the parent node hasn‘t loaded the child nodes, it will first load the child nodes before it add child node.</li>
  103. </ul>
  104. </li>
  105. <li class="title"><h2>2, Explanation of setting</h2>
  106. <ul class="list">
  107. <li class="highlight_red">1) Use editing features, please refer to "Normal Drag Node Operation" & "Basic Edit Nodes" demo of the instructions.</li>
  108. <li class="highlight_red">2) Use dynamic loading, please refer to "Dynamic Tree with Ajax" demo of the instructions.</li>
  109. </ul>
  110. </li>
  111. <li class="title"><h2>3, Explanation of treeNode</h2>
  112. <ul class="list">
  113. <li>No special requirements on the node data, please refer to "Dynamic Tree with Ajax" & "Normal Drag Node Operation" & "Basic Edit Nodes" demo of the instructions</li>
  114. </ul>
  115. </li>
  116. </ul>
  117. </div>
  118. </div>
  119. </BODY>
  120. </HTML>