<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyResourceMng.aspx.cs" Inherits="Webdisk.MyResourceMng" %>
<%@ import namespace="Webdisk" %>
<%@ Import Namespace="Global" %>

<link href="<%=xml.GetStyle()%>" type="text/css" rel="Stylesheet" />
   <script language="javascript" type="text/javascript">
       $.datepick.setDefaults({ prevText: "上月", todayText: "今天", clearText: "清除", nextText: "下月", closeText: "关闭", dateFormat: "yyyy-mm-dd", dayNamesMin: ["日", "一", "二", "三", "四", "五", "六"],
           monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"]
       });
       $('#txttime1').datepick();
       $('#txttime2').datepick();

       function getSearch() {
           var tag = $('#search');
           var bTag = $("#but");
           if (bTag.text() == "↓高级查找↓") {
               bTag.text("↑高级查找↑");
               tag.slideDown(500);
           } else {
               bTag.text("↓高级查找↓");
               tag.slideUp(500);
           }
       }
</script>
<div class="menuBlock">
	<div class="menuHead" style="overflow:hidden;border-bottom: 1px dashed #cfcfcf;">
		<a id="but" class="floatR" onclick="getSearch();" href="javascript:void(0);">↓高级查找↓</a>
		<h2 style="font-size: 18px;color: #1EA7DF;"><img src="pics/menu_file_cut.gif" align="absMiddle">已发布资源 </h2>
	</div>
	<div id="search" class="clear search-con" style="DISPLAY: none;">
		<table class="form-table" style="width: 100%;margin: 0;">
			<tr>
				<td  class="label">
						文件名：
				</td>
				<td>
					<input name="key" class="input3" id="key" runat="server" style="width:280px;">
					（可模糊输入，不填为不限，多个关键字用半角空格分隔）
					<input class="but1 floatR" id="submit2" type="button" value=" 查 找 " name="submit22" onclick="resourceMng.Search();">
				</td>
			</tr>
			<tr>
				<td  class="label">
						添加时间：
				</td>
				<td>
					<input name="txttime1" id="txttime1" style="width:80px;" runat="server" class="input3 ">
					－
					<input name="txttime2" id="txttime2" style="width:80px;" runat="server" class="input3 ">（不填为不限）
				</td>
			</tr>
			<tr id="show1" runat="server">
				<td class="label">
						文件大小：
				</td>
				<td>
					<input name="txtsize1" class="input3" style="width:80px;" id="txtsize1" runat="server">
					KB－
					<input name="txtsize2" class="input3" style="width:80px;" id="txtsize2" runat="server">
					KB（不填为不限）
				</td>
			</tr>
			<tr id="show2" runat="server">
				<td class="label">
						文件类型：
				</td>
				<td>
					<input name="txttype" class="input3" id="txttype"  style="width:280px;" runat="server">（输入扩展名，用半角,分隔，不填为不限）
				</td>
			</tr>
		</table>
	</div>
	<div class="menubox">
		<input class="but5 editC edit" id="Submit1" type="button" value="编辑选中" name="Submit1" runat="server">
		<input class="but5 cancel" id="cancelSend" value="取消选中" title="取消选中" name="" type="button">
	</div>
	<div id="content" class="menuBox2"></div>
	<div class="pageList" id="page"> 
	</div>
	         
	<input type="hidden" id="hiddenUser" value ='<%=Session["username"]==null?"":Session["username"].ToString() %>'/>          
    </div>           
<script type="text/javascript">
     var isFile;
var resourceMng = {};
resourceMng.descOrAsc = 0;
resourceMng.type = "";
resourceMng.asc = "";
resourceMng.urlParam = {} ; //url参数
resourceMng.iframeDialog = null;
	 
