<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AdminPicker.aspx.cs" Inherits="PowerEasy.Module.General.WebSite.Admin.User.AdminPicker" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManger1" runat="server" />
    <asp:Panel ID="PnlMulitSelect" runat="server" Visible="false">
        <table width="100%" border="0" cellpadding="2" cellspacing="0" class="border" style="margin-bottom: 3px;">
            <tr class="title" style="height: 22">
                <td align="left">
                    <b>已经选定的管理员：</b>
                </td>
                <td align="right">
                </td>
            </tr>
            <tr class="tdbg">
                <td align="left">
                    <input type="text" id="UserNameList" size="60" maxlength="200" class="inputtext" />
                </td>
                <td align="center">
                    <input type="button" class="inputbutton" name="del1" onclick="delLast()" value="删除最后" />
                    <input type="button" class="inputbutton" name="del2" onclick="delAll()" value="删除全部" />
                </td>
            </tr>
        </table>
    </asp:Panel>
    <asp:Panel ID="PnlDepartmentList" runat="server" Style="float: left; width: 25%;">
        <pe:ExtendedGridView ID="EgvDepartmentList" runat="server" CheckBoxFieldHeaderWidth="3%"
            IsHoldState="True" SerialText="" AutoGenerateColumns="False">
            <Columns>
                <asp:TemplateField HeaderText="部门列表">
                    <ItemTemplate>
                        <span onclick='GetAdminList(<%# Eval("Key") %>)' style="cursor: pointer;">
                            <%#Eval("Value") %></span>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <SelectedRowStyle BackColor="#33CCFF" />
        </pe:ExtendedGridView>
    </asp:Panel>
    <div style="float: left; width: 74%; margin-left: 3px;">
        <asp:UpdatePanel ID="UpnlAdminList" runat="server" OnLoad="UpnlAdminList_Load">
            <ContentTemplate>
                <table width="100%" border="0" style="text-align: center" cellpadding="2" cellspacing="0"
                    class="border">
                    <tr class="title">
                        <td style="text-align: right">
                            查找管理员：
                            <asp:TextBox ID="TxtKeyWord" runat="server" />&nbsp;<asp:Button ID="BtnSearch" runat="server"
                                Text="查找" OnClick="BtnSearch_Click" />
                        </td>
                    </tr>
                    <tr>
                        <td align="center">
                            <asp:DataList ID="DlstAdmin" runat="server" CssClass="tdbg" RepeatColumns="5" RepeatDirection="Horizontal"
                                Width="100%" CellSpacing="2" Height="0px">
                                <ItemStyle HorizontalAlign="Center" Width="20%" />
                                <ItemTemplate>
                                    <span style='cursor: pointer;' onclick='<%#string.Format("ReturnValues(\"{0}\",\"{1}\")",Eval("AdminName"),Eval("AdminId"))  %>'>
                                        <%#Eval("AdminName")%></span>
                                </ItemTemplate>                                
                            </asp:DataList>
                            <asp:Table CellSpacing="1" CellPadding="0" BorderWidth="0px" Width="100%" 
                                CssClass="border" ID="TabEmplyTemplate" runat="server">                                
                                <asp:TableRow runat="server" CssClass="tdbg" Height="80px" 
                                    HorizontalAlign="Center" VerticalAlign="Middle">
                                    <asp:TableCell runat="server">没有任何数据！</asp:TableCell>
                                </asp:TableRow>                                
                            </asp:Table>
                        </td>
                    </tr>
                </table>
                <div style="text-align: center;">
                    <pe:AspNetPager ID="Pager" runat="server" OnPageChanged="Pager_PageChanged">
                    </pe:AspNetPager>
                </div>
                <asp:HiddenField ID="HdnDepartment" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>

<script type="text/javascript">

    var ltext = document.getElementById('UserNameList');
    var otext = parent.document.getElementById('<%= Request["OpenerText"] %>');
    var isSingle = "<%=m_IsSingle %>" == "True";
    var hdnDepartment = document.getElementById('<%=HdnDepartment.ClientID %>');
    var array = [];
    var type = "<%=m_Type%>";

    function GetAdminList(departmentId) {
        hdnDepartment.value = departmentId;
        __doPostBack("<%=UpnlAdminList.ClientID %>", departmentId)
    }

    function ReturnValues(adminName, adminId) {
        if (otext != null) {
            if (isSingle) {
                otext.value = adminName;
                if (type == 0) {
                    CloseFloatingDialog();
                } else {
                    ReturnBack(adminName, type);
                }
            } else {
                add(adminName);
            }
        } else {
            if (type!=0) {
                ReturnBack(adminName, type);
            }
        }
    }
    function ReturnBack(adminName, type) {
        if (window.opener) {
            window.opener.DoPostBack(adminName, type);
        }
        else {
            parent.DoPostBack(adminName, type);
        }
    }

    function add(name) {
        if (name == "") { return; }
        if (jQuery.inArray(name, array) < 0) {
            array.push(name)
        } else {
            alert(name + "管理员已被选，此操作被忽略！");
            return;
        }
        ltext.value = array.join(',');
        if (otext != null) {
            otext.value = ltext.value;
        }
    }

    function delLast() {
        array.pop();
        ltext.value = otext.value = array.join(',');
    }
    function delAll() {
        array = [];
        ltext.value = otext.value = '';
    }

    jQuery(function () {
        if (otext != null && otext.value.length != 0 && !isSingle) {
            ltext.value = otext.value;
            array = otext.value.split(',');
        }
    });

    //关闭浮动窗口
    function CloseFloatingDialog() {
        parent.jQuery(".floatingDialog").hide();
        parent.jQuery("#jqDnrFloatDivBg").hide();
    }
</script>

</html>
