8f9df09f579223ce96cba223b1bacb1a805cc2c8.svn-base 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5. <title>树的编辑</title>
  6. <!--框架必需start-->
  7. <script type="text/javascript" src="../../libs/js/jquery.js"></script>
  8. <script type="text/javascript" src="../../libs/js/language/cn.js"></script>
  9. <script type="text/javascript" src="../../libs/js/framework.js"></script>
  10. <link href="../../libs/css/import_basic.css" rel="stylesheet" type="text/css"/>
  11. <link rel="stylesheet" type="text/css" id="skin" prePath="../../"/>
  12. <link rel="stylesheet" type="text/css" id="customSkin"/>
  13. <!--框架必需end-->
  14. <!-- 树组件start -->
  15. <script type="text/javascript" src="../../libs/js/tree/ztree/ztree.js"></script>
  16. <link href="../../libs/js/tree/ztree/ztree.css" rel="stylesheet" type="text/css"/>
  17. <!-- 树组件 end -->
  18. </head>
  19. <body>
  20. <div class="box1" panelWidth="800">
  21. <table class="tableStyle" formMode="line">
  22. <tr>
  23. <td>选中节点:</td>
  24. <td><input type="text" style="width:300px;" id="selectNode"/></td>
  25. </tr>
  26. <tr>
  27. <td>功能描述:</td>
  28. <td><input type="text" style="width:300px;" id="nodeDes"/></td>
  29. </tr>
  30. <tr>
  31. <td>链接地址:</td>
  32. <td><input type="text" style="width:300px;" id="nodeUrl"/></td>
  33. </tr>
  34. <tr>
  35. <td>链接target:</td>
  36. <td><select editable="true" style="width:300px;" autoWidth="true" id="nodeTarget"><option>frmright</option><option>_blank</option><option>_self</option><option>_top</option><option>_parent</option></select></td>
  37. </tr>
  38. <tr>
  39. <td colspan="2">
  40. <input type="button" value="确定"/>
  41. <input type="button" value="取消"/>
  42. </td>
  43. </tr>
  44. </table>
  45. </div>
  46. <div class="box1" panelWidth="800">
  47. <div>
  48. <ul id="tree-1" class="ztree"></ul>
  49. </div>
  50. </div>
  51. <script type="text/javascript">
  52. var setting1 = {
  53. view: {
  54. addHoverDom: addHoverDom,
  55. removeHoverDom: removeHoverDom,
  56. selectedMulti: false
  57. },
  58. edit: {
  59. enable: true,
  60. renameTitle:"修改",
  61. removeTitle:"删除"
  62. },
  63. callback: {
  64. onClick: onClick1,
  65. //不允许拖拽
  66. beforeDrag: beforeDrag1,
  67. //修改前确认
  68. beforeEditName: beforeEditName1,
  69. //修改完时的处理
  70. beforeRename: beforeRename1,
  71. //修改成功后处理
  72. onRename: onRename1,
  73. //删除前确认
  74. beforeRemove: beforeRemove1
  75. }
  76. };
  77. var zNodes1 =[
  78. { id:1, parentId:0, name:"系统导航列表",icon:"../../libs/icons/list.gif"}
  79. ];
  80. function initComplete(){
  81. $.fn.zTree.init($("#tree-1"), setting1, zNodes1);
  82. }
  83. //点击
  84. function onClick1(event, treeId, treeNode, clickFlag){
  85. //设置表单的值
  86. setForm(treeNode.name,"","","frmright");
  87. }
  88. function beforeDrag1(treeId, treeNodes) {
  89. return false;
  90. }
  91. //确认是否进入编辑状态
  92. function beforeEditName1(treeId, treeNode) {
  93. if(treeNode.id=="1"){
  94. top.Dialog.alert("根节点不能修改!");
  95. return false;
  96. }
  97. var zTree = $.fn.zTree.getZTreeObj("tree-1");
  98. //选中该节点
  99. zTree.selectNode(treeNode);
  100. //设置表单的值
  101. setForm(treeNode.name,"","","frmright");
  102. zTree.editName(treeNode);
  103. return true;
  104. }
  105. //修改完时处理 不进行后台数据处理
  106. function beforeRename1(treeId, treeNode, newName) {
  107. if (newName.length == 0) {
  108. top.Dialog.alert("节点名称不能为空.");
  109. var zTree = $.fn.zTree.getZTreeObj("tree-1");
  110. setTimeout(function(){zTree.editName(treeNode)}, 10);
  111. return false;
  112. }
  113. return true;
  114. }
  115. //修改成功后处理
  116. function onRename1(event, treeId, treeNode) {
  117. //设置表单的值
  118. setForm(treeNode.name,"","","frmright");
  119. //此处进行ajax后台数据处理
  120. }
  121. //确认是否删除+删除处理
  122. function beforeRemove1(treeId, treeNode) {
  123. if(treeNode.id=="1"){
  124. top.Dialog.alert("根节点不能删除!");
  125. return false;
  126. }
  127. var zTree = $.fn.zTree.getZTreeObj("tree-1");
  128. //选中该节点
  129. zTree.selectNode(treeNode);
  130. top.Dialog.confirm("确认删除 节点 -- " + treeNode.name + " 吗?",function(){
  131. zTree.removeNode(treeNode);
  132. //此处进行ajax后台数据处理
  133. });
  134. return false;
  135. }
  136. //添加新增按钮
  137. var newCount = 1;
  138. function addHoverDom(treeId, treeNode) {
  139. if (treeNode.editNameFlag || $("#addBtn_" + treeNode.id).length > 0) return;
  140. var sObj = $("#" + treeNode.tId + "_span");
  141. var addStr = "<span class='zbutton add' id='addBtn_" + treeNode.id + "' title='添加' onfocus='this.blur();'></span>";
  142. sObj.append(addStr);
  143. var btn = $("#addBtn_" + treeNode.id);
  144. if (btn){
  145. btn.bind("click", function(){
  146. var zTree = $.fn.zTree.getZTreeObj("tree-1");
  147. var newNode;
  148. newNode = zTree.addNodes(treeNode, {id:(100 + newCount), parentId:treeNode.id, name:"新增" + (newCount++),icon:"../../libs/icons/mark.gif"});
  149. if (newNode) {
  150. zTree.editName(newNode[0]);
  151. //设置表单的值
  152. //setForm(newNode[0].name,"","","frmright");
  153. }
  154. return false;
  155. });
  156. }
  157. };
  158. function removeHoverDom(treeId, treeNode) {
  159. $("#addBtn_" + treeNode.id).unbind().remove();
  160. };
  161. function setForm(val1,val2,val3,val4){
  162. $("#selectNode").val(val1);
  163. $("#nodeDes").val(val2);
  164. $("#nodeUrl").val(val3);
  165. $("#nodeTarget").attr("editValue",val4);
  166. $("#nodeTarget").render();
  167. }
  168. </script>
  169. </body>
  170. </html>