<%@ Page Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true"
    EnableViewState="false" CodeBehind="RolePermissions.aspx.cs" Inherits="PowerEasy.Module.General.WebSite.Admin.User.RolePermissionsManage"
    Title="角色权限设置" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CphNavigation" runat="server">
    <pe:ExtendedSiteMapPath ID="SmpNavigator" SiteMapProvider="AdminMapProvider" runat="server" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CphContent" runat="server">
    <table width="100%" border="0" cellpadding="2" cellspacing="1" class="border">
        <tr align="center">
            <td colspan="2" class="spacingtitle">
                <b>角色权限设置</b>
            </td>
        </tr>
        <tr class="tdbg">
            <td class="tdbgleft" align="right" style="width: 150px; height: 30px;">
                <strong>角色名：</strong>
            </td>
            <td>
                <asp:Label ID="LblRoleName" runat="server" Text="" />
            </td>
        </tr>
        <tr class="tdbg">
            <td class="tdbgleft" align="right" style="height: 79px">
                <strong>角色描述：</strong>
            </td>
            <td style="height: 79px">
                <asp:Label ID="LblDescription" runat="server" Text="" />
            </td>
        </tr>
        <tr class="tdbg">
            <td class="tdbgleft" align="right" style="width: 150px;">
                <strong>成员个数：</strong>
            </td>
            <td style="height: 30px;">
                <a href="AdministratorManage.aspx?RoleId=<%=RoleId %>">
                    <asp:Label ID="LblRoleCount" runat="server" Text="" /></a>
            </td>
        </tr>
    </table>
    <br />
    <table width="100%" cellpadding="2" cellspacing="1">
        <tr align="center">
            <td colspan="2" class="spacingtitle">
                <b>常规模块权限设置 </b>
            </td>
        </tr>
        <tr class="tdbg">
            <td align="left" class="tdbg" colspan="2" valign="top" style="padding-left: 2px;">
                <fieldset id="ModelPurview" style="border: 1px solid #FFFFFF;">
                    <table width="100%" border="0" cellpadding="0" cellspacing="1" class="tdbg">
                        <pe:ExtendedLabel HtmlEncode="false" ID="LblModelPurview" Text="" runat="server" />
                    </table>
                </fieldset>
            </td>
        </tr>
    </table>
    <br />
    <asp:HiddenField ID="HdnKeyword" Value="0" runat="server" />
    <pe:FloatDivDialog ID="FdvShowWindow" runat="server" EnableViewState="false" Width="800"
        Height="430" Enabled="true">
    </pe:FloatDivDialog>
    <pe:FloatDivDialog ID="FDScopeSetting" runat="server" EnableViewState="false" Width="700"
        Height="400" IsGetContainerID="true">
    </pe:FloatDivDialog>
    <center>
        <br />
        <asp:Button ID="BtnSubmit" runat="server" Text="保存角色权限设置" OnClick="BtnSubmit_Click" />&nbsp;&nbsp;
        <asp:Button ID="BtnCancle" runat="server" Text="返回角色管理" ValidationGroup="BtnCancleValidationGroup"
            OnClick="BtnCancle_Click" />
    </center>
    <script language="javascript" id="check" type="text/javascript"> 
    function ShowRolesInfo(obj){
        var operateCode=obj.alt;
        var title="标题：拥有此权限的角色列表";
        var link="RoleList.aspx?operateCode="+operateCode;
        jQuery('.title').html(title);
        jQuery('#<%=FdvShowWindow.ClientID %>' + '__HdnLoadUrl').prop('value', link);
        jQuery('#<%=FdvShowWindow.ClientID %>' + '__LitID').click();
    }
    
    function ShowWindow(type){
        var strUrl = "";
        
        switch (type)
        {
            case 1:
                strUrl = "User/NodePermissions.aspx?PermissionsType=Role&Type=Content&RoleId=<%=Request["RoleId"]%>";
                break ;   
            case 2:
                strUrl = "User/SpecialPermissions.aspx?PermissionsType=Role&RoleId=<%=Request["RoleId"]%>";
                break ;    
            case 3:
                strUrl = "User/NodePermissions.aspx?PermissionsType=Role&Type=Comment&RoleId=<%=Request["RoleId"]%>";
                break ;
            case 4:
                strUrl = "User/NodePermissions.aspx?PermissionsType=Role&Type=Node&RoleId=<%=Request["RoleId"]%>";
                break ;
            default:
                break ;
        }
         var pe=new parent.PE_FrameTab.AddNew(strUrl); 
    }

    function ShowOperateSetting(operateCode){
        var title="标题：操作范围设置";
        var link="RoleScopePermissions.aspx?RoleId=<%=Request["RoleId"]%>&OperateCode="+operateCode;
        jQuery('.title').html(title);
        jQuery('#<%=FDScopeSetting.ClientID %>' + '__HdnLoadUrl').prop('value', link);
        jQuery('#<%=FDScopeSetting.ClientID %>' + '__LitID').click();
    }
        
    function CheckModel(obj){
    
	    var oSpanArr = document.getElementsByTagName('fieldset');
	    var j = oSpanArr.length;
		
	    //更改所有所有子节点的状态
	    for ( var i=0; i<j; i++ ) 
	    {    
		    if (oSpanArr[i].id != ""){       
			    var inputArr = oSpanArr[i].getElementsByTagName('input');
			    var m = inputArr.length
			    for ( var r=0; r< m; r++ ) 
			    {
				    var t = inputArr[r];
				    if (t.id){
				       if (t.id.substr(0,obj.id.length+1) == obj.id + '_')
				       t.checked = obj.checked;
				    }  
			    }
		    }
	    }
        //特殊情况处理，由于对管理员的管理需要有对会员的权限，因此此处在选择一般管理权限的时候需要选择相应的会员管理
        if(obj.value=="NormalAdministratorManage")
        {
            var inputArr1 = document.getElementsByTagName('input');
            var n=inputArr1.length;
            if(obj.checked)
            {
                for(var h=0;h<n;h++)
                {
                    if(inputArr1[h].value=="NormalAdministratorManage"||inputArr1[h].value=="UserAdd"||inputArr1[h].value=="UserSuperManage"||inputArr1[h].value=="UserManage")
                    {
                        inputArr1[h].checked=true;
                    }
                }
            }
            if(!obj.checked)
            {
                    var NorArray=new Array();
                    var tips="";
                    for(var h1=0;h1<n;h1++)
                    {
                        if(inputArr1[h1].value=="NormalAdministratorManage"||inputArr1[h1].value=="UserAdd"||inputArr1[h1].value=="UserSuperManage"||inputArr1[h1].value=="UserManage")
                        {
                            NorArray.push(inputArr1[h1]);
                
                        }
                    }
                    for(var len=0;len<NorArray.length;len++)
                    {
                        if(NorArray[len].value!=null&&NorArray[len].checked)
                        {
                           if(NorArray[len].value=="UserManage")
                           {
                                tips="会员管理";
                           } 
                           if(NorArray[len].value=="UserAdd")
                           {
                                tips+="-添加会员";
                           } 
                        }
                    }
                    if(tips!="")
                    {
                        if(confirm("您需要去除:"+tips+"的权限吗?"))
                        {
                            for(var len1=0;len1<NorArray.length;len1++)
                            {
                                NorArray[len1].checked=false;
                            }
                        }
                    }                   
                
            }

        }
        //同理，如果没有会员添加的权限，也是没有一般管理员的权限的
        if(obj.value=="UserAdd"||obj.value=="UserSuperManage"||obj.value=="UserManage")
        {
            var inputArr2 = document.getElementsByTagName('input');
            if(!obj.checked)
            {
                for(var h1=0;h1<inputArr2.length;h1++)
                {
                    if(inputArr2[h1].value=="NormalAdministratorManage")
                    {
                        inputArr2[h1].checked=false;
                    }
                }
            }
        }
		    
		//开始更改父节点的状态
		if(obj.checked==true){
			CheckParentModel(obj.id);
		}
		else{
			ChangeParentModel(obj.id);
		}
	}
	
	function CheckParentModel(objID){
		if(objID.indexOf("_") > 0)
		{
		    var parentid=objID.substr(0,objID.lastIndexOf("_"));
		    document.getElementById(parentid).checked=true;
		    CheckParentModel(parentid);
		}
	}
	function ChangeParentModel(objID){
		if(objID.indexOf("_") > 0)
		{
            var oSpanArr = document.getElementsByTagName('fieldset');
		    var j = oSpanArr.length;
		    var parentid=objID.substr(0,objID.lastIndexOf("_"));
		    document.getElementById(parentid).checked = false;

		    for ( var i=0; i<j; i++ ) 
		    {    
			    if (oSpanArr[i].id != ""){       
				    var inputArr = oSpanArr[i].getElementsByTagName('input');
				    var m = inputArr.length
				    
				    for ( var r=0; r< m; r++ ) 
				    {
					    var t = inputArr[r];
					    if (t.id){
					       if (t.id.substr(0,parentid.length+1) == parentid + '_'){
						       if(t.checked == true){
							       document.getElementById(parentid).checked = true;
							       break;
						       }
						    }
					    }  
				    }
			    }
		    }
		    ChangeParentModel(parentid);
		}
	}
    </script>
</asp:Content>
