<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="menutreeeditmove.aspx.cs" Inherits="Us.Web.admin.v3basic.menutreeeditmove" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8,chrome=1" />
<title>系统菜单</title><link href="../style/default/style.css" rel="stylesheet" type="text/css" />
<%=ImportScriptStr %>

 

<link rel="stylesheet" href="../mtree/css/zTreeStyle/zTreeStyle.css" type="text/css">

<script type="text/javascript" src="../mtree/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="../mtree/js/jquery.ztree.excheck-3.5.js"></script>
<script type="text/javascript" src="../mtree/js/jquery.ztree.exedit-3.5.js"></script>
 <SCRIPT type="text/javascript">
		<!--
    var setting = {

        view: {
            dblClickExpand: false,
            showLine: true
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        edit: {
            drag: {
                autoExpandTrigger: true,
                prev: dropPrev,
                inner: dropInner,
                next: dropNext
            },
            enable: true,
            showRemoveBtn: false,
            showRenameBtn: false
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            beforeDrag: beforeDrag,
            beforeDrop: beforeDrop,
            beforeDragOpen: beforeDragOpen,
            onDrag: onDrag,
            onDrop: onDrop,
            onExpand: onExpand
        }
    };

   <% =TreeHTML %>

     function dropPrev(treeId, nodes, targetNode) {
         var pNode = targetNode.getParentNode();
         if (pNode && pNode.dropInner === false) {
             return false;
         } else {
             for (var i = 0, l = curDragNodes.length; i < l; i++) {
                 var curPNode = curDragNodes[i].getParentNode();
                 if (curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
                     return false;
                 }
             }
         }
         return true;
     }
     function dropInner(treeId, nodes, targetNode) {
         if (targetNode && targetNode.dropInner === false) {
             return false;
         } else {
             for (var i = 0, l = curDragNodes.length; i < l; i++) {
                 if (!targetNode && curDragNodes[i].dropRoot === false) {
                     return false;
                 } else if (curDragNodes[i].parentTId && curDragNodes[i].getParentNode() !== targetNode && curDragNodes[i].getParentNode().childOuter === false) {
                     return false;
                 }
             }
         }
         return true;
     }
     function dropNext(treeId, nodes, targetNode) {
         var pNode = targetNode.getParentNode();
         if (pNode && pNode.dropInner === false) {
             return false;
         } else {
             for (var i = 0, l = curDragNodes.length; i < l; i++) {
                 var curPNode = curDragNodes[i].getParentNode();
                 if (curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
                     return false;
                 }
             }
         }
         return true;
     }

     var log, className = "dark", curDragNodes, autoExpandNode;
     function beforeDrag(treeId, treeNodes) {
         className = (className === "dark" ? "" : "dark");
         //showLog("[ " + getTime() + " beforeDrag ]&nbsp;&nbsp;&nbsp;&nbsp; drag: " + treeNodes.length + " nodes.");
         for (var i = 0, l = treeNodes.length; i < l; i++) {
             if (treeNodes[i].drag === false) {
                 curDragNodes = null;
                 return false;
             } else if (treeNodes[i].parentTId && treeNodes[i].getParentNode().childDrag === false) {
                 curDragNodes = null;
                 return false;
             }
         }
         curDragNodes = treeNodes;
         return true;
     }
     function beforeDragOpen(treeId, treeNode) {
         autoExpandNode = treeNode;
         return true;
     }
     function beforeDrop(treeId, treeNodes, targetNode, moveType, isCopy) {
         className = (className === "dark" ? "" : "dark");
         //showLog("[ " + getTime() + " beforeDrop ]&nbsp;&nbsp;&nbsp;&nbsp; moveType:" + moveType);
         //showLog("target: " + (targetNode ? targetNode.name : "root") + "  -- is " + (isCopy == null ? "cancel" : isCopy ? "copy" : "move"));
         return true;
     }
     function onDrag(event, treeId, treeNodes) {
         className = (className === "dark" ? "" : "dark");
         //showLog("[ " + getTime() + " onDrag ]&nbsp;&nbsp;&nbsp;&nbsp; drag: " + treeNodes.length + " nodes.");
         showLog("[开始拖动]");
     }
     function onDrop(event, treeId, treeNodes, targetNode, moveType, isCopy) {
         className = (className === "dark" ? "" : "dark");
         //showLog("[ " + getTime() + " onDrop ]&nbsp;&nbsp;&nbsp;&nbsp; moveType:" + moveType);

         //showLog("treeId=" + treeId);
         //showLog("targetNode=" + targetNode.id);
         //alert(targetNode.getParentNode().name);

         var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
         var node = treeObj.getSelectedNodes()[0];
         var parentNode = node.getParentNode();

         var childrenNodes;// = parentNode.children;
         if (parentNode == null) {
             childrenNodes = treeObj.getNodes();
         }
         else {
             childrenNodes = parentNode.children;
         }



         result = "";
         var pid = "0";
         for (var i = 0; i < childrenNodes.length; i++) {
             pid = childrenNodes[i].pId;
             result += childrenNodes[i].id + ",";
         }
         if (pid == null) { pid = "0" }
         //alert("pid=" + pid + ",id=" + result);

         showLog("[拖动结束]");

         $.ajax({
             type: "POST",
             url: "menumanagerajax.aspx",
             data: "keyid=1&id=" + result + "&pid=" + pid,
             success: function (msg) {
                 //alert(msg);
                 if (msg == "0") {
                     //alert("恭喜您，更换课程成功！");
                     showLog("[成功保存]");

                 }
                 else {

                     showLog("[提交失败]");
                     //alert("对不起，更换课程失败！");
                 }
             }
         });

     }
     function onExpand(event, treeId, treeNode) {
         if (treeNode === autoExpandNode) {
             className = (className === "dark" ? "" : "dark");
             //showLog("[ " + getTime() + " onExpand ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name);
         }
     }

     function showLog(str) {
         $("#loginfo").html(str);
     }
     function getTime() {
         var now = new Date(),
         h = now.getHours(),
         m = now.getMinutes(),
         s = now.getSeconds(),
         ms = now.getMilliseconds();
         return (h + ":" + m + ":" + s + " " + ms);
     }

     function setTrigger() {
         var zTree = $.fn.zTree.getZTreeObj("treeDemo");
     }

     $(document).ready(function () {
         $.fn.zTree.init($("#treeDemo"), setting, zNodes);
         //$("#callbackTrigger").bind("change", {}, setTrigger);
     });
     //-->
	</SCRIPT>
   

 <script language="javascript" type="text/javascript" >
     function AutoHeight() {
         var h = $(window).height() - 70;
         $("#ScroLeft").height(h);
     }

     $(document).ready(function () {
         AutoHeight();
     });
</script>

</head>
<body>
<form id="Form1" method="post" runat="server">
  <table width="100%" border="0" cellpadding="0" cellspacing="0" height="100%">
    <tr>
      <td width="100%" valign="top">
          
          <div class="divTbg">
          <div class="divTbgL"></div>
          <div class="divTbgInfo">
            <div class="divTbgTitle">菜单拖动管理</div>
          </div>
        </div>
        <div class="divTbgF"></div>
        <div class="divSearchBoth">
         <table  border="0" cellpadding="0" cellspacing="0">
             <tr>
                 <td width="220"> <div class="divInfo" align="center">
                     <a href="menutreeedit.aspx" class="rptlink careffdivheight" target="_self">[菜单管理]</a>&nbsp;&nbsp;

                     <span class="rptlink careffdivheight" id="loginfo">[操作提示]</span>
          </div>
          <div class="divInfo">
            <div class="divAutoHeight" id="ScroLeft" style="overflow:auto;"><ul id="treeDemo" class="ztree"></ul> 
            </div>
          </div></td>
                 <td style=" text-align:left; vertical-align:text-top;">
          <div class="divInfo">
                    <br>
              <pre></pre>
                       <span class="fColorRed">*使用提示*</span><br>
                     1、选择想要排序的菜单 <br>
                     2、按住鼠标左键拖动 <br>
                     3、拖动到目标位置撒开左键 <br>
                     4、查看系统提示 <br>
                     5、所有操作都是即时提交，不可撤销； <br>
                     6、如果发现拖动错误，可以重新拖动回来，也可以把鼠标拖动到页面其他空白地方后撒开鼠标来取消；
                   </div>      </td>
             </tr>

         </table>
           
        </div></td>
     
    </tr>
  </table>
</form>
</body>
</html>
