<%@ Page Title="" Language="C#" MasterPageFile="../BaseMaster.Master" CodeBehind="AdminDetail.aspx.cs" Inherits="WAP2P.Web.PC.Admin.Sys.AdminDetail" %>
<asp:Content ID="Content1" 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 rowspan="3" width="15%">操作员头像</th>
                    <td rowspan="3" id="f" width="35%">
                        <div id="faceResult" class="mb10">
                            <% =string.IsNullOrWhiteSpace(Model.Face) ? string.Empty : string.Format("<img src=\"{0}\", alt=\"\" />", Model.Face) %>
                        </div>
                        <div class="pl136" > 
                            <input type="hidden" name="face" id="face" value="<% =Model.Face.HtmlEncode() %>"/>
                        </div>
                        <input type="file" id="faceFile" name="js-file" />
                        <em>请上传尺寸为 <i class="fcred-3">120 X 120 像素</i> 的头像</em>
                    </td> 
                    <th width="15%">操作员账号</th>
                    <td width="35%">
                        <input type="text" name="name" id="name" class="w150" maxlength="50" placeholder="请输入登录账号" data-vtype="must" data-vmsg="请输入操作员账户" value="<% =Model.Name.HtmlEncode() %>" />
                        <%= IsNew ? string.Empty : string.Format(@" <a href=""javascript:;"" onclick=""utils.copy('{0}');"">复制推荐网址</a>", (string.IsNullOrEmpty(SiteUrl) ? Context.GetAppFullPath() : SiteUrl) + string.Format("User/Register{0}?r=a{1}", PageExt, Model.Id)) %>
                    </td>

                </tr>
                <tr>
                   <th>操作员密码</th>
                   <td>
                       <input type="password" name="password" placeholder="请输入登录密码"  class="w150" maxlength="50" <% =IsNew ? "data-vtype=\"must\" data-vmsg=\"请输入操作员密码\"" : string.Empty %> />
                        <% =IsNew ? string.Empty : "<em>不填则不修改</em>" %>
                    </td>   
                </tr>
                <tr>
                    <th>所属操作组</th>
                    <td>
                        <% if(IsNew || CurrentAdmin.HavePermission("系统设置", "操作员账号设置", "设置权限")) { %>
                          <ruson:Select runat="server" ID="groupId" TipsText="请选择所属操作组" data-vtype="must" data-vmsg="请选择所属操作组"></ruson:Select>
                        <% } else { %>
                            <% =Model.GetGroup().Name %>
                        <% } %>
                        
                    </td>
                </tr>
                <tr>
                    <th>管理员昵称</th>
                    <td><input type="text" name="nickName" placeholder="请输入前台显示昵称"  class="w150" maxlength="50" value="<% =Model.Nickname %>" /></td>        
                    <th>手机号码</th>
                    <td><input type="text" name="phone" placeholder="请输入手机号码" class="w150" maxlength="20" data-vtype="phone" data-vmust="false" data-vmsg="手机号码格式错误" value="<% =Model.Phone.HtmlEncode() %>" /></td>                              
                </tr>
                <tr>
                    <th>电子邮箱</th>
                    <td><input type="text" name="email" placeholder="请输入电子邮箱" class="w150" maxlength="100" data-vtype="email" data-vmust="false" data-vmsg="电子邮箱格式错误" value="<% =Model.Email.HtmlEncode() %>" /></td>
                     <th>QQ号码</th>
                    <td><input type="text" name="qq" placeholder="请输入工作QQ" class="w150" maxlength="20" data-vmust="false" data-vtype="qq" data-vmsg="QQ号码不正确" value="<% =Model.QQ.HtmlEncode() %>" /></td>         
                </tr>
                <ruson:PermissionSpace runat="server" Module="系统设置" Function="操作员账号设置" Operate="设置权限">                
                <tr>
                    <th>是否锁定账号</th>
                    <td><% =HtmlHelper.CheckBox("isLock" , "锁定" , Model.IsLock) %></td>
                    <th>是否加入客服列表</th>
                    <td><% =HtmlHelper.CheckBox("isService" , "加入" , Model.IsService) %></td>                 
                </tr>

                <tr>
                    <th>仅允许查看自己帐号信息</th>
                    <td><% =HtmlHelper.CheckBox("viewOnlySlef" , "是" , Model.ViewOnlySlef) %></td>  
                    <th>仅允许查看名下会员</th>
                    <td><% =HtmlHelper.CheckBox("viewUserOnlySelf" , "是" , Model.ViewUserOnlySelf) %></td>  

                </tr>
                <tr>
                    <th>额外允许登录的区域<br />(除所属操作组以外)</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>
                    <th>连续登录错误次数</th>
                    <td>
                        <input type="text" name="loginErrorCount" value="<% =Model.LoginErrorCount %>" class="w60 ui-int" data-vtype="number" data-vmsg="请输入正确的数据值" />  次
                        <em style="<% =GlobalSetting.Get<int>(GlobalSetting.Keys.Security.LoginErrorLockN) == 0 ? "display:none;" : string.Empty %>">连续登录错误 <% =GlobalSetting.Get<int>(GlobalSetting.Keys.Security.LoginErrorLockN) %> 次后，将在 <% =GlobalSetting.Get<int>(GlobalSetting.Keys.Security.LoginErrorLockTime) %> 分钟内禁止登录</em>
                    </td> 
                </tr> 
                </ruson:PermissionSpace>  
                <tr>
                     <th>最后登录情况</th>
                    <td><% =string.IsNullOrEmpty(Model.LastLoginIP) ? string.Empty : Area.GetLocationString(Model.LastLoginIP) + "(" + Model.LastLoginIP + ")" %><br />
                        <% =Model.LastLoginAt.ToDateTimeString() %></td>                     
                    <th>登录次数</th>
                    <td><% =Model.LoginCount %> 次</td>   
                </tr>          
                <tr>
                    <th>备注</th>
                    <td colspan="3"><textarea name="remark"><% =Model.Remark.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="copyAdmin" TipsText="从现有操作员复制" class="ml10">
                        </ruson:Select>
                        <span class="ml10">
                            同步当前权限至：
                            <input type="text" name="permissionCopyTo" id="permissionCopyTo" value="" class="w138 ml10" />
                            <input type="button" class="btn-base c-normal iconfont g-valign" value="&#xe60f;" id="permissionCopy" />
                        </span>
                    </td>
                </tr>

                <tr>
                    <td>
                        <table cellpadding="0" cellspacing="0" width="100%" class="m-permission" id="js-permission">
                            <ruson:Space runat="server" ID="permissionSpace">
                                <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 %>" class="" <%# 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>
                            </ruson:Space>
                        </table>                        
                    </td>
                </tr>
            </table>
            </ruson:PermissionSpace>
        </div>
    </form>
</asp:Content>
<asp:Content ID="Content2" 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>
        //限制登录地区编辑
        $('#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>');
        });

        setTimeout(function () {
            $('#faceFile').uploadify({
                width: 120,
                height: 32,
                multi: false,
                removeTimeout: 0,
                swf: '../res/uploadify/uploadify.swf?v=<% =CryptoHelper.Random(100000,999999) %>',
                uploader: '../res/uploadify/SwfUpload.aspx?type=image&width=120&height=120',
                buttonClass: 'iconfont',
                buttonText: '&#xe629; 上传头像',
                fileTypeExts: '<% =WAP2P.Web.PC.Admin.Res.uploadify.SwfUpload.AllowImages %>',
                formData: {
                    '<% =WAP2P.Web.Admin.Membership.CookieName %>': '<% =Request.Cookies[WAP2P.Web.Admin.Membership.CookieName].Value %>'
                },
                onUploadSuccess: function (res, data) {
                    eval('var d = ' + data);
                    if (d.Success) {
                        $('#face').val(d.Message).trigger('blur');
                        $('#faceResult').html('<img src="' + d.Message + '" />');
                    } else {
                        $.jError(d.Message);
                    }
                }
            });
        }, 10);

        //权限相关
        function ajaxGroupPermisstions(str) {
            $.ajax({
                url: '?action=groupPermission&id=<% =Model.Id %>&gid=' + str,                                
                success: function (res) {
                    $('#js-permission').html(res);
                    initPermissionParentStatus();
                }
            });

            $.ajax({
                url: '?action=getAdmins&id=<% =Model.Id %>&gid=' + str,
                dataType: 'json',
                success: function (res) {
                    var adminSelect = $('#copyAdmin');
                    adminSelect[0].length = 0;
                    adminSelect.append('<option value="">从现有操作员复制</option>')

                    if (res && res.length) {
                        $.each(res, function (i, n) {
                            adminSelect.append('<option value="' + n.Id + '">' + n.Name + (n.Nickname == "" ? n.Nickname : '(' + n.Nickname + ')') + '</option>')
                        });
                    }                    
                }
            });
        };

        var groupVal = $('#groupId').val();
        if (groupVal) {
            ajaxGroupPermisstions(groupVal);
        }

        $('#groupId').change(function () {
            ajaxGroupPermisstions($(this).val());
        });

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

                me.val('');
            }
        });
        function ajaxAdminPermisstions(aid) {
            $.ajax({
                url: "?action=adminPermission&id=<% =Model.Id %>&aid=" + aid,
                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();
                }
            });
        };

        $('#permissionCopy').click(function () {
            var groupId = $('#groupId').val();
            $.jPopupEdit('将权限设置同步到', '../Common/AdminSelect.aspx?fn=selectAdmin&groupId=' + groupId);
        });

        function selectAdmin(obj) {
            var to = $('#permissionCopyTo'),
                val = ',' + to.val() + ',';
            if (obj && obj.admins && obj.admins.length)
            {
                $.each(obj.admins, function (i, n) {
                    
                    if (n.name != '<% =Model.Name %>' && val.indexOf(',' + n.name + ',') == -1)
                        val += n.name + ',';
                });
            }
            to.val(val.replace(/^,+|,+$/g, ''));
        }
    </script>
</asp:Content>