<%@ Page CodeBehind="myfriendteam.aspx.cs" Language="c#" AutoEventWireup="True" Inherits="Webdisk.myfriendteam" %>
<% @ Import Namespace="Webdisk" %>
<link href="<%=xml.GetStyle()%>" type="text/css" rel="Stylesheet"/>
 <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">
		添加分组： </td><td><input class="input3" id="txtteam" type="text" size="20" name="txtteam" runat="server">
															<input class="but1" id="btnAdd" type="button" value=" 添 加 " name="butadd" runat="server">
	</td></tr></table>
	<div class="menubox">
		<input name="butdel" type="button" id="butdel" class="but5 deleteMsg" value="删除勾选">
		</div>
		
		<div  class="menuBox2">
    <div class="mListT">
        <span class="l1">
           <input name="" id="codeCheckAll" type="checkbox" value="" />
		</span>
		<span class="l5">分组名称</span>
        <span class="l3">人员个数</span> 
		<span class="l3">修改</span>
        <span class="l3">删除</span>
    </div>
    <ul class="menuList" id="codeList">
        <asp:repeater runat="server" id="rptFrienTeamList">
            <ItemTemplate>
                <li>
                <span class="l1"><input name="checkItem" class="checkItem" type="checkbox" data-name='<%# DataBinder.Eval(Container.DataItem,"friendteam")%>' value="<%# DataBinder.Eval(Container.DataItem,"id") %>"/></span>
                <span class="l5"><%# DataBinder.Eval(Container.DataItem, "friendteam")%></span>
                <span class="l3"><%# showcount(DataBinder.Eval(Container, "DataItem.id").ToString()) %></span>
                <span class="l3" ><a class="linked editItem" href="javascript:void(0);">修改</a></span>
                <span class="l3 "><a class="linked deleteItem" href="javascript:void(0);">删除</a></span>
                </li>
           </ItemTemplate>
        </asp:repeater>
    </ul>
	<input type="hidden" value="" id="H_itemtCount"  runat="server"/>
	<input type="hidden" value="" id="H_currentPage"  runat="server"/>
    <input type="hidden" value="" id="H_pagesize" runat="server" />
	<input type="hidden" id="hiddenUser" value ='<%=Session["username"]==null?"":Session["username"].ToString() %>'/>
	<div class="pageList" id="page"> 
	   
	</div></div>
</div>
<script type="text/javascript">
var Item = {};
Item.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");
		});
	});
	//删除勾选
	$("#butdel").click(function(){
		var checked = $(".checkItem:checked") ;
		if(checked.size() == 0) {
			var d = dialog({content : "您没有勾选任何内容"}).showModal();
			that.autoClose(d);
		}else{
			that.submitDelete(checked);
		}
	});
	$(".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 ;
	});
	$("#codeList li").click(function(event){
		if(event.target.nodeName.toLowerCase() != "input" && event.target.nodeName.toLowerCase() != "a"){
			$(this).find(".checkItem")[0].click();
		}
	});
	$("#btnAdd").click(function(){
		var _txtteam = $.trim($("#txtteam").val());
		if(_txtteam == ""){
			var d = dialog({content : "您没有填写组名"}).showModal();
			that.autoClose(d);
		}else{
			that.submitAdd(_txtteam);
		}
	});
	$(".deleteItem").click(function(){
		var checked = $(this).closest('li').find(".checkItem");
		that.submitDelete(checked);
	});
	$(".editItem").click(function(){
		var parent =$(this).closest('li');
		that.submitEdit(parent);
	});
}
Item.submitEdit = function(tag){
	var that = this ;
	var nTag = tag.find(".l5");
	var d = dialog({
		title :"修改分组",
		content : '<table width="100%" border="0"><tbody><tr><td valign="top">输入新名称：</td><td><input type="text" class="dialog-input" id="newName" size="24" maxlength="96" value="'+nTag.text()+'"></td></tr></tbody></table>',
		statusbar: "<span class='dialog-error' id='addError'></span>",
		button : [{
            value: '同意',
            callback: function () {
                ajax();
                return false;
            },
            autofocus: true
        },{
            value: '取消',
            callback: function () {
                return true;
            },
            autofocus: true
        }]
	}).showModal();
	function ajax (){
		var _name = $.trim($("#newName").val());
		var error = $("#addError").html("");
		if(_name == "" ) {
			error.html("名称不能为空");
			return false ;
		}
		if(_name == $.trim(nTag.text())){
			d.close().remove();
		}else{
			$.ajax({
				url : "OtherHandler.ashxcmd=UpdateFriendTeam",
				data : {friendTeam: encodeURI(_name),id:tag.find(".checkItem").val()},
				dataType : "json",
				type : "POST",
				cache:false,
				success : function(data){
					error.html(data.msg);
					if(data.code == "0"){
						nTag.text(_name);
						that.autoClose(d);
					}
				}
			});
		}
	}
}
Item.submitAdd = function(name){
	var that = this;
	var d = dialog().showModal();
	$.ajax({
		url : "OtherHandler.ashx?cmd=AddFriendTeam",
		data : {team :encodeURI(name),user:encodeURI($("#hiddenUser").val())},
		type : "POST",
		cache:false,
		dataType : "json",
		success :  function(data){
			d.content(data.msg);
			that.autoClose(d);
			if(data.code == "0"){
				that.ajaxPage(0);
			}
		}
	});
}
Item.submitDelete = function(cTag){
	var that = this ;
	var arr =[];
	cTag.each(function(){
		arr.push(this.value);
	});
	var d = dialog().showModal();
	$.ajax({
		url : "OtherHandler.ashx?cmd=DeleteFriendTeam",
		data : {id :arr.join(",")},
		type : "POST",
		dataType : "json",
		cache:false,
		success :  function(data){
			d.content(data.msg);
			that.autoClose(d);
			if(data.code == "0"){
				cTag.closest("li").remove();
				if($("#codeList li").size() == 0 ){
					that.ajaxPage(parseInt($("#H_currentPage").val()));
				}
			}
		}
	});
}
Item.autoClose = function(d){
	setTimeout(function(){
		d.close().remove();
	},2000);
}
Item.page = function(){
	var that = this;
	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: parseInt($("#H_currentPage").val()),
		num_edge_entries: 2,
		link_to: "javascript:void(0);",
		callback: function (page_id, panel) {
			var self = this;
			that.ajaxPage(page_id);
		}
	});
}
Item.ajaxPage = function(page){
	//var d = dialog().showModal();
	$.ajax({
		url : "myfriendteam.aspx",
		data : {page : page},
		dataType : "html",
		cache:false,
		type :"POST",
		success : function(data){
			//d.close().remove();
			$("#wdContent").empty().append(data);
		}
	});
}
Item.init = function(){
	this.addEvent();
	this.page();
}
Item.init();
</script>
 