<%@ Page CodeBehind="searchAdd_user.aspx.cs" Language="c#" AutoEventWireup="True" Inherits="Webdisk.searchAdd_user" %>
<% @ Import Namespace="Webdisk" %>
    <link href="<%=xml.GetStyle()%>" type="text/css" rel="Stylesheet"/>
    <link rel="stylesheet" href="js/artDialog/css/ui-dialog.css" />
    <link href="css/common.css" rel="stylesheet" type="text/css" />
		<link href="css/webdialog.css" type=text/css rel=stylesheet>

    <script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script src="js/artDialog/dist/dialog-plus.js" type="text/javascript"></script>
    <script src="js/plugins/jquery.pagination.js" type="text/javascript"></script>
    <form id="form1" runat="server">
    <div  class="menuBlock" runat="server" id="divList">
        <div class="menuHead" style="overflow: hidden; border-bottom: 1px dashed #cfcfcf;">
            <h2 style="font-size: 18px; color: #1EA7DF;">
                <img src="pics/menu_file_cut.gif" align="absMiddle">
                添加用户</h2>
        </div>
		<table class="wfrom-table">
			<tr><td class="label" style="width:100px;"> 过滤显示：</td>
			<td> <asp:DropDownList id="dept" runat="server" class="input-select" >
				</asp:DropDownList></td></tr>
            <tr><td class="label">
                    查找用户：</td><td>
                    <input class="input-text" id="key" name="key" runat="server" style="width:200px;">
					（请输入用户名或真实姓名） <span class="wtc-1EA7DE"><asp:CheckBox ID="chkLike" runat="server"  Text="模糊查找"></asp:CheckBox></span>
					<span id="keyError" style="color:#f00;"></span>
                    <input class="wbtn-1" id="btnSearch" type="button" value=" 查 找 " name="submit2" runat="server">
                    </td></tr>
			<tr id="showshare" runat="server"><td class="label">共享权限：</td>
			<td><asp:RadioButtonList ID="type" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
											<asp:ListItem Value="1">完全(任意操作)</asp:ListItem>
											<asp:ListItem Value="2">添加(新建,上传)</asp:ListItem>
											<asp:ListItem Value="3" Selected="True">只读(列表和下载)</asp:ListItem>
											<asp:ListItem Value="4">列表(不允许下载)</asp:ListItem>
										</asp:RadioButtonList>
            </td>
            </tr>
			<tr><td colspan="2" >
			<div class="mListT">
						<span class="l1">
							<input name="" id="codeCheckAll" type="checkbox" />
						</span><span class="l5">用户名</span> <span class="l3">真实姓名</span> <span class="l3">性别</span>
						<span class="l3">班级</span>
					</div>
					<div id="ListContent" style="max-height: 350px;overflow: auto;"></div> 
					<div id="page" style="text-align:center;cursor:pointer;"></div>
				</div>
				<input type="hidden" id="hiddenUser" value ='<%=Session["username"]==null?"":Session["username"].ToString() %>'/>
				<input type="hidden" id="hiddenCheckUsers" runat="server"/>
			</td></tr>
			<tr><td colspan="2" >
			<input class="wbtn-1 " type="button" value="确定选择" id="Button1" name="Button1" runat="server" style="margin-right:30px;" onserverclick="Button1_Click">
        <INPUT class="wbtn-2 " type="button" value="关闭" id="closeWinsow" name="Button1" onClick="javascript:window.close();">
			</td></tr>
        </table>
     </div>
    </form>
	<script type="text/javascript">
var SearchUser = {};
SearchUser.init = function () {
    this.addEvent();
    this.ListEvent();
    this.page();
}
SearchUser.addEvent = function () {
    var that = this;
    //全选反选
    $("#codeCheckAll").click(function () {
        var checked = this.checked;
        $(".checkItem").each(function () {
            this.checked = checked;
            $(this).parents("li")[checked ? "addClass" : "removeClass"]("checked");
        });
		that.setCUser();
    });
    $("#dept").change(function () {
        that.page();
    });
    $("#btnSearch").click(function () {
        var _key = $.trim($("#key").val());
        var error = $("#keyError").html("");
       /* if (_key == "") {
            error.html("您没有输入用户名");
            return false;
        }*/
        that.page();
    });
}
SearchUser.addFriend = function(tousers){
	var that = this ;
	var d = dialog();
	d.showModal();
	$.ajax({
		url : "OtherHandler.ashx?cmd=JionInFriend",
		type : "POST",
		cache:false,
		data  : {tousers:tousers.join(","),user:$("hiddenUser").val()},
		dataType : "json",
		success : function(data){
			d.content(data.msg);
			that.autoClose(d);
		}
	})

}
SearchUser.setCUser = function(){
	var vals = [];
	$(".checkItem:checked").each(function(){
		vals.push(this.value);
	});
	$("#hiddenCheckUsers").val(vals.join(","));
}
SearchUser.ListEvent = function(){
	var that = this;
	$(".checkItem").live("click",function(){
		var flag = $(".checkItem").size() == $(".checkItem:checked").size() ;
		var checked = this.checked ;
		$(this).parents("li")[checked ? "addClass":"removeClass"]("checked");
		$("#codeCheckAll")[0].checked = flag ;
		that.setCUser();
	});
	$("#SearchUserList li").live("click",function(event){
		if(event.target.nodeName.toLowerCase() != "input"){
			$(this).find(".checkItem")[0].click();
		}
	});
}
SearchUser.autoClose = function(d){
	setTimeout(function(){
		d.close().remove();
	},2000);
}
SearchUser.page = function () {
    var that = this;
    var tag = $("#ListContent");
    $("#keyError").html("");
    function ajax(page) {
        var d = dialog();
        var _data = { pageIndex: encodeURI(page), dept: encodeURI($("#dept").val()), key: encodeURI($.trim($("#key").val())), islike: encodeURI(($("#chkLike").is(":checked") ? 1 : 0)) }
        $('input[name="type"]').size() > 0 && (_data[type] = encodeURI($('input[name="type"]:checked').val()));
        $.ajax({
            url: "SearchUserMng.aspx",
            data: _data,
			cache:false,
            dataType: "html",
            type: "POST",
            beforeSend: function () {
            },
            success: function (data) {
                if (page == 0) {
                    tag.empty().append(data);
                } else {
                    tag.find("input[type='hidden']").remove();
                    tag.find("ul").append($(data).filter("ul"));
                    tag.append($(data).filter("input[type='hidden']"));
                    $("#codeCheckAll")[0].checked = false;
                }

                var maxlength = parseInt($("#H_itemtCount").val());
                var currentPage = parseInt($("#H_currentPage").val()) + 1;
                var pageSize = parseInt($("#H_pagesize").val());
                var count = Math.ceil(maxlength / pageSize);
                var html = count <= currentPage ? "" : "<span>点击加载第" + (currentPage + 1) + "页</span>";
                $("#page").empty().append(html);
                $("#page span").click(function () {
                    ajax(currentPage);
                });
            }
        });
    }
    ajax(0);
}
SearchUser.init();

    </script>
