<%@ Page Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true"
    CodeBehind="RoleMember.aspx.cs" EnableEventValidation="false" Inherits="PowerEasy.Module.General.WebSite.Admin.User.RoleMember"
    Title="角色成员管理" %>

<asp:Content ID="Content3" ContentPlaceHolderID="CphNavigation" runat="server">
    <pe:ExtendedSiteMapPath ID="SmpNavigator" SiteMapProvider="AdminMapProvider" runat="server" />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="CphContent" runat="Server">
    <style>
        /*搜索*/
        .Admin_Search
        {
            margin-top: 3px;
            margin-bottom: 0px;
        }
        .Admin_Searchb, .Admin_Searcha
        {
            background-image: url(../../Admin/Images/SearchN.gif);
            background-repeat: no-repeat;
            cursor: pointer;
            width: 15px;
            height: 15px;
            z-index: 9999;
            position: absolute;
            margin-left: -22px;
            margin-top: 3px;
        }
        .Admin_Searcha
        {
            background-image: url(../../Admin/Images/SearchX.gif);
        }
        .Admin_Search_UpAndDown
        {
            display: none;
        }
    </style>
    <script type="text/javascript" language="javascript">
        var oldvalue;
        var selectobj;
        var index = 0;
        var count = 0;

        function beginsearch(obj) {
            if ($(obj).prop("value") == "快速搜索") {
                $("#Searchb").attr("className", "Admin_Searcha")
                $("#Searchb").bind("click", offsearch);
                $(obj).prop("value", "");
            }
            return true;
        }
        function outsearch(obj) {
            if ($(obj).prop("value") == "") {
                $("#Searchb").attr("className", "Admin_Searchb")
                $(obj).prop("value", "快速搜索");
                $("#Admin_Search_UpAndDown").hide();
                index = 0;
                count = 0;
            }
            return true;
        }
        function offsearch(obj) {
            $("#Searchb").attr("className", "Admin_Searchb")
            $("#Admin_Search").prop("value", "快速搜索");
            $("#Searchb").unbind();
            index = 0;
            count = 0;
            $("#Admin_Search_UpAndDown").hide();
            return true;
        }
        function Gosearch(obj, event) {
            var searchtext = $("#Admin_Search").val();
            if (searchtext != "") {
                if (searchtext != oldvalue) {
                    var sobj = $("#<%=this.LstNotBelongRole.ClientID %>").find("option:contains('" + searchtext + "')");
                    selectobj = sobj;
                    count = sobj.length;
                    if (count > 0) {
                        sobj.parent().val(sobj.eq(0).val());
                    }
                    if (count > 1) {
                        $("#Admin_Search_UpAndDown").show();
                    } else {
                        $("#Admin_Search_UpAndDown").hide();
                    }
                    oldvalue = searchtext;
                }
            } else {
                oldvalue = "";
                $("#Admin_Search_UpAndDown").hide();
            }
            return true;
        }

        function searchpre() {
            if (count > 1) {
                index--;
                if (index < 0) {
                    index = count - 1;
                }
                selectobj.parent().val(selectobj.eq(index).val());
            }
        }

        function searchnext() {
            if (count > 1) {
                index++;
                if (index >= count) {
                    index = 0;
                }
                selectobj.parent().val(selectobj.eq(index).val());
            }
        }

        $(document).ready(function () {
            var o = $("#Admin_Search");
            o.bind("keyup", function (event) { Gosearch(this, event); });
            o.bind("blur", function () { outsearch(this); });
            o.bind("focus", function () { beginsearch(this); });
            o.bind("mouseover", function () { $(this).attr("className", 'inputtext_hover'); });
            o.bind("mouseout", function () { $(this).attr("className", 'inputtext'); });
            o.bind("focus", function () { $(this).attr("className", 'inputtext_focus'); });
        });
    </script>
    <script type="text/javascript" language="javascript">
        var oldvalue1;
        var selectobj1;
        var index1 = 0;
        var count1 = 0;

        function beginsearch1(obj1) {
            if ($(obj1).prop("value") == "快速搜索") {
                $("#Searchb1").attr("className", "Admin_Searcha")
                $("#Searchb1").bind("click", offsearch1);
                $(obj1).prop("value", "");
            }
            return true;
        }
        function outsearch1(obj1) {
            if ($(obj1).prop("value") == "") {
                $("#Searchb1").attr("className", "Admin_Searchb")
                $(obj1).prop("value", "快速搜索");
                $("#Admin_Search_UpAndDown1").hide();
                index1 = 0;
                count1 = 0;
            }
            return true;
        }
        function offsearch1(obj1) {
            $("#Searchb1").attr("className", "Admin_Searchb")
            $("#Admin_Search1").prop("value", "快速搜索");
            $("#Searchb1").unbind();
            index1 = 0;
            count1 = 0;
            $("#Admin_Search_UpAndDown1").hide();
            return true;
        }
        function Gosearch1(obj1, event1) {
            var searchtext1 = $("#Admin_Search1").val();
            if (searchtext1 != "") {
                if (searchtext1 != oldvalue1) {
                    var sobj1 = $("#<%=this.LstBelongToRole.ClientID %>").find("option:contains('" + searchtext1 + "')");
                    selectobj1 = sobj1;
                    count1 = sobj1.length;
                    if (count1 > 0) {
                        sobj1.parent().val(sobj1.eq(0).val());
                    }
                    if (count1 > 1) {
                        $("#Admin_Search_UpAndDown1").show();
                    } else {
                        $("#Admin_Search_UpAndDown1").hide();
                    }
                    oldvalue1 = searchtext1;
                }
            } else {
                oldvalue1 = "";
                $("#Admin_Search_UpAndDown1").hide();
            }
            return true;
        }

        function searchpre1() {
            if (count1 > 1) {
                index1--;
                if (index1 < 0) {
                    index1 = count1 - 1;
                }
                selectobj1.parent().val(selectobj1.eq(index1).val());
            }
        }

        function searchnext1() {
            if (count1 > 1) {
                index1++;
                if (index1 >= count1) {
                    index1 = 0;
                }
                selectobj1.parent().val(selectobj1.eq(index1).val());
            }
        }

        $(document).ready(function () {
            var obj = $("#Admin_Search1");
            obj.bind("keyup", function (event1) { Gosearch1(this, event1); });
            obj.bind("blur", function () { outsearch1(this); });
            obj.bind("focus", function () { beginsearch1(this); });
            obj.bind("mouseover", function () { $(this).attr("className", 'inputtext_hover'); });
            obj.bind("mouseout", function () { $(this).attr("className", 'inputtext'); });
            obj.bind("focus", function () { $(this).attr("className", 'inputtext_focus'); });
        });
    </script>
    <table width="100%" border="0" cellpadding="2" cellspacing="1" class="border">
        <tr align="center">
            <td colspan="2" class="spacingtitle">
                <b>角色权限设置</b>
            </td>
        </tr>
        <tr class="tdbg">
            <td class="tdbgleft" align="right" style="width: 150px;height:30px;">
                <strong>角色名：</strong>
            </td>
            <td>
                <asp:Label ID="LblRoleName" runat="server" Text="" />
            </td>
        </tr>
        <tr class="tdbg">
            <td class="tdbgleft" align="right" style="height: 79px">
                <strong>角色描述：</strong>
            </td>
            <td style="height: 79px">
                <asp:Label ID="LblDescription" runat="server" Text="" />
            </td>
        </tr>
         <tr class="tdbg" style="height:30px;">
            <td class="tdbgleft" align="right" style="width: 150px;">
                <strong>成员个数：</strong>
            </td>
            <td>
                <a href="AdministratorManage.aspx?RoleId=<%=RoleId %>"><asp:Label ID="LblRoleCount" runat="server" Text="" /></a>
            </td>
        </tr>
    </table>
    <br />
    <table width="100%" border="0" cellpadding="2" cellspacing="1" class="border">
        <tr align="center">
            <td class="spacingtitle">
                <b>
                    <asp:Label ID="LblRoleName2" runat="server" Text=""></asp:Label>角色成员管理</b>
            </td>
        </tr>
        <tr class="tdbg">
            <td align="center" style="height: 100px">
                <br />
                <table border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td align="left" style="width: 258px;">
                            <strong>未属于该角色的管理员</strong><br />
                            <div class="Admin_Search">
                                <input id="Admin_Search" value="快速搜索" class="inputtext" style="width: 248px;" />
                                <a id="Searchb" class="Admin_Searchb"></a>
                            </div>
                            <asp:ListBox ID="LstNotBelongRole" OnDataBound="LstNotBelongRole_OnDataBound" runat="server" Height="282px" Width="250px" DataTextField="AdminName"
                                DataValueField="AdminId" SelectionMode="Multiple"></asp:ListBox>
                        </td>
                        <td style="width: 100px;" align="center">
                            <span id="Admin_Search_UpAndDown" class="Admin_Search_UpAndDown">
                                <input id="Button4" value="上一个" type="button" onclick="searchpre()" /><br />
                                &nbsp;<br />
                                <input id="Button3" value="下一个" type="button" onclick="searchnext()" />
                            </span>
                            <br />
                            <br />
                            <input type="button" class="inputbutton" value="添加>>" onclick="JavaScript:addItem(<%=LstNotBelongRole.ClientID%>,<%=LstBelongToRole.ClientID%>);delItem(<%=LstNotBelongRole.ClientID%>)" />
                            <br />
                            <br />
                            <input type="button" class="inputbutton" value="<<移除" onclick="JavaScript:addItem(<%=LstBelongToRole.ClientID%>,<%=LstNotBelongRole.ClientID%>);delItem(<%=LstBelongToRole.ClientID%>)" />
                        </td>
                        <td align="left" valign="top" style="width:258px;">
                            <strong>已属于该角色的管理员</strong><br />
                            <div class="Admin_Search">
                                <input id="Admin_Search1" value="快速搜索" class="inputtext" style="width: 248px;" />
                                <a id="Searchb1" class="Admin_Searchb"></a>
                            </div>
                            <asp:ListBox ID="LstBelongToRole" runat="server" Height="282px" Width="250px" DataTextField="AdminName"
                                DataValueField="AdminId" SelectionMode="Multiple"></asp:ListBox>
                            <asp:HiddenField ID="HdnBelongToRole" runat="server" />
                        </td>
                        <td>
                            <span id="Admin_Search_UpAndDown1" class="Admin_Search_UpAndDown">
                                <input id="Button1" value="上一个" type="button" onclick="searchpre1()" /><br />
                                &nbsp;<br />
                                <input id="Button2" value="下一个" type="button" onclick="searchnext1()" />
                            </span>
                        </td>
                    </tr>
                </table>
                <br />
                <asp:Button ID="BtnConfirm" runat="server" Text=" 确定 " OnClick="BtnConfirm_Click" /><br />
                &nbsp;
                <br />
            </td>
        </tr>
    </table>
    <script language="JavaScript">
