<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="authorizationSet.aspx.cs" Inherits="Czou2012.UI.Manager.AdminUser.authorizationSet" %>

<!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 runat="server">
    <title>权限管理</title>
        <link type="text/css" rel="stylesheet" href="../Styles/style.css" />
     <link type="text/css" rel="stylesheet" href="../Styles/pagination.css" />
     <link type="text/css" rel="stylesheet" href="../Styles/table.css" />
     <link rel="stylesheet" type="text/css" href="../Scripts/themes/default/easyui.css" />
    <script type="text/javascript" src="../Scripts/jquery.min.js"></script>
    <script type="text/javascript" src="../Scripts/jquery.form.js"></script>
    <script type="text/javascript" src="../Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../Scripts/jquery.fixedtableheader.min.js"></script>
	<script type="text/javascript" language="javascript">
	    function equals(strA, strB) {
	        var n;
	        if (strA.length != strB.length)
	            return false;
	        n = strA.length;
	        for (k = 0; k < n; k++) {
	            if (strA.charCodeAt(k) != strB.charCodeAt(k)) {
	                return false;
	            }
	        }
	        return true;
	    }

	    function isParent(name, parentName) {
	        var parentAction = parentName.substring(0, 1);
	        var parentId = parentName.substring(1);
	        //父类ID数组
	        var parentCode = parentId.split("_");
	        if (parentCode == null) {
	            alert("程序出错,请重试!");
	        }
	        else {
	            for (i = 1; i < parentCode.length; i++) {
	                parentCode[i] = parentCode[i - 1] + "_" + parentCode[i];
	            }
	        }

	        //选择或者不选择
	        var flag = $("#"+parentName).attr("checked"); 

	        var testCode = name.substring(1);
	        var testAction = name.substring(0, 1);

	        for (i = 0; i < parentCode.length; i++) {
	            if (equals(parentCode[i], testCode)) {
	                if (equals(parentAction, testAction)) {
	                    return true;
	                }
	                if (parentAction == "c" || (parentAction == "d" && testAction == "r")) {
	                    return true;
	                }
	                if (parentAction == "m" && (testAction == "r" || testAction == "w")) {
	                    return true;
	                }
	                if (parentAction == "w" && testAction == "r") {
	                    return true;
	                }
	            }
	        }
	        return false;
	    }


	    function setSubClass(parentName) {

	        var action = parentName.substring(0, 1);
	     
	        var parentCode = parentName.substring(1);
	        // var flag = document.all[parentName].checked; //选择或者不选择
	        var flag = $("#" + parentName).is(':checked');
	        var count = $(":input[name='chkAll']").length;
	        for (var i = 0; i < count; i++) {
	            var  objname = $(":input[name='chkAll']").eq(i).attr("id");
	            //过滤无关的组件检查
	            var parCode = ""
	            parPos = parentCode.indexOf("_");
	            if (parPos == -1) {
	                parCode = parentCode;
	            }
	            else {
	                parCode = parentCode.substring(0, parPos);
	            }
	            if (objname.indexOf(parCode) < 0) {
	                continue;
	            }
	            else {
	                var xxx = objname.charAt(objname.indexOf(parCode) + parCode.length);
	                if (xxx >= "0" && xxx <= "9") {
	                    continue;
	                }
	            }

	            if (objname.indexOf(parentName) == 0) {
                $("#"+objname).attr("checked",flag);
	            }
	            if (action == "r") {
	                if (!flag) {//当去掉读权限时，把其它权限也去掉
	                    if (objname.indexOf("c" + parentCode) == 0 || objname.indexOf("w" + parentCode) == 0
						|| objname.indexOf("m" + parentCode) == 0 || objname.indexOf("d" + parentCode) == 0) {	                     
	                        $("#" + objname).attr("checked", flag);
	                    }
	                }
	            }
	            if (action == "w") {
	                if (flag) {
	                    if (objname.indexOf("r" + parentCode) == 0) {	                      
	                        $("#" + objname).attr("checked", flag);
	                    }
	                }
	            }
	            if (action == "m") {
	                if (flag) {
	                    if (objname.indexOf("r" + parentCode) == 0 || objname.indexOf("w" + parentCode) == 0) {
	                        $("#" + objname).attr("checked", flag);
	                    }
	                }
	            }
	            if (action == "d") {
	                if (flag) {
	                    if (objname.indexOf("r" + parentCode) == 0) {
	                        $("#" + objname).attr("checked", flag);
	                    }
	                }
	            }
	            if (action == "c") {
	                if (flag) {
	                    if (objname.indexOf("r" + parentCode) == 0 || objname.indexOf("w" + parentCode) == 0
						|| objname.indexOf("m" + parentCode) == 0 || objname.indexOf("d" + parentCode) == 0) {
	                        $("#" + objname).attr("checked", flag);
	                    }
	                }
	            }
	            if (flag) {//当选择某项时，应把相差父权限项也选上
	                if (isParent(objname, parentName)) {
	                    $("#" + objname).attr("checked", flag);
	                }
	            }

	            //}
	        }
	    }
	    function handle(name) {
	        setSubClass(name);
	    }
	    //选择或取消所有选择框
	    function CheckAll() {
	        if ($("#AllPowers").attr("checked") == true) {
	            $("form input:checkbox").each(function (i) {
	          	         $("form input:checkbox").eq(i).attr("checked", true);
	     	    })
	        }
	        else {
	            $("form input:checkbox").each(function (i) {	            
	                    $("form input:checkbox").eq(i).attr("checked", false);	
	            })
            
            };
	        }

	        //页面属性 Start--------------------------------------------------------------/
	        $(function () {	         
	            $("#infoTable").fixedtableheader({ headerrowsize: 1 });
	        })
		</script>
	</head>
	<body>
		<form id="frmAuthorization" method="post">
			<!--是否提交标志-->
			<input type="hidden" id="hidPost" name="hidPost" runat="server"/>
			<asp:Label id="lblPower" runat="server"></asp:Label>
		</form>
	</body>
</html>
