<%@ Page Title="" Language="C#" MasterPageFile="../BaseMaster.Master" CodeBehind="AdminGroupDetail.aspx.cs" Inherits="WAP2P.Web.PC.Admin.Sys.AdminGroupDetail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="header" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
    <form class="auto" method="post" action="" beforeSubmit="var val = ''; $('#loginAreaul li').each(function(i,n) { val += $(n).attr('data-id') + '|' });$('#loginAreaFilter').val(val);" onsuccess="parent.$.jPopupEdit.close(true);">
        <div class="m-editbar">
            <input type="submit" class="btn-larger c-priority iconfont" value="&#xe684; 保存" /> 
            <input type="button" class="btn-larger c-normal iconfont" value="&#xe634; 关闭" onclick="parent.$.jPopupEdit.close();" />
        </div>
        <div class="m-content m-editcontent">        
            <table class="m-info" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <th>操作组名称</th>
                    <td><input type="text" name="name" class="w250" data-vtype="must" placeholder="请输入适合的操作组名称" value="<% =Model.Name.HtmlEncode() %>" maxlength="50" data-vmsg="请输入操作组名称" /></td>
                </tr>
                <ruson:PermissionSpace runat="server" Module="系统设置" Function="操作组设置" Operate="设置权限">
                <tr>
                    <th>仅允许查看组内资料</th>
                    <td><% =HtmlHelper.CheckBox("viewOnlyGroup" , "是" , Model.ViewOnlyGroup) %></td>  
                </tr>
                </ruson:PermissionSpace>
                <tr>
                    <th>限制登录地区</th>
                    <td>
                        选择地区 <span id="area"></span> <input type="button"  class="btn-base c-priority iconfont" value="&#xe67a; 添加" id="btnAddArea" />
                        <ul id="loginAreaul" class="ui-termselect">
                            <asp:Repeater runat="server" ID="rptLoginAreaFilter" ItemType="WAP2P.Sys.Area">
                                <ItemTemplate>
                                    <li class="btn-smaller c-important" data-id="<%# Item.Id  %>"><%# Item.GetParentsAndSelf().Select(item => item.Name).Join(" ") %><i onclick="$(this).closest('li').remove();"class="iconfont fcyellow-1">&#xe65a;</i></li>
                                </ItemTemplate>
                            </asp:Repeater>
                        </ul>
                        <input type="hidden" name="loginAreaFilter" id="loginAreaFilter" value="<% =Model.LoginAreaFilter.HtmlEncode() %>" />
                    </td>
                </tr>
                <tr>
                    <th>操作组备注</th>
                    <td>
                        <textarea name="description"><% =Model.Description.HtmlEncode() %></textarea>
                    </td>
                </tr>
            </table>
            <ruson:PermissionSpace runat="server" Module="系统设置" Function="操作组设置" Operate="设置权限">
            <table class="m-info" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <th class="info-listhead" colspan="2">
                        整站权限设置 
                    </th>
                </tr>
                <tr>
                    <td class="g-fcenter">
                            替换组权限：
                        <ruson:Select runat="server" ID="copyGroup" TipsText="从现有操作组复制" class="ml10">
                        </ruson:Select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <table cellpadding="0" cellspacing="0" width="100%" class="m-permission">
                            <asp:Repeater runat="server" ID="rptPermisstionModule">
                                <ItemTemplate>
                                    <tr><td colspan="4"><div class="ui-checkbox"><label><input type="checkbox" class="module" /> <%# Container.DataItem %></label></div></td></tr>
                                    <tr>
                                        <asp:Repeater runat="server" ID="rptPermisstionFunction">
                                            <ItemTemplate>
                                                <td>
                                                    <dl>
                                                        <dt><div class="ui-checkbox"><label><input type="checkbox" class="fun" name="permissions" value="<%# moduleName + "|" + (string)Container.DataItem + "|" %>" <%# permission != null && permission.HavePermission(moduleName, (string)Container.DataItem) ? "checked=\"checked\"" : string.Empty %> /> <%# Container.DataItem %></label></div></dt>
                                                        <asp:Repeater runat="server" ID="rptPermisstionOper">
                                                            <ItemTemplate>
                                                                <dd><div class="ui-checkbox"><label><input type="checkbox" name="permissions" value="<%# moduleName + "|" +  funName + "|" + (string)Container.DataItem %>" <%# permission != null && permission.HavePermission(moduleName, funName, (string)Container.DataItem) ? "checked=\"checked\"" : string.Empty %> /> <%# Container.DataItem %></label></div></dd>
                                                            </ItemTemplate>
                                                        </asp:Repeater>
                                                    </dl>
                                                </td>
                                                <%# (Container.ItemIndex + 1) % 4 == 0 ? "</tr><tr>" : string.Empty %>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </tr>
                                    <tr class="split"><td colspan="4"></td></tr>
                                </ItemTemplate>
                            </asp:Repeater>
                        </table>
                    </td>
                </tr>
            </table> 
               </ruson:PermissionSpace>                   
        </div>
    </form>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="script" runat="server">
    <script src="<% =this.ImportJsCss("../res/core/scripts/permission.js") %>"></script>
    <script src="<% =this.ImportJsCss("../../res/core/scripts/areadata.js") %>"></script>
    <script>
        initPermissionParentStatus();

        //限制登录地区编辑
        $('#area').cascade({ data: areadata, names: ['province', 'city', 'area'], emptyTip: '全部' });

        var loginAreaUl = $('#loginAreaul'), loginAreaFilter = $('#loginAreaFilter');
        $('#btnAddArea').click(function () {
            var val = '', txt = '', ok = true;
            $('#area select').each(function (i, n) {
                var v = $(n).val();
                if (v) {
                    val = v;
                    txt += $(':selected', n).text() + ' ';

                    if (loginAreaUl.find('li[data-id="' + val + '"]').length > 0) {
                        ok = false;
                        $.jError('所选地区已存在');                        
                        return false;
                    }
                }
            });
            if (ok && val) loginAreaUl.append('<li class="btn-smaller c-important" data-id="' + val + '">' + txt + '<i onclick="$(this).closest(\'li\').remove();" class="iconfont fcyellow-1">&#xe65a;</i></li>');
        });

        $('#copyGroup').change(function () {
            var me = $(this), val = me.val();
            if (val) {
                $.jConfirm('选择的管理组权限将替换当前权限，您确定吗？', function () {
                    ajaxGroupPermisstions(val);
                });

                me.val('');
            }
        });

        function ajaxGroupPermisstions(gid) {
            $.ajax({
                url: "?action=groupPermission&gid=" + gid,
                dataType: "json",
                success: function (res) {
                    res = res.Value;
                    var checked = [];
                    for (var module in res) {
                        for (var fun in res[module]) {
                            checked.push(module + '|' + fun + '|');
                            for (var i = 0; i <= res[module][fun].length; i++) {
                                checked.push(module + '|' + fun + '|' + res[module][fun][i]);
                            }
                        }
                    }

                    $('table.m-permission :checkbox[name=permissions]').each(function (i, n) {
                        var n = $(n);
                        if (checked.indexOf(n.val()) != -1)
                            n[0].checked = true;                            
                        else
                            n[0].checked = false;
                    });

                    initPermissionParentStatus();
                }
            });
        };
    </script>
</asp:Content>