<%@ Page CodeBehind="search_user.aspx.cs" Language="c#" AutoEventWireup="True" Inherits="Webdisk.search_user" %>
<% @ Import Namespace="Webdisk" %>
    <link href="<%=xml.GetStyle()%>" type="text/css" rel="Stylesheet"/>
    <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="form-table">
			<tr><td class="label" style="width:100px;"> 过滤显示：</td>
			<td> <asp:DropDownList id="dept" runat="server" >
				</asp:DropDownList></td></tr>
            <tr><td class="label">
                    查找用户：</td><td>
                    <input class="input3" id="key" name="key" runat="server" style="width:200px;">
					（请输入用户名或真实姓名） <asp:CheckBox ID="chkLike" runat="server" Text="模糊查找"></asp:CheckBox>
					<span id="keyError" style="color:#f00;"></span>
                    <input class="but1" 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>
        </table>
		<div class="menubox">
			<INPUT class="but5 addUser" type="button" value="添加勾选的用户" id="Button1" name="Button1" runat="server" style="display:none;">
			<INPUT type="button" value="加为常用联系人" name="butfriend" id="butfriend" runat="server" class="but5 maguser">
			</div>
		<div  class="menuBox2">
     <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"></div> 
		<div class="pageList" id="page">
        </div>
    </div></div>
	<input type="hidden" id="hiddenUser" runat="server" value />
    </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");
		});
	});
	$("#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();
	});
	$("#Button1").click(function(){
	
	});
	$("#butfriend").click(function(){
		var checked = [];
		$(".checkItem:checked").each(function(){
			checked.push(this.value);
		});
		if(checked.length == 0 ){
			var d = dialog();
			d.content("您没有选择任何用户!");
			d.showModal();
			that.autoClose(d);
		}else{
			that.addFriend(checked);
		}
	});
}
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.ListEvent = function(){
	
	$(".checkItem").click(function(){
		var flag = $(".checkItem").size() == $(".checkItem:checked").size() ;
		var checked = this.checked ;
		$(this).parents("li")[checked ? "addClass":"removeClass"]("checked");
		$("#codeCheckAll")[0].checked = flag ;
	});
	$("#SearchUserList li").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,callback){
	//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,
			dataType : "html",
			cache:false,
			type : "POST",
			beforeSend : function(){
			//	d.showModal();
			},
			success : function(data){
			//	d.close().remove();
				tag.empty().append(data);
				that.ListEvent();
				typeof callback == "function" && callback();
			}
		});
	}
	ajax(0,function(){
		var maxlength =parseInt($("#H_itemtCount").val());
		$("#page").pagination(maxlength, {
			prev_text: '< 上一页',
			next_text: '下一页 >',
			items_per_page: parseInt($("#H_pagesize").val()),
			num_display_entries: 5,
			current_page: 0,
			num_edge_entries: 2,
			link_to: "javascript:void(0);",
			callback: function (page_id, panel) {
				var self = this;
				ajax(page_id, function () {
					self.maxentries = parseInt($("#H_itemtCount").val());
				});
			}
		});
	});
}
SearchUser.init();
	</script>
