<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="rolelist.aspx.cs" Inherits="HySoft.BaseCallCenter.Web.sysmanage.rolelist" %>

<!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 id="Head1" runat="server">
    <title>角色管理</title>
    <link href="../scripts/ui/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <script src="../scripts/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="../scripts/jquery/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/core/base.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/ligerui.min.js" type="text/javascript"></script>
    <link href="../scripts/ui/skins/Tab/css/tab.css" rel="stylesheet" type="text/css" />
    <link href="../scripts/ui/skins/Tab/css/grid.css" rel="stylesheet" type="text/css" />
    <script src="../scripts/ui/js/plugins/ligerGrid.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/plugins/ligerLayout.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/plugins/ligerTree.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/plugins/ligerMenu.js" type="text/javascript"></script>
    <script src="../scripts/CustomersData.js" type="text/javascript"></script>
    <link href="../scripts/ui/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <script src="../scripts/My97DatePicker/lang/zh-cn.js" type="text/javascript"></script>
    <link href="../images/style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        var menu;
        var menucategory;
        var actionNode;
        var actionRow;
        var categorytree = null;
        var gridlist = null;
        var singleClick = 0;
        var iconcls;
        var treeClick;
        var actionNodeID;
        var pandaun = 0;
        var pandaunCheck = 0;
        var pandaunClick = "false";
        var pandaunClickDouble = 0;
        var panduanrole = 0;
        var count = 1;
        var counts = 1;
        function itemclick(item, i) {
            alert(actionNodeID + " | " + item.text);
        }
        function tree() {
            try {
                var vwidth = document.body.clientWidth - 450;
                categorytree = $("#tree1").ligerTree({
                    checkbox: true,
                    nodeWidth: 500,
                    autoCheckboxEven: false,
                    url: 'ajax/rolelist.ashx?action=gettreelist',
                    onSuccess: function (data) {
                        var parm = function (data) {
                            var s = false;
                            var s1 = false;
                            if (document.getElementById("hdF_FunctionId").value != "") {
                                var str = new Array();
                                var strdata = "";
                                str = document.getElementById("hdF_FunctionId").value.split(',');
                                for (var i = 0; i < str.length - 1; i++) {
                                    s = s || data.id == str[i];
                                }
                                s = (s) && data.IconCls == "1";
                            }
                            if (document.getElementById("hdF_ModuleId").value != "") {
                                var str = new Array();
                                var strdata = "";
                                str = document.getElementById("hdF_ModuleId").value.split(',');
                                for (var i = 0; i < str.length - 1; i++) {
                                    s1 = s1 || data.id == str[i];
                                }
                                s1 = (s1) && data.IconCls == "4";
                            }
                            return (s) || (s1);
                        };
                        categorytree.selectNode(parm);
                    },
                    onClick: function (node, target) {
                        //                        if (pandaunClickDouble != node.data.id) {
                        //                            pandaunClickDouble = node.data.id;
                        //                            alert(1);
                        //                        }
                        //                        else {
                        //                            pandaunClickDouble = 0;
                        //                            alert(0);
                        //                        }
                        //alert("onClick" + pandaunCheck);

                        if (count > 1) {
                            count -= 1;
                            return;
                        } else {
                            count = counts;
                            var arr = new Array();
                            arr = categorytree.getChecked();

                            for (var i = 0; i < arr.length; i++) {
                                if (node.data.id == arr[i].data.id) {

                                    pandaunClick = "true";
                                }

                            }

                            if (pandaunCheck == 0) {
                                if (node.data.IconCls == "1") {
                                    $.ajax({
                                        async: false,
                                        type: "Post",
                                        url: "rolelist.aspx/GetChildrenID",
                                        //方法传参的写法一定要对，str为形参的名字,str2为第二个形参的名字
                                        data: "{'id':'" + node.data.id + "','roleid':'" + singleClick + "','pandaunClick':'" + pandaunClick + "','F_FunctionId':'" + document.getElementById("hdF_FunctionId").value + "','F_ModuleId':'" + document.getElementById("hdF_ModuleId").value + "'}",
                                        contentType: "application/json; charset=utf-8",
                                        dataType: "json",
                                        success: function (data) {
                                            //返回的数据用data.d获取内容
                                            var str1 = data.d;
                                            var str = new Array();
                                            str = str1.split('@');
                                            if (str.length = 5) {

                                                //alert(pandaunClickDouble + "   " + node.data.id);
                                                if (pandaunClick == "true") {

                                                    pandaunClick = "false";
                                                    pandaunClickDouble = node.data.id;
                                                    panduanrole = singleClick;
                                                    document.getElementById("hdF_FunctionId").value = str[0];
                                                    document.getElementById("hdF_ModuleId").value = str[1];
                                                    var str2 = new Array();
                                                    str2 = str[3].split(',');
                                                    for (var i = 0; i < str2.length - 1; i++) {
                                                        categorytree.cancelSelect(categorytree.getDataByID(str2[i]));
                                                    }
                                                    var str3 = new Array();
                                                    str3 = str[4].split(',');
                                                    for (var i = 0; i < str3.length - 1; i++) {
                                                        categorytree.cancelSelect(categorytree.getDataByID(str3[i]));
                                                    }


                                                }
                                                else {

                                                    document.getElementById("hdF_FunctionId").value = str[0];
                                                    document.getElementById("hdF_ModuleId").value = str[1];
                                                    panduanrole = singleClick;
                                                    var parm = function (data) {
                                                        var s = false;
                                                        var s1 = false;
                                                        if (document.getElementById("hdF_FunctionId").value != "") {
                                                            var str = new Array();
                                                            var strdata = "";
                                                            str = document.getElementById("hdF_FunctionId").value.split(',');
                                                            for (var i = 0; i < str.length - 1; i++) {
                                                                s = s || data.id == str[i];
                                                            }
                                                            s = (s) && data.IconCls == "1";
                                                        }
                                                        if (document.getElementById("hdF_ModuleId").value != "") {
                                                            var str = new Array();
                                                            var strdata = "";
                                                            str = document.getElementById("hdF_ModuleId").value.split(',');
                                                            for (var i = 0; i < str.length - 1; i++) {
                                                                s1 = s1 || data.id == str[i];
                                                            }
                                                            s1 = (s1) && data.IconCls == "4";
                                                        }
                                                        return (s) || (s1);
                                                    };
                                                    pandaunClick = "false";
                                                    pandaunClickDouble = node.data.id;
                                                    categorytree.selectNode(parm);

                                                }


                                            }
                                        },
                                        error: function (err) {

                                        }
                                    });
                                }
                            }
                            if (pandaunCheck == 0) {

                            } else {
                                pandaunCheck -= 1;
                            }
                        }
                    },
                    onCheck: function (node, checked) {
                        pandaunCheck += 1;
                        //alert("onCheck" + pandaunCheck);
                        if (checked == true) {
                            if (pandaun != node.data.id) {
                                if (node.data.IconCls == "1") {
                                    document.getElementById("hdF_FunctionId").value += node.data.id + ",";
                                    pandaun = node.data.id;
                                }
                                else {
                                    document.getElementById("hdF_ModuleId").value += node.data.id + ",";
                                    pandaun = node.data.id;
                                }
                            }
                        }
                        else {
                            pandaun = 0;
                            if (node.data.IconCls == "1") {
                                var place = node.data.id + ",";
                                document.getElementById("hdF_FunctionId").value = document.getElementById("hdF_FunctionId").value.replace("" + place + "", "");
                            }
                            else {
                                var place = node.data.id + ",";
                                document.getElementById("hdF_ModuleId").value = document.getElementById("hdF_ModuleId").value.replace("" + place + "", "");
                            }
                        }
                    }

                });
            }
            catch (e) {
                alert(e.Message);
            }
        }
        function grid() {
            $("#divDataList").ligerGrid({
                height: '97%',
                width: 280,
                columns: [
                { display: 'Id', name: '_f_roleid', width: '1%', hide: 'Id' },
                { display: '角色名称', width: '86%', name: '_f_rolename' }
                ], url: 'ajax/rolelist.ashx?action=getlist', pageSize: 10, rownumbers: true,
                onAfterShowData: function (data) {
                    //var vheight = document.body.clientHeight;
                    var vheight = $("#divDataList").height();
                    document.getElementById("divTree").style.height = vheight;
                },
                onSelectRow: function (data, rowindex, rowobj) {
                    count += 1;
                    counts = count;
                    singleClick = data._f_roleid;
                    $.ajax({
                        async: false,
                        type: "Post",
                        url: "rolelist.aspx/GetID",
                        //方法传参的写法一定要对，str为形参的名字,str2为第二个形参的名字
                        data: "{'id':'" + singleClick + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            //返回的数据用data.d获取内容
                            var str1 = data.d;
                            var str = new Array();
                            str = str1.split('@');
                            if (str.length = 2) {
                                document.getElementById("hdF_FunctionId").value = str[0];
                                document.getElementById("hdF_ModuleId").value = str[1];
                                categorytree = null;
                                tree();
                            }
                        },
                        error: function (err) {

                        }
                    });
                }
            });
            $("#pageloading").hide();
        }
        $(function () {
        try
        {
            var vheight = document.body.clientHeight;
            document.getElementById("tableMessage").style.height = vheight - 80;
            document.getElementById("divTree").style.height = vheight - 80;
        }
        catch (e)
            { }

            menu = $.ligerMenu({ top: 100, left: 100, width: 120, items:
            [
            { text: '增加', click: itemclick, icon: 'add' },
            { text: '修改', click: itemclick },
            { line: true },
            { text: '查看', click: itemclick }
            ]
            });
            categorytree = null;
            tree();
            grid();
        });

        function Add() {
            $.ligerDialog.open({ url: 'rolelistedit.aspx?action=Add', title: '添加角色信息', height: 280, width: 600, isResize: true
            });
        }

        function Modify() {
            if (singleClick == "" || singleClick == undefined) {
                $.ligerDialog.error("请选择修改行！");
            } else {
                $.ligerDialog.open({ url: 'rolelistedit.aspx?action=Edit' + '&ID=' + singleClick, title: '修改角色信息', height: 280, width: 600, isResize: true
                });
            }
        }

        function Delete() {
            try {
                if (singleClick == "" || singleClick == undefined) {
                    $.ligerDialog.error("没有选择要删除的行！");
                } else {
                    $.ligerDialog.confirm('确定要删除选择的记录吗？', function (yes) {
                        if (yes) {
                            try {
                                $.post("ajax/rolelist.ashx?action=deletelist&id=" + singleClick, function (data) {
                                    if (data == "success") {
                                        $.ligerDialog.success('删除成功');
                                        grid();
                                    }
                                    else {
                                        $.ligerDialog.error('删除失败');
                                    }
                                });
                            }
                            catch (e) {
                                alert(e.Message);
                            }
                        }
                        else {
                        }
                    });
                }
            }
            catch (e) {
                $.ligerDialog.error(e.Message);
            }
        }

        function All() {
            $.post("ajax/rolelist.ashx?action=save&F_FunctionId=" + document.getElementById("hdF_FunctionId").value + "&F_ModuleId=" + document.getElementById("hdF_ModuleId").value + "&RoleID=" + singleClick, function (data) {
                if (data == "success") {
                    $.ligerDialog.success('保存角色权限成功');
                }
                else {
                    $.ligerDialog.error('保存角色权限失败');
                }
            });
        }
        document.onkeydown = function (event) {
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e && e.keyCode == 13) {
                LoadList();
            }
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="tools_box">
        <asp:HiddenField ID="hdF_FunctionId" runat="server" />
        <asp:HiddenField ID="hdF_ModuleId" runat="server" />
        <div class="tools_bar">
            <a class="tools_btn" href="#" onclick="Add();"><span><b class="add">添加</b></span>
            </a><a class="tools_btn" href="#" onclick="Modify();"><span><b class="modify">修改</b></span>
            </a><a class="tools_btn" href="#" onclick="Delete();"><span><b class="delete">删除</b></span>
            </a><a id="A1" href="#" runat="server" onclick="All();" class="tools_btn"><span><b
                class="all">保存角色权限</b></span> </a>
            <div class="search_box">
                角色名称：<asp:TextBox ID="txtKeywords" runat="server" CssClass="txtInput"></asp:TextBox>&nbsp;&nbsp;
                <input id="btnSearch" type="button" value="搜 索" class="btnSearch" onclick="LoadList();" />
            </div>
        </div>
    </div>
    <table id="tableMessage" cellpadding="3" cellspacing="3" border="0" style="width: 100%;">
        <tr>
            <td valign="top" style="width: 280px; padding: 0px 2px 5px 2px;">
                <div class="tools_box" style="height: 30px;">
                    <div class="tools_bar">
                        <div style="float: left; padding-top: 6px; padding-left: 1px; font-weight: bold;
                            color: red;">
                            <img src="../images/ico_16_2.gif" />&nbsp;角色列表</div>
                    </div>
                </div>
                <div id="divDataList">
                </div>
            </td>
            <td valign="top" style="padding: 0px 2px 5px 2px;">
                <div class="tools_box" style="height: 30px;">
                    <div class="tools_bar">
                        <div style="float: left; padding-top: 6px; padding-left: 1px; font-weight: bold;
                            color: red;">
                            <img src="../images/icon_site.gif" />&nbsp;权限设置</div>
                    </div>
                </div>
                <table id="tableTree" cellpadding="0" cellspacing="0" style="width: 100%; background-color: White;
                    border: 1px solid #D6D6D6;">
                    <tr>
                        <td valign="top">
                            <div id="divTree" style="overflow: auto;">
                                <ul id="tree1">
                                    <li isexpand="false" id="-1"><span>权限设置</span>
                                        <ul>
                                        </ul>
                                    </li>
                                </ul>
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