<!--
        /**
        * add one option of a select to another select.
        *
        * @author  Chunsheng Wang <wwccss@263.net>
        */
        function addItem(ItemList, Target) {
            for (var x = 0; x < ItemList.length; x++) {
                var opt = ItemList.options[x];
                if (opt.selected) {
                    flag = true;
                    for (var y = 0; y < Target.length; y++) {
                        var myopt = Target.options[y];
                        if (myopt.value == opt.value) {
                            flag = false;
                        }
                    }
                    if (flag) {
                        Target.options[Target.options.length] = new Option(opt.text, opt.value, 0, 0);
                    }
                }
            }
        }

        /**
        * move one selected option from a select.
        *
        * @author  Chunsheng Wang <wwccss@263.net>
        */
        function delItem(ItemList) {
            for (var x = ItemList.length - 1; x >= 0; x--) {
                var opt = ItemList.options[x];
                if (opt.selected) {
                    ItemList.options[x] = null;
                }
            }
        }

        function GetBelongToRole(ItemList) {
            var adminId = "";
            for (var x = 0; x < ItemList.length; x++) {
                if (adminId == "") {
                    adminId = ItemList.options[x].value;
                }
                else {
                    adminId += "," + ItemList.options[x].value;
                }
            }
            var belongToRole = document.getElementById("<%=HdnBelongToRole.ClientID%>");
            belongToRole.value = adminId;
        }
//-->
    </script>
</asp:Content>
