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

<!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" style="width: 60px; padding: 0px;"
                        onclick="selAll()" value="选择全部" />
                    <input type="button" class="inputbutton" name="del1" style="width: 60px; padding: 0px;"
                        onclick="delLast()" value="删除最后" />
                    <input type="button" class="inputbutton" name="del2" style="width: 60px; padding: 0px;"
                        onclick="delAll()" value="删除全部" />
                </td>
            </tr>
        </table>
    </asp:Panel>
    <asp:Panel ID="PnlRoleList" runat="server" Style="float: left; width: 25%;">
        <div class="guidecollapse" onclick="Switch(this)">
            角色列表</div>
        <div class="guide" style="display: none; width: 100%;">
            <ul>
                <asp:Repeater ID="rptRole" runat="server">
                    <ItemTemplate>
                        <li onclick='GetAdminList(<%# Eval("Key") %>)' onmousedown="javascript:this.bgColor='#eeeeee'"
                            style="cursor: pointer; width: auto; height: 20px; margin-left: 20px;">
                            <%#Eval("Value") %></li>
                    </ItemTemplate>
                </asp:Repeater>
            </ul>
        </div>
        <div class="guideexpand" onclick="Switch(this)">
            按部门查看</div>
        <div style="background: #FFFFFF; width: 100%; overflow-y: hidden; overflow-x: auto;">
            <span style="width: 100%">
                <asp:TreeView runat="server" SelectedNodeStyle-BackColor="#EEEEEE" ID="tvdepartment"
                    OnSelectedNodeChanged="tvdepartment_SelectedNodeChanged">
                </asp:TreeView>
            </span>
        </div>
    </asp:Panel>
    <div style="float: left; width: 74%;" runat="server" id="pnlAdminList">
        <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 ID="TableRow1" runat="server" CssClass="tdbg" Height="80px" HorizontalAlign="Center"
                                    VerticalAlign="Middle">
                                    <asp:TableCell ID="TableCell1" runat="server">没有任何数据！</asp:TableCell>
                                </asp:TableRow>
                            </asp:Table>
                        </td>
                    </tr>
                </table>
                <div style="text-align: center;">
                    <pe:AspNetPager ID="Pager" SimplePager="true" runat="server" OnPageChanged="Pager_PageChanged">
                    </pe:AspNetPager>
                </div>
                <asp:HiddenField ID="HdnRole" runat="server" />
                <asp:HiddenField ID="HdnDepartment" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
<script type="text/javascript">

    var ltext = document.getElementById('UserNameList');
    //    var otext = window.opener.document.getElementById('<%= Request["OpenerText"] %>');
    var otext = window.parent.document.getElementById('<%= Request["OpenerText"] %>');
    var oValue = window.parent.document.getElementById('<%= Request["OpenerKey"] %>');

    var isSingle = "<%=m_IsSingle %>" == "True";
    var hdnRole = document.getElementById('<%=HdnRole.ClientID %>');
    var hdnDepartment = document.getElementById('<%=HdnDepartment.ClientID %>');
    var array = [];
    var arrayId = [];
    var callbackName = '<%= Request["CallBackName"] %>';

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

    function GetAdminListByDepartmentId(departmentId) {
        __doPostBack("<%=tvdepartment.ClientID %>", departmentId)
    }

    function ShellCallBack() {
        if (callbackName != null && callbackName != "") {
            eval('window.parent.' + callbackName + "()");
        }
    }

    function ReturnValues(adminName, adminId) {
        if (otext != null) {
            if (isSingle) {
                otext.value = adminName;
                CloseFloatingDialog();
            } else {
                add(adminName);
            }
            ShellCallBack();
        }
        if (oValue != null) {
            if (isSingle) {
                oValue.value = adminId;
                CloseFloatingDialog();
            } else {
                addId(adminId);
            }
            ShellCallBack();
        }
    }

    function selAll() {
        delAll();
        jQuery("table#DlstAdmin span").each(function () {
            $(this).trigger("click");
        });
    }

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

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

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

    //关闭浮动窗口
    function CloseFloatingDialog() {

        window.parent.jQuery(".floatingDialog").hide();
        window.parent.jQuery("#jqDnrFloatDivBg").hide();
    }

    function Switch(obj) {
        obj.className = (obj.className == "guideexpand") ? "guidecollapse" : "guideexpand";
        var nextDiv;
        if (obj.nextSibling) {
            if (obj.nextSibling.nodeName == "DIV") {
                nextDiv = obj.nextSibling;
            }
            else {
                if (obj.nextSibling.nextSibling) {
                    if (obj.nextSibling.nextSibling.nodeName == "DIV") {
                        nextDiv = obj.nextSibling.nextSibling;
                    }
                }
            }
            if (nextDiv) {
                nextDiv.style.display = (nextDiv.style.display != "") ? "" : "none";
            }
        }
    }
</script>
</html>