/***
**
***/ 	
resourceMng.setHtml = function (html) {
	$("#content").empty().append(html);
	this.listEvent();
}
/***
**
***/ 
resourceMng.init = function(){
	var that = this ;
	this.initUrlParam();
	this.getList();
	this.addEvent();
}
/***
**查询分页内容
***/ 
resourceMng.getList = function (currentPage) {
	var that = this ;
	currentPage = currentPage ? currentPage : 0;
	var isqs = $("#isqs").val();
	function ajax(page, callback) {
	 $.ajax({
		 url: "MyResourceList.aspx",
		 data:   { pageindex: page },
		 cache : false,
		 beforeSend: function () {
		 },
		 success: function (data) {
			 typeof callback == "function" && callback(data);
		 }
	 });
	}
	 ajax(currentPage, function (data) {
		 that.setHtml(data);
		 var maxlength = parseInt($("#H_itemtCount").val());
		 $("#H_currentPage").val(currentPage);
		 $("#page").pagination(maxlength, {
			 prev_text: '< 上一页',
			 next_text: '下一页 >',
			 items_per_page: parseInt($("#H_pageSize").val()),
			 num_display_entries:10,
			 current_page: currentPage,
			 num_edge_entries: 2,
			 link_to: "javascript:void(0);",
			 callback: function (page_id, panel) {
				 var self = this;
				 ajax(page_id, function (vdata) {
					 that.setHtml(vdata);
					$("#H_currentPage").val(page_id);
					 self.maxentries = parseInt($("#H_itemtCount").val());
				 });
			 }
		 });
	 });
 };
/***
**高级搜索
***/ 
resourceMng.Search = function () {
	var that = this ;
	that.asc = that.getUrlParam('asc');
	var page = that.getUrlParam('page') ? that.getUrlParam('page') : 0;
	var friend = that.getUrlParam('friend');
	var key = encodeURI($.trim($("#key").val()));
	var txttime1 =  encodeURI($.trim($("#txttime1").val()));
	var txttime2 =  encodeURI($.trim($("#txttime2").val()));
	var txtsize1 =  encodeURI($.trim($("#txtsize1").val()));
	var txtsize2 =  encodeURI($.trim($("#txtsize2").val()));
	var txttype =  encodeURI($.trim($("#txttype").val()));
	 var d = dialog();
	function ajax(page, callback) {
		 $.ajax({
			 url: "MyResourceList.aspx?cmd=search",
		     cache : false,
			 data: { pageindex: page, key: key, time1: txttime1, time2: txttime2, size1: txtsize1, size2: txtsize2, type: txttype },
			 beforeSend: function () {
				 d.showModal();
			 },
			 success: function (data) {
				 d.close().remove();
				 typeof callback == "function" && callback(data);
			 }
		 });
	 }
	 ajax(page, function (data) {
		 that.setHtml(data);
		 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 (vdata) {
					 that.setHtml(vdata);
					 self.maxentries = parseInt($("#H_itemtCount").val());
				 });
			 }
		 });
	 });
 }

/***
** 获取url中的参数
***/ 
resourceMng.initUrlParam = function () {
	var s = $("#wdContent").attr("src");
	if (s != ""){
		if (s.indexOf('?')<0){ 
			this.urlParam ={};
		 }else {
			 var sarr = s.substr(s.indexOf('?')+1).split("&");
			 var tarr;
			 for (i = 0; i < sarr.length; i++) {
				 tarr = sarr[i].split("=");
				 this.urlParam[tarr[0]] = tarr[1];
			 }
		 }
    }
    isFile = this.getUrlParam('type') == "1" ? false : true
}
/***
**获取url中的指定参数，无该值则返回空字符
***/ 
resourceMng.getUrlParam = function(param){
	return typeof this.urlParam[param] == "undefined" ? "" : this.urlParam[param] ;
}

resourceMng.listEvent = function () {
	var that = this;
	$("#dsUl .edit").bind("click", function () {
		that.showWindow("shareout.aspx?user=" +$("#hiddenUser").val()+"&sharelist=`"+$(this).data("value") , "编辑选中发布资源");
	});
	$("#dsUl .cancel").bind("click", function () {
		that.cancelSend($(this).attr("data-id"),false);
	});
	$("#dsUl li").bind("click",function(event){
		if(event.target.nodeName.toLowerCase() != "input" && event.target.nodeName.toLowerCase() != "a"){
			var checkTag = $(this).find("input[type='checkbox']")[0];
			checkTag.checked = !checkTag.checked ;
			$(this)[checkTag.checked? "addClass" : "removeClass"]("checked");
			isCheckedAllTag();
		}
	});
	$("#dsUl input[type='checkbox']").bind("click",function(){ 
		$(this).parents("li")[this.checked ? "addClass" :"removeClass"]("checked");
		isCheckedAllTag();
	});
	//反选
	function isCheckedAllTag(){
		var cbox = $("#dsUl input[type='checkbox']");
		$("#checkALL")[0].checked = cbox.size() == cbox.filter(":checked").size();
	}
	//全选
	$("#checkALL").click(function (){
		var checked = this.checked ;
		$("#dsUl .chkSelect").each(function(){
			this.checked = checked ;
		});
	});
	
}
resourceMng.showWindow = function(href ,title){
	var d = this.iframeDialog = dialog({
			content: "<iframe src='" +href + "' style='border:none;width:800px;height:550px;'></iframe>",
			title: title
		});
		d.showModal();
}
resourceMng.autoClose = function(d){
	setTimeout(function(){
		d.close().remove();
	},2000);
}
resourceMng.addEvent = function () {
    var that = this;
    //编辑选中
    $(".editC").click(function () {
        var checked = getChecked();
        if (checked.path.length > 0) {//+"&path="+
            that.showWindow("shareout.aspx?user=" +$("#hiddenUser").val()+"&sharelist=`"+encodeURI( checked.path.join("`")) , "编辑选中发布资源");
        }
    });
	$("#cancelSend").click(function(){
		var checked = getChecked();
        if (checked.path.length > 0) {//+"&path="+
            that.cancelSend(checked.id.join(","),true);
        }
	});
    function getChecked() {
        var checked = { path: [], id: [] };
        $("#dsUl input[type='checkbox']:checked").each(function () {
            checked.path.push(this.value);
            checked.id.push($(this).data("id"));
        });
        if (checked.path.length == 0) {
            var d = dialog({ content: "您没有选中任何目录和文件，请先选择!" });
            d.showModal();
            setTimeout(function () {
                d.close().remove();
            }, 2000);
        }
        return checked;
    }
}
resourceMng.cancelSend = function(ids,flag){
	var that = this ;
	if(flag){
		var d = dialog({
			title :"温馨提示",
			content:"您是否要删除您选中的列表",
			okValue: '确定',
			ok: function () {
				ajax();
			},
			cancelValue: '取消',
			cancel: function () {}
				}).width(320).showModal();
	}else{
		ajax();
	}
	function ajax(){
		
		$.ajax({
			url : "FileSpaceHandler.ashx?cmd=CancelShareResource",
			data : {user : encodeURI($("#hiddenUser").val()),ids : ids },
			dataType : "json",
			cache : false,
			success : function(data){
				if(data.code == "0"){
					that.getList($("#H_currentPage").val());
				}else{
					var d = dialog({ content: "删除失败，请稍后再试!" });
					d.showModal();
					setTimeout(function () {
						d.close().remove();
					}, 2000);
				}
			}
		});
	}
}
/***
*关闭上传文件窗口
***/
resourceMng.closeWindow = function(flag){
	if(this.iframeDialog){
		this.iframeDialog.close().remove();
		this.iframeDialog = null ;
		if(flag){
			this.getList($("#H_currentPage").val());
		}
	}
}
var closeWindow = function(flag){
	resourceMng.closeWindow(flag);
}
 resourceMng.init();
                    </script>    
