async_edit.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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-3.5.js"></script>
  10. <script type="text/javascript" src="../../../js/jquery.ztree.excheck-3.5.js"></script>
  11. <script type="text/javascript" src="../../../js/jquery.ztree.exedit-3.5.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. alert("Node name can not be empty.");
  55. return false;
  56. }
  57. return true;
  58. }
  59. var newCount = 1;
  60. function addHoverDom(treeId, treeNode) {
  61. var sObj = $("#" + treeNode.tId + "_span");
  62. if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
  63. var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
  64. + "' title='add node' onfocus='this.blur();'></span>";
  65. sObj.after(addStr);
  66. var btn = $("#addBtn_"+treeNode.tId);
  67. if (btn) btn.bind("click", function(){
  68. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  69. zTree.addNodes(treeNode, {id:(100 + newCount), pId:treeNode.id, name:"new node" + (newCount++)});
  70. return false;
  71. });
  72. };
  73. function removeHoverDom(treeId, treeNode) {
  74. $("#addBtn_"+treeNode.tId).unbind().remove();
  75. };
  76. $(document).ready(function(){
  77. $.fn.zTree.init($("#treeDemo"), setting);
  78. });
  79. //-->
  80. </SCRIPT>
  81. <style type="text/css">
  82. .ztree li span.button.add {margin-left:2px; margin-right: -1px; background-position:-144px 0; vertical-align:top; *vertical-align:middle}
  83. </style>
  84. </HEAD>
  85. <BODY>
  86. <h1>Editing Dynamic Tree</h1>
  87. <h6>[ File Path: exedit/async_edit.html ]</h6>
  88. <div class="content_wrap">
  89. <div class="zTreeDemoBackground left">
  90. <ul id="treeDemo" class="ztree"></ul>
  91. </div>
  92. <div class="right">
  93. <ul class="info">
  94. <li class="title"><h2>1, Explanation of editing dynamic tree</h2>
  95. <ul class="list">
  96. <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>
  97. <li>2) At the same time set the editing mode and dynamic mode can be achieved editing dynamic tree.</li>
  98. <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>
  99. </ul>
  100. </li>
  101. <li class="title"><h2>2, Explanation of setting</h2>
  102. <ul class="list">
  103. <li class="highlight_red">1) Use editing features, please refer to "Normal Drag Node Operation" & "Basic Edit Nodes" demo of the instructions.</li>
  104. <li class="highlight_red">2) Use dynamic loading, please refer to "Dynamic Tree with Ajax" demo of the instructions.</li>
  105. </ul>
  106. </li>
  107. <li class="title"><h2>3, Explanation of treeNode</h2>
  108. <ul class="list">
  109. <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>
  110. </ul>
  111. </li>
  112. </ul>
  113. </div>
  114. </div>
  115. </BODY>
  116. </HTML>