<%@ Page Title="" Language="C#" MasterPageFile="../BaseMaster.Master" CodeBehind="AdminSelect.aspx.cs" Inherits="WAP2P.Web.PC.Admin.Common.AdminSelect" %>
<asp:Content ID="Content1" ContentPlaceHolderID="header" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
    <dl class="ui-tabs">
        <dt>
            <div class="m-editbar">
                <input type="button" id="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>
        </dt>
        <dd>
            <form action="?action=search&radio=<% =Request.QueryString["radio"] %>&service=<% =Request.QueryString["service"] %>" method="get" class="m-search">
                <table class="m-criteria" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <th>操作员筛选:</th>
                        <td>
                            <ruson:Select runat="server" ID="groupId" TipsText="全部操作员"></ruson:Select>
                            <ruson:Select runat="server" ID="type" FillRequestValue="true">
                                <option value="操作员名称">操作员名称</option>
                                <option value="操作员昵称">操作员昵称</option>
                                <option value="手机号码">手机号码</option>
                            </ruson:Select>
                            <input type="text" size="35" name="key" value="<% =Request.QueryString["key"].HtmlEncode() %>" />
                            <span class="ml20 js-inlinesubmit"><input type="submit" class="btn-base c-priority iconfont" value="&#xe60f; 搜索" /><input type="reset" class="btn-base c-normal iconfont" value="&#xe670; 清空条件" /></span>
                        </td>
                    </tr>                    
                </table>
            </form>
            <div class="m-content">
                <div class="m-oper">
                    <% =isRadio ? string.Empty : "<input type=\"button\" class=\"oper-clear btn-smaller c-normal selall iconfont\" value=\"&#xe612; 全选\" /><input type=\"button\" class=\"oper-clear btn-smaller c-normal selreverse iconfont\" value=\"&#xe644; 反选\" />" %>
                </div>
                <table class="m-list" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <th width="5%">选取</th>
                        <th width="40%" class="g-fleft">操作员</th>
                        <th width="20%">操作组</th>
                        <th width="20%" class="g-fleft">昵称</th>
                        <th width="15%">手机号码</th>                        
                    </tr>                
                </table>
            </div>
        </dd>
    </dl>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="script" runat="server">
    <script>
        var resultData = {
            adminGroups: null, //{ id: '1', name: 'Name' }
            admins: []       //{ id: '1', name: 'Name' }
        };

        $('#submit').click(function() {
            var fn = '<% =Request.QueryString["fn"] ?? string.Empty %>';
            if (fn && parent[fn]) {
                parent[fn](resultData);
                parent.$.jPopupEdit.close();
            }
        });

        //变更组
        var groupChange = function () {
            var option = $('#groupId :selected'), val = option.val();
            if (val == '') {
                resultData.adminGroups = null;
            } else {
                var obj = { id: val, name: $.trim(option.text()) };
                resultData.adminGroups = obj;
            }
        };
        $('#groupId').change(groupChange);

        var toggleChecked = function (dom) {
            var me = $(dom), obj = { id: me.val(), name: me.closest('td').next().text() };
            if (<% =isRadio ? "true" : "false" %>) {
                resultData.admins = [ obj ];
            } else {
                var idx = -1;
                for(var i = 0; i < resultData.admins.length; i++) {
                    if (resultData.admins[i].id == obj.id) {
                        idx = i;
                        break;
                    }
                }

                if (dom.checked) {
                    if (idx == -1) resultData.admins.push(obj);
                } else {
                    if (idx != -1) resultData.admins.splice(idx, 1);
                }
            }
        };

        //分页加载
        function loadInitChecked() {
            $('.m-content .m-list .js-select').each(function(i, n) {
                var id = $(n).val();
                var idx = -1;
                for(var i = 0; i < resultData.admins.length; i++) {
                    if (resultData.admins[i].id == id) {
                        idx = i;
                        break;
                    }
                }
                if (idx != -1)
                    n.checked = true;
            });
        };

        //点击
        $('.m-content .m-list').on('click', '.js-select', function () {
            toggleChecked(this);
        }).on('dblclick', '.js-select', function() {
            $('#submit').trigger('click');
        });

        $('.m-oper .selall').click(function () {
            setTimeout(function() {
                $('.m-content .m-list .js-select').each(function(i, n) {
                    toggleChecked(n);
                });
            }, 10);
        });
        $('.m-oper .selreverse').click(function () {
            setTimeout(function() {
                $('.m-content .m-list .js-select').each(function(i, n) {
                    toggleChecked(n);
                });
            }, 10);            
        });
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="list" runat="server">
    <ruson:Repater runat="server" ID="rptList" ItemType="WAP2P.Sys.Admin">
        <ItemTemplate>
            <tr>
                <td><input type="<% =isRadio ? "radio" : "checkbox" %>" name="select" value="<%# Item.Id %>" class="del js-select" /></td>
                <td class="g-fleft"><img alt="" src="<%# Item.Face %>" height="20" align="absmiddle" /><%# Item.Name %></td>
                <td><%# (Item.GetGroup() ?? new WAP2P.Sys.AdminGroup()).Name %></td>
                <td class="g-fleft"><%# Item.Nickname %></td>
                <td><%# Item.Phone %></td>
            </tr>   
        </ItemTemplate>
        <EmptyTemplate>
            <tr>
                <td colspan="5" class="g-fleft">暂无数据。</td>
            </tr>
        </EmptyTemplate>
    </ruson:Repater>
    <tr class="pager">
        <td colspan="5"><ruson:Pager runat="server" ID="pages" CssClass="pages" /><a href="<% =Request.RawUrl %>" class="g-hide"></a></td>
    </tr>
    <script type="text/html" class="js-run">loadInitChecked();</script>
</asp:Content>
