123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <!DOCTYPE html>
- <HTML>
- <HEAD>
- <TITLE> ZTREE DEMO - copyNode / moveNode</TITLE>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <link rel="stylesheet" href="../../../css/demo.css" type="text/css">
- <link rel="stylesheet" href="../../../css/zTreeStyle/zTreeStyle.css" type="text/css">
- <script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>
- <script type="text/javascript" src="../../../js/jquery.ztree.core-3.5.js"></script>
- <script type="text/javascript" src="../../../js/jquery.ztree.excheck-3.5.js"></script>
- <script type="text/javascript" src="../../../js/jquery.ztree.exedit-3.5.js"></script>
- <SCRIPT type="text/javascript">
- <!--
- var setting = {
- view: {
- selectedMulti: false
- },
- edit: {
- enable: true,
- showRemoveBtn: false,
- showRenameBtn: false
- },
- data: {
- simpleData: {
- enable: true
- }
- },
- callback: {
- beforeDrag: beforeDrag,
- beforeClick: beforeClick
- }
- };
- var zNodes =[
- { id:1, pId:0, name:"parent node 1", open:true},
- { id:11, pId:1, name:"leaf node 1-1"},
- { id:12, pId:1, name:"leaf node 1-2"},
- { id:13, pId:1, name:"leaf node 1-3"},
- { id:2, pId:0, name:"parent node 2", open:true},
- { id:21, pId:2, name:"leaf node 2-1"},
- { id:22, pId:2, name:"leaf node 2-2"},
- { id:23, pId:2, name:"leaf node 2-3"},
- { id:3, pId:0, name:"parent node 3", open:true },
- { id:31, pId:3, name:"leaf node 3-1"},
- { id:32, pId:3, name:"leaf node 3-2"},
- { id:33, pId:3, name:"leaf node 3-3"}
- ];
- function fontCss(treeNode) {
- var aObj = $("#" + treeNode.tId + "_a");
- aObj.removeClass("copy").removeClass("cut");
- if (treeNode === curSrcNode) {
- if (curType == "copy") {
- aObj.addClass(curType);
- } else {
- aObj.addClass(curType);
- }
- }
- }
- function beforeDrag(treeId, treeNodes) {
- return false;
- }
- function beforeClick(treeId, treeNode) {
- return !treeNode.isCur;
- }
- var curSrcNode, curType;
- function setCurSrcNode(treeNode) {
- var zTree = $.fn.zTree.getZTreeObj("treeDemo");
- if (curSrcNode) {
- delete curSrcNode.isCur;
- var tmpNode = curSrcNode;
- curSrcNode = null;
- fontCss(tmpNode);
- }
- curSrcNode = treeNode;
- if (!treeNode) return;
- curSrcNode.isCur = true;
- zTree.cancelSelectedNode();
- fontCss(curSrcNode);
- }
- function copy(e) {
- var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
- nodes = zTree.getSelectedNodes();
- if (nodes.length == 0) {
- alert("Please select one node at first...");
- return;
- }
- curType = "copy";
- setCurSrcNode(nodes[0]);
- }
- function cut(e) {
- var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
- nodes = zTree.getSelectedNodes();
- if (nodes.length == 0) {
- alert("Please select one node at first...");
- return;
- }
- curType = "cut";
- setCurSrcNode(nodes[0]);
- }
- function paste(e) {
- if (!curSrcNode) {
- alert("Please select one node to copy or cut at first...");
- return;
- }
- var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
- nodes = zTree.getSelectedNodes(),
- targetNode = nodes.length>0? nodes[0]:null;
- if (curSrcNode === targetNode) {
- alert("Can't move, the same source node and destination node.");
- return;
- } else if (curType === "cut" && ((!!targetNode && curSrcNode.parentTId === targetNode.tId) || (!targetNode && !curSrcNode.parentTId))) {
- alert("Can't move, source node is the target node's child.");
- return;
- } else if (curType === "copy") {
- targetNode = zTree.copyNode(targetNode, curSrcNode, "inner");
- } else if (curType === "cut") {
- targetNode = zTree.moveNode(targetNode, curSrcNode, "inner");
- if (!targetNode) {
- alert("Cutting failure, source node is the target node's parent.");
- }
- targetNode = curSrcNode;
- }
- setCurSrcNode();
- delete targetNode.isCur;
- zTree.selectNode(targetNode);
- }
-
- $(document).ready(function(){
- $.fn.zTree.init($("#treeDemo"), setting, zNodes);
- $("#copy").bind("click", copy);
- $("#cut").bind("click", cut);
- $("#paste").bind("click", paste);
- });
- //-->
- </SCRIPT>
- <style type="text/css">
- .ztree li a.copy{padding-top:0; background-color:#316AC5; color:white; border:1px #316AC5 solid;}
- .ztree li a.cut{padding-top:0; background-color:silver; color:#111; border:1px #316AC5 dotted;}
- </style>
- </HEAD>
- <BODY>
- <h1>Move / Copy - zTree methods</h1>
- <h6>[ File Path: exedit/drag_fun.html ]</h6>
- <div class="content_wrap">
- <div class="zTreeDemoBackground left">
- <ul id="treeDemo" class="ztree"></ul>
- </div>
- <div class="right">
- <ul class="info">
- <li class="title"><h2>1, Explanation of 'copyNode / moveNode' method</h2>
- <ul class="list">
- <li>Use 'copyNode / moveNode' method can also be achieved copy / move nodes.</li>
- <li><p>Try to copy or cut node:<br/>
- [ <a id="copy" href="#" title="copy" onclick="return false;">copy</a> ]
- [ <a id="cut" href="#" title="cut" onclick="return false;">cut</a> ]
- [ <a id="paste" href="#" title="paste" onclick="return false;">paste</a> ]</p>
- <li class="highlight_red">How to use 'zTreeObj.copyNode / moveNode' method, please see the API documentation.</li>
- </ul>
- </li>
- <li class="title"><h2>2, Explanation of setting</h2>
- <ul class="list">
- <li>Same as 'Normal Drag Node Operation'</li>
- </ul>
- </li>
- <li class="title"><h2>3, Explanation of treeNode</h2>
- <ul class="list">
- <li>Same as 'Normal Drag Node Operation'</li>
- </ul>
- </li>
- </ul>
- </div>
- </div>
- </BODY>
- </HTML>
|