<%@ Page CodeBehind="trash.aspx.cs" Language="c#" AutoEventWireup="True" Inherits="Webdisk.trash" %>
		<% @ Import Namespace="Webdisk" %>
		<link href="<%=xml.GetStyle()%>" type=text/css rel=stylesheet>
		<script type="text/javascript" language="javascript" src="js/function.js"></script>
			<style type="text/css">.STYLE1 { COLOR: #0000ff }
	        .STYLE2 { VERTICAL-ALIGN: bottom; BORDER-BOTTOM: #bbbbbb 1px dashed }
	        </style>
 <div class="menuBlock">
	<div class="menuHead" style="overflow:hidden;border-bottom: 1px dashed #cfcfcf;">
		<label class="floatR"><INPUT id="usetrash" type="checkbox" CHECKED  name="usetrash" runat="server">启用回收站</label>
		<h2 style="font-size: 18px;color: #1EA7DF;"><img src="pics/trash_s.gif" align="absMiddle"> 回 收 站（只保留前<asp:Label id="lblcount" runat="server"></asp:Label>天文件）</h2>
	</div>
	<div class="menubox">
		<INPUT class="but5 cancelTrash" id="Submit1" type="button" value="还原选中" onclick=""> 
        <INPUT class="but5 deleteTrash" id="Button3" type="button" value="删除选中" onclick=""> 
		<asp:button id="clear" CssClass="but5 emptyTrash" Text="清空回收站" onclick="clear_Click"></asp:button>
		<INPUT id="HdnSelectedValues" type="hidden" name="HdnSelectedValues" runat="server">
	</div>
	
	<div  class="menuBox2">
		<div class="mListT">
			<span class="l1">
			   <input name="" id="codeCheckAll"  type="checkbox" value="全选" />
			</span>
			<span class="l2">已删目录和文件</span> 
			<span class="l3">还原</span>
			<span class="l3">删除</span>
		</div>
		<ul class="menuList" id="codeList">
			<asp:repeater runat="server" id="rptTrachList">
				<ItemTemplate>
					<li>
						<span class="l1">
						   <input name="chkSelect" class="chkSelect" type="checkbox" value='<%# Eval("id").ToString() %>' />
						</span>
						<span class="l2"><asp:Label runat="server" Text='<%# Eval("Postion").ToString()+Eval("DirName").ToString()+Eval("FileName").ToString() %>'></asp:Label></span> 
						<span class="l3"><a class="restore linked" href='javascript:trach.RestoreDel("<%# Eval("id").ToString() %>")'>还原</a></span>
						<span class="l3"><a class="del linked" href='javascript:trach.DelTrach("<%# Eval("Postion").ToString()+Eval("DirName").ToString()+Eval("FileName").ToString() %>")'>删除</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 Trach = {};
Trach.ajaxList = function (pageIndex) {
		$.ajax({
			url: "trach.aspx",
			cache:false,
			data: { page: pageIndex,pageSize:parseInt($("#H_pagesize").val())},
			dataType: "html",
			success: function () {
				$("#wdContent").empty().append(data);
			}
		})
}
/**
*还原
*/
Trach.RestoreDel = function (fileIds,callback) {
    var d = dialog().showModal();
    $.ajax({
        url: "OtherHandler.ashx?cmd=updateTrach",
        data: { id: encodeURI(fileIds) },
		cache:false,
        success: function (data) {
            d.close().remove();
            typeof callback == "function" && callback();
        }
    })
}
Trach.DelTrach = function (path,callback) {
		$.ajax({
			url: "OtherHandler.ashx?cmd=DelTrach",
			cache:false,
			data: {user:encodeURI($("#hiddenUser").val()), path: encodeURI(path) },
			success : function(data){
				typeof callback == "function" && callback();
			}
		});
}
Trach.ClearTrach = function () {
	var d = dialog().showModal();
		$.ajax({
			url: "OtherHandler.ashx?cmd=ClearTrach",
			cache:false,
			data: { user: encodeURI($("#hiddenUser").val())},
			success : function(data){
				d.close().remove();
				if(data.code == 0){
					that.ajaxList(0);
				}
			}
		});
}
Trach.init = function(){
	if($.trim($("#hiddenUser").val()) == ""){
		dialog({content:"您长时间没操作，需要重新登录",
			title : "温馨提醒",
			okValue : "确定",
			ok : function(){
				location.href="/login.aspx";
			}}).showModal();
	}
	this.addEvent();
	this.page();
}
Trach.addEvent = function(){
	var that = this ;
		//全选反选
	$("#codeCheckAll").click(function(){
		var checked = this.checked ;
		$(".chkSelect").each(function(){
			this.checked = checked ;
			$(this).parents("li")[checked ? "addClass":"removeClass"]("checked");
		});
	});
	$(".chkSelect").click(function(){
		var flag = $(".chkSelect").size() == $(".chkSelect: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(".chkSelect")[0].click();
		}
	});
	//还原选中
	$("#Submit1").click(function(){
		var checked = [];
		var tags = $(".chkSelect:checked") ;
		tags.each(function(){
			checked.push(this.value);
		});
		if(checked.length == 0 ){
			var d = dialog({content:"您没有选择任何记录"}).showModal();
			that.autoClose(d);
		}else{
			that.RestoreDel(checked.join(","),function(){
				
				tags.parents("li").remove();
				if($("#codeList li").size() < 1){
					that.ajaxList(0);
				}
			});
		}
	});
	//删除选中
	$("#Button3").click(function(){
		var checked = [];
		var tags = $(".chkSelect:checked") ;
		tags.each(function(){
			checked.push(this.value);
		});
		if(checked.length == 0 ){
			var d = dialog({content:"您没有选择任何记录"}).showModal();
			that.autoClose(d);
		}else{
			that.DelTrach(checked.join(","),function(){
				
				tags.parents("li").remove();
				if($("#codeList li").size() < 1){
					that.ajaxList(0);
				}
			});
		}
	});
	//清空回收站
	$("#clear").click(function(){
		that.ClearTrach();
	});
	//还原单个
	$(".restore").click(function(){
		var ctag = $(this).parents("li").find(".chkSelect");
		that.RestoreDel(ctag.val(),function(){
				
				ctag.parents("li").remove();
				if($("#codeList li").size() < 1){
					that.ajaxList(0);
				}
			});
	});
	//删除单个
	$(".del").click(function(){
		var ctag = $(this).parents("li").find(".chkSelect");
		that.DelTrach(ctag.val(),function(){
				ctag.parents("li").remove();
				if($("#codeList li").size() < 1){ 
					that.ajaxList(0);
				}
			});
	});
	//启用回收站
	$("#usetrash").click(function(){
		var check = this.checked ;
		var self ; 
		var d = dialog().showModal();
		$.ajax({
			url : "OtherHandler.ashx?cmd=EnableTrach",
			cache:false,
			data : { user: encodeURI($("#hiddenUser").val()),enabletrach:check},
			dataType : "json",
			type : "POST",
			success : function(data){
				d.content(data.msg);
				that.autoClose(d);
				if(data.code != 0){
					self.checked = !check ;
				}
			}
		});
	});
}
Trach.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.ajaxList(page_id);
		}
	});
}
Trach.autoClose = function(d){
	setTimeout(function(){
		d.close().remove();
	},2000);
}
Trach.init();
            </script>