<%@ Page Language="c#" Inherits="Web.Wpdcc.groupAccredit" CodeBehind="groupAccredit.aspx.cs" %>

<!DOCTYPE html>
<!--[if lt IE 9]><html class="lte-ie8"><![endif]-->
<!--[if gt IE 8]><!-->
<html>
<!--<![endif]-->
<head>
    <title>用户组权限管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!--#include file = "../Css/head.htm" -->
         <script type="text/javascript" src="../js/TreeView2.js"></script>

    <script type="text/javascript" language="javascript">

        var TURLParams = new Object();

        function closeWindow() {
            window.close();
        }
        function initValues() {
            var re = new RegExp("canAuditContribute", "g")
            var TaParams = document.all.Hidden1.value.split('|');
            for (i = 0 ; i < TaParams.length ; i++) {
                var TaParam = TaParams[i].split('=');
                TURLParams[TaParam[0]] = TaParam[1];
                if (re.test(TaParam[0]) == true) {
                    var menuId = TaParam[0].replace("canAuditContribute", "");
                    var itemAdd = document.getElementById("canAdd" + menuId);
                    var itemDelete = document.getElementById("canDelete" + menuId);
                    var itemRecommand = document.getElementById("canSetRecommand" + menuId);
                    var itemTop = document.getElementById("canSetTop" + menuId);
                    if (TaParam[1] == "1") {
                        itemAdd.selectedIndex = 0;
                        itemAdd.disabled = true;
                        TURLParams["canAdd" + menuId] = 0;
                        itemDelete.selectedIndex = 0;
                        itemDelete.disabled = true;
                        TURLParams["canDelete" + menuId] = 0;
                    }
                    else {
                        itemRecommand.selectedIndex = 0;
                        itemRecommand.disabled = true;
                        TURLParams["canSetRecommand" + menuId] = 0;
                        itemTop.selectedIndex = 0;
                        itemTop.disabled = true;
                        TURLParams["canSetTop" + menuId] = 0;
                    }
                }
            }
        }
        function changeValue(id, menuId, val) {
            var d = id.indexOf(menuId);
            if (id.substring(0, d) == "canAuditContribute") {
                var itemAdd = document.getElementById("canAdd" + menuId);
                var itemDelete = document.getElementById("canDelete" + menuId);
                var itemRecommand = document.getElementById("canSetRecommand" + menuId);
                var itemTop = document.getElementById("canSetTop" + menuId);
                if (val == "1") {
                    itemAdd.selectedIndex = 0;
                    TURLParams["canAdd" + menuId] = 0;
                    itemAdd.disabled = true;

                    itemDelete.selectedIndex = 0;
                    TURLParams["canDelete" + menuId] = 0;
                    itemDelete.disabled = true;

                    itemRecommand.selectedIndex = 1;
                    TURLParams["canSetRecommand" + menuId] = 1
                    itemRecommand.disabled = false;

                    itemTop.selectedIndex = 1;
                    TURLParams["canSetTop" + menuId] = 1
                    itemTop.disabled = false;
                }
                else if (val == "0") {
                    itemRecommand.selectedIndex = 0;
                    TURLParams["canSetRecommand" + menuId] = 0;
                    itemRecommand.disabled = true;

                    itemTop.selectedIndex = 0;
                    TURLParams["canSetTop" + menuId] = 0;
                    itemTop.disabled = true;

                    itemAdd.selectedIndex = 1;
                    TURLParams["canAdd" + menuId] = 1
                    itemAdd.disabled = false;

                    itemDelete.selectedIndex = 1;
                    TURLParams["canDelete" + menuId] = 1
                    itemDelete.disabled = false;
                }
            }
            TURLParams[id] = val;
        }
        function setValues() {
            var str = '';
            var TaParams = document.all.Hidden1.value.split('|');
            for (i = 0 ; i < TaParams.length ; i++) {
                var TaParam = TaParams[i].split('=');
                str = str + TaParam[0] + "=" + TURLParams[TaParam[0]] + "|";
            }
            document.all.Hidden2.value = str;
        }
    </script>

    <script type="text/javascript" language="javascript">

        function getNodeIndex1(node) {
            var strIndex = "";
            if (node != null) {
                if (node.getAttribute("sibIndex") == null) {
                    if (node.parentElement == null) {
                        return null;
                    }
                    var col = node.parentElement.children.tags("treenode");
                    var i = 0;
                    while (col[i] != node) i++;
                    node.setAttribute("sibIndex", i);
                }
                strIndex = node.getAttribute("sibIndex");
                while (node.getAttribute("parentElement") && node.getAttribute("parentElement").tagName.toLowerCase() == "treenode") {
                    node = node.getAttribute("parentElement");
                    if (node.getAttribute("sibIndex") == null)
                        return null;
                    strIndex = node.getAttribute("sibIndex") + "." + strIndex;
                }
            }
            return strIndex;
        }

        //初始化选中节点
        function initchecknode() {
            var node = treeMenu.getTreeNode("1");
            node.setAttribute("Checked", "false");
            setcheck(node, "false");
            treeMenu.queueEvent('oncheck', getNodeIndex1(node));
            // FindCheckedFromNode(treeMenu);
        }
        //oncheck事件
        function tree_oncheck(tree) {

            var node = treeMenu.getTreeNode(treeMenu.clickedNodeIndex);
            var Pchecked = node.getAttribute("Checked");
            alert(node.getAttribute("Text") + "=" + Pchecked);
            setcheck(node, Pchecked);
            node.setAttribute("Checked", Pchecked);
            treeMenu.queueEvent('oncheck', treeMenu.clickedNodeIndex);

        }
        //设置子节点选中
        function setcheck(node, Pc) {

            var i;
            var ChildNode = new Array();
            ChildNode = node.getChildren();

            if (parseInt(ChildNode.length) == 0) {
                return;
            }
            else {
                for (i = 0; i < ChildNode.length; i++) {
                    var cNode;
                    cNode = ChildNode[i];
                    if (parseInt(cNode.getChildren().length) != 0) {
                        setcheck(cNode, Pc);
                    }
                    cNode.setAttribute("Checked", Pc);
                    //    alert(getNodeFromIndex(getNodeIndex1(cNode)));
                    treeMenu.queueEvent('oncheck', getNodeIndex1(cNode));
                }
            }
        }
        //获取所有节点状态
        function FindCheckedFromNode(node, Pc) {
            var i = 0;
            var nodes = new Array();
            nodes = node.getChildren();

            for (i = 0; i < nodes.length; i++) {
                var cNode;
                cNode = nodes[i];
                cNode.setAttribute("Checked", Pc);
                //    alert(getNodeFromIndex(getNodeIndex1(cNode)));
                treeMenu.queueEvent('oncheck', getNodeIndex1(cNode));

                if (parseInt(cNode.getChildren().length) != 0) {
                    FindCheckedFromNode(cNode, Pc);
                }
            }
        }
        //添加选中节点
        function AddChecked(node) {
            //document.accredit.checked.value += node.getAttribute("NodeData");
            // document.accredit.checked.value += ',';
        }
        //添加未选中节点
        function AddUnChecked(node) {
            //document.accredit.unchecked.value += node.getAttribute("NodeData");
            //document.accredit.unchecked.value += ',';
        }

        //李聪杰 2006-6-9
        function OnTreeNodeChecked(number, ev) {
            var element = ev.srcElement || ev.target;
            if (!IsCheckBox(element))
                return;

            var isChecked = element.checked;

            var tree = TV2_GetTreeById("treeMenu");
            var node = TV2_GetNode(tree, element);

            TV2_SetChildNodesCheckStatus(node, isChecked);

            var parent = TV2_GetParentNode(tree, node);
            TV2_NodeOnChildNodeCheckedChanged_Zdsoft(tree, parent, true);

        }

        //关闭弹出层
        function delayClose() {
            //alert("恭喜您，权限分配成功！");
            parent.$.fancybox.close();
        }
    </script>
</head>
<body>
    <form method="post" runat="server" target="_self">
        <div class="list-func-box func-box">
            <div class="hd b">
                <asp:Label ID="groupName" runat="server">用户组名称：</asp:Label>
                <div class="user-service">
                     <span data-original-title="帮助" data-placement="left" data-rel="popover" data-content="若未正常显示菜单树，请把webctrl_client文件夹拷贝到当前站点根目录" data-trigger="hover"><i class="fa fa-question-circle bigger-120 white"></i></span>
                </div>
            </div>
            <div class="space-4"></div>
            <div class="container">
                <table border="1px" width="100%">
                    <tr>
                        <td style="width: 100px">
                            <asp:TreeView ID="treeMenu" runat="server" ExpandDepth="0" ShowCheckBoxes="All" ShowLines="True"
                                AutoGenerateDataBindings="False">
                            </asp:TreeView>
                            <asp:Label ID="checkLabel" runat="server" Visible="False" ForeColor="Red"></asp:Label>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="ft">
                <div class="action-field text-center">
                    <asp:Button ID="selectTrue" class="btn btn-sm btn-primary" runat="server" Text="全部选中" EnableViewState="False"
                        CausesValidation="False" OnClick="selectTrue_Click"></asp:Button>
                    &nbsp;
                <asp:Button ID="selectFalse" class="btn btn-sm btn-primary" runat="server" Text="全部取消" OnClick="selectFalse_Click"></asp:Button>
                    &nbsp;
                <asp:Button ID="checkButton" class="btn btn-sm btn-primary" runat="server" Text="确  定" OnClick="checkButton_Click"></asp:Button>
                    &nbsp;
                <input name="button" type="button" class="btn btn-sm btn-primary" onclick="parent.$.fancybox.close();"
                    value="关  闭" />
                    <input id="Hidden1" runat="server" type="Hidden" />
                    <input id="Hidden2" runat="server" type="Hidden" />
                </div>
            </div>
        </div>
    </form>
     <!--#include file = "../Css/foot.htm" -->
    
    <script type="text/javascript" language="javascript">
        initValues();
    </script>

</body>
</html>
