edit_super.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - beforeEditName / beforeRemove / onRemove / beforeRename / onRename</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. view: {
  16. addHoverDom: addHoverDom,
  17. removeHoverDom: removeHoverDom,
  18. selectedMulti: false
  19. },
  20. edit: {
  21. enable: true,
  22. editNameSelectAll: true,
  23. showRemoveBtn: showRemoveBtn,
  24. showRenameBtn: showRenameBtn
  25. },
  26. data: {
  27. simpleData: {
  28. enable: true
  29. }
  30. },
  31. callback: {
  32. beforeDrag: beforeDrag,
  33. beforeEditName: beforeEditName,
  34. beforeRemove: beforeRemove,
  35. beforeRename: beforeRename,
  36. onRemove: onRemove,
  37. onRename: onRename
  38. }
  39. };
  40. var zNodes =[
  41. { id:1, pId:0, name:"parent node 1", open:true},
  42. { id:11, pId:1, name:"leaf node 1-1"},
  43. { id:12, pId:1, name:"leaf node 1-2"},
  44. { id:13, pId:1, name:"leaf node 1-3"},
  45. { id:2, pId:0, name:"parent node 2", open:true},
  46. { id:21, pId:2, name:"leaf node 2-1"},
  47. { id:22, pId:2, name:"leaf node 2-2"},
  48. { id:23, pId:2, name:"leaf node 2-3"},
  49. { id:3, pId:0, name:"parent node 3", open:true },
  50. { id:31, pId:3, name:"leaf node 3-1"},
  51. { id:32, pId:3, name:"leaf node 3-2"},
  52. { id:33, pId:3, name:"leaf node 3-3"}
  53. ];
  54. var log, className = "dark";
  55. function beforeDrag(treeId, treeNodes) {
  56. return false;
  57. }
  58. function beforeEditName(treeId, treeNode) {
  59. className = (className === "dark" ? "":"dark");
  60. showLog("[ "+getTime()+" beforeEditName ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
  61. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  62. zTree.selectNode(treeNode);
  63. return confirm("Start node '" + treeNode.name + "' editorial status?");
  64. }
  65. function beforeRemove(treeId, treeNode) {
  66. className = (className === "dark" ? "":"dark");
  67. showLog("[ "+getTime()+" beforeRemove ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
  68. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  69. zTree.selectNode(treeNode);
  70. return confirm("Confirm delete node '" + treeNode.name + "' it?");
  71. }
  72. function onRemove(e, treeId, treeNode) {
  73. showLog("[ "+getTime()+" onRemove ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
  74. }
  75. function beforeRename(treeId, treeNode, newName, isCancel) {
  76. className = (className === "dark" ? "":"dark");
  77. showLog((isCancel ? "<span style='color:red'>":"") + "[ "+getTime()+" beforeRename ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name + (isCancel ? "</span>":""));
  78. if (newName.length == 0) {
  79. alert("Node name can not be empty.");
  80. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  81. setTimeout(function(){zTree.editName(treeNode)}, 10);
  82. return false;
  83. }
  84. return true;
  85. }
  86. function onRename(e, treeId, treeNode, isCancel) {
  87. showLog((isCancel ? "<span style='color:red'>":"") + "[ "+getTime()+" onRename ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name + (isCancel ? "</span>":""));
  88. }
  89. function showRemoveBtn(treeId, treeNode) {
  90. return !treeNode.isFirstNode;
  91. }
  92. function showRenameBtn(treeId, treeNode) {
  93. return !treeNode.isLastNode;
  94. }
  95. function showLog(str) {
  96. if (!log) log = $("#log");
  97. log.append("<li class='"+className+"'>"+str+"</li>");
  98. if(log.children("li").length > 8) {
  99. log.get(0).removeChild(log.children("li")[0]);
  100. }
  101. }
  102. function getTime() {
  103. var now= new Date(),
  104. h=now.getHours(),
  105. m=now.getMinutes(),
  106. s=now.getSeconds(),
  107. ms=now.getMilliseconds();
  108. return (h+":"+m+":"+s+ " " +ms);
  109. }
  110. var newCount = 1;
  111. function addHoverDom(treeId, treeNode) {
  112. var sObj = $("#" + treeNode.tId + "_span");
  113. if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
  114. var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
  115. + "' title='add node' onfocus='this.blur();'></span>";
  116. sObj.after(addStr);
  117. var btn = $("#addBtn_"+treeNode.tId);
  118. if (btn) btn.bind("click", function(){
  119. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  120. zTree.addNodes(treeNode, {id:(100 + newCount), pId:treeNode.id, name:"new node" + (newCount++)});
  121. return false;
  122. });
  123. };
  124. function removeHoverDom(treeId, treeNode) {
  125. $("#addBtn_"+treeNode.tId).unbind().remove();
  126. };
  127. function selectAll() {
  128. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  129. zTree.setting.edit.editNameSelectAll = $("#selectAll").attr("checked");
  130. }
  131. $(document).ready(function(){
  132. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  133. $("#selectAll").bind("click", selectAll);
  134. });
  135. //-->
  136. </SCRIPT>
  137. <style type="text/css">
  138. .ztree li span.button.add {margin-left:2px; margin-right: -1px; background-position:-144px 0; vertical-align:top; *vertical-align:middle}
  139. </style>
  140. </HEAD>
  141. <BODY>
  142. <h1>Advanced Edit Nodes</h1>
  143. <h6>[ File Path: exedit/edit_super.html ]</h6>
  144. <div class="content_wrap">
  145. <div class="zTreeDemoBackground left">
  146. <ul id="treeDemo" class="ztree"></ul>
  147. </div>
  148. <div class="right">
  149. <ul class="info">
  150. <li class="title"><h2>1, 'beforeDrag / onDrag'<br/>&nbsp;&nbsp;'beforeEditName'<br/>&nbsp;&nbsp;'beforeRemove / onRemove'<br/>&nbsp;&nbsp;'beforeRename / onRename' callback function</h2>
  151. <ul class="list">
  152. <li>This demo shows the use of custom controls, the callback function to enhance the user experience, the operation can be compared with "Basic Edit Nodes" example.</li>
  153. <li>This demo achieve the Add nodes button.</li>
  154. <li>This demo achieve the confirmation when deleting node.</li>
  155. <li>This demo use the 'showRenameBtn' to hide the rename button, when the treeNode's isLastNode = true</li>
  156. <li>This demo use the 'showRemoveBtn' to hide the delete button, when the treeNode's isFirstNode = true</li>
  157. <li class="highlight_red">Can use 'beforeEditName' callback trigger custom editing.</li>
  158. <li><p><span class="highlight_red">After be familiar with these configurations, I think you can design a more flexible and rational rules!</span><br/>
  159. &nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="selectAll" checked /> Whether select all text, when edit node's name.<br/>
  160. remove / rename log:&nbsp;&nbsp;<span style="color:red">RED</span> is cancel edit (v3.5.13+)<br/>
  161. <ul id="log" class="log"></ul></p>
  162. </li>
  163. </ul>
  164. </li>
  165. <li class="title"><h2>2, Explanation of setting</h2>
  166. <ul class="list">
  167. <li>Same as 'Basic Edit Nodes'</li>
  168. </ul>
  169. </li>
  170. <li class="title"><h2>3, Explanation of treeNode</h2>
  171. <ul class="list">
  172. <li>Same as 'Basic Edit Nodes'</li>
  173. </ul>
  174. </li>
  175. </ul>
  176. </div>
  177. </div>
  178. </BODY>
  179. </HTML>