<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true"
    CodeBehind="RolePermissionSet.aspx.cs" Inherits="OAWeb.Role.RolePermissionSet" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlace" runat="server">
    <style>
        .table_list th, .table_list td
        {
            text-align: left;
        }
        .table_list td
        {
            padding: 0px;
        }
        .role_span
        {
        	width:135px;
            margin-left: 10px;
            display: block;
            float: left;
            height:24px;
             margin:3px 0px;
        }
        .role_span select { border:solid 1px #cccccc;color:Red; }
        .role_span select option { color:Red; }
        .per_all { text-decoration:underline;}
        .op_all { width:80px;}
    </style>
    <div class="page_main">
        <div class="page_content">
            <table class="data_title" cellspacing="3">
                <tr>
                    <td class="data_caption">
                        设置角色“<asp:Label ID="lblRoleName" runat="server" Text=""> </asp:Label>”的权限
                    </td>
                </tr>
                <tr>
                    <td class="data_field">
                        [<asp:Label ID="lblRemark" runat="server" Text=""></asp:Label>]
                    </td>
                </tr>
            </table>
            <table class="table_list" cellspacing="0" cellpadding="0" border="0">
                <tr>
                    <th scope="col">
                        资源对象
                    </th>
                    <th scope="col">
                        权限操作
                    </th>
                    <th scope="col">
                        &nbsp;
                    </th>
                </tr>
                <%=LoadRolePermissionHTML()%>
                <tr>
                    <td align="center" colspan="3" style="padding:10px 0px;">
                        <input id="btnSave" type="button" value=" 保 存 " class="btn_77px" />
                        <input id="btnClose" type="button" value=" 返 回 " onclick="window.location.href = '<%=ReturnUrl %>'"
                            class="btn_77px" />
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".per_all").live("click",function(){                
                $.each($(this).parent().parent().find('input[type="checkbox"]'), function (n,value) {
                     $(this).attr("checked", "true");           
                });
            })
            $("#btnSave").click(function () {
                var pId = [];
                var scopes = [];
                $('input[type="checkbox"]:checked').each(function () { 
                    pId.push($(this).val());
                    var select = $(this).parent().find("select");
                    if(select.length > 0)
                    {
                        scopes.push(select.attr("name") + "=" + select.val());
                    }                    
                });
                $.ajax({
                    type: "POST",
                    url: "RolePermissionSet.aspx",
                    async: false, //同步请求
                    data: "op=Save&pId=" + escape(pId.join(",")) + "&scope=" + escape(scopes.join("&")) + "&RoleId=<%=RoleId %>",
                    success: function (data, textStatus) {
                        if (data == "true") {
                            alert("保存成功");
                            window.location.href = '<%=ReturnUrl %>';
                        }
                        else { alert("保存失败"); }
                    }
                });
            })

            var Ids = [<%=GetRolePermissionIds() %>];
            var Scope = eval("({<%=GetRoleScopes() %>})");
            $.each(Ids, function (n,value) {
                $('input[type="checkbox"]').each(function () { 
                   if($(this).val() == value){
                      $(this).attr("checked", "true");
                   } 
                });               
            });
             $.each(Scope, function (n,value) {
                $('select').each(function () { 
                   if($(this).attr("name") == n){
                      $(this).val(value);
                   } 
                });
            });
        });
    </script>
</asp:Content>
