<%@ Page CodeBehind="sharesee.aspx.cs" Language="c#" AutoEventWireup="True" Inherits="Webdisk.sharesee" %>
<%@ import namespace="Webdisk" %>
<%@ Import Namespace="Global" %>

<link href="<%=xml.GetStyle()%>" type="text/css" rel="Stylesheet" />
<script language="javascript" type="text/javascript">
		
		$('#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"> 已共享<% if(Request["type"] != null) Response.Write(Request["type"].ToString() == "1" ? "目录" : "文件"); %></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">
						<%=lstr%>名：
				</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="sharesee.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>
			<tr>
				<td class="label">
						<%=lstr%>注释：
				</td>
				<td>
					<input name="txtnote" class="input3" id="txtnote"  style="width:280px;" runat="server">（不填为不限）
				</td>
			</tr>
			<tr id="show3" runat="server">
				<td class="label">
						签收状态：
				</td>
				<td>
					<select name="isqs" id="isqs" class="input4"  runat="server">
						<option value="" selected>全部</option>
						<option value="1">已签收</option>
						<option value="0">未签收</option>
					</select>
				</td>
			</tr>
		</table>
	</div>
	<div class="menubox">
		<input class="but5 editC edit" id="Submit1" type="button" value="编辑选中" name="Submit1" runat="server">
		&nbsp;&nbsp;
		<input class="but5 cancelC cancel" id="Button3" type="button" value="取消选中" name="Button3" runat="server">
		<input id="HdnSelectedValues" type="hidden" name="HdnSelectedValues" runat="server">
		&nbsp; 
	</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 sharesee = {};
sharesee.descOrAsc = 0;
sharesee.type = "";
sharesee.asc = "";
sharesee.urlParam = {} ; //url参数
sharesee.iframeDialog = null;
	 
/***
**
***/ 	
sharesee.setHtml = function (html) {
	$("#content").empty().append(html);
	this.listEvent();
}
/***
**
***/ 
sharesee.init = function(){
	var that = this ;
	this.initUrlParam();
	this.getList();
	this.addEvent();
}
/***
**查询分页内容
***/ 
sharesee.getList = function (currentPage) {
	var that = this ;
	currentPage = currentPage ? currentPage : 0;
	var isqs = $("#isqs").val();
	function ajax(page, callback) {
	//var d = dialog();
	 $.ajax({
		 url: "ShareSeeList.aspx",
		 cache:false,
		 data: isFile == false ? { pageindex: page,  isFile:isFile , sort1: that.type, sort2: that.asc} : { pageindex: page, isFile:isFile, sort1: that.type, sort2: that.asc, isqs: isqs,isFile: isFile },
		 beforeSend: function () {
			// d.showModal();
		 },
		 success: function (data) {
			// d.close().remove();
			 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: <%=Session["username"]==null?10:Convert.ToInt32(Common.GetListCount(Session["username"].ToString())) %>,
			 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());
				 });
			 }
		 });
	 });
 };
/***
**高级搜索
***/ 
sharesee.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 txtnote =  encodeURI($.trim($("#txtnote").val()));
	var isqs =  encodeURI($.trim($("#isqs").val()));
	 var d = dialog();
	function ajax(page, callback) {
		 $.ajax({
			 url: "ShareSeeList.aspx",
			 cache:false,
			 data: isFile ==false ? { pageindex: page, key: key, isFile: isFile, sort1: that.type, sort2: that.asc, txttime1: txttime1, txttime2: txttime2, txtnote: txtnote} :
					{ pageindex: page,  key: key, sort1: that.type, sort2: that.asc, txttime1: txttime1, txttime2: txttime2, txtsize1: txtsize1, txtsize2: txtsize2, txttype: txttype, txtnote: txtnote, isqs: isqs,isFile: isFile },
			 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中的参数
***/ 
sharesee.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中的指定参数，无该值则返回空字符
***/ 
sharesee.getUrlParam = function(param){
	return typeof this.urlParam[param] == "undefined" ? "" : this.urlParam[param] ;
}

sharesee.listEvent = function () {
	var that = this;
	$("#dsUl .show").bind("click",function(){
		that.showWindow($(this).data("href"),"权限查看");
	});
	$("#dsUl .edit").bind("click", function () {
		that.showWindow($(this).data("href")+"&type="+(that.getUrlParam('type') == "1" ? "1" : "2"),"权限修改");
	});
	$("#dsUl .cancel").bind("click", function () {
		var checked = [];
		$(this).closest("li").find(".chkSelect").each(function(){
			checked.push($(this).data("id"));
		});
		that.cancelAjax(checked);
	});
	$("#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 ;
		});
	});
	
}
sharesee.cancelAjax = function(value){
	var that = this ;
	var d = dialog().showModal();
	$.ajax({
		url : "FileSpaceHandler.ashx?cmd=CancelShare",
		dataType : "json",
		cache:false,
		type : "POST",
		data : {user:$("#hiddenUser").val(),ids:value.join(","),isFile:that.getUrlParam('type') == "1" ? "1" : "2"},
		success : function(data){
			d.content(data.msg);
			that.autoClose(d);
			if(data.code == 0||(data.code ==1 && value.length > 1) ){
				that.getList($("#H_currentPage").val());
			}
		}
	});
}
sharesee.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();
}
sharesee.autoClose = function(d){
	setTimeout(function(){
		d.close().remove();
	},2000);
}
sharesee.addEvent = function () {
    var that = this;
    //编辑选中
    $(".editC").click(function () {
        var checked = getChecked();
        if (checked.path.length > 0) {
            that.showWindow("share.aspx?sharelist=`" + checked.path.join("`") + "&id=" + checked.id.join(",") + "&type=" + (that.getUrlParam('type') == "1" ? "1" : "2"), "编辑选中权限");
        }
    });
    //取消选中
    $(".cancelC").click(function () {
        var checked = getChecked();
        if (checked.path.length > 0) {
            that.cancelAjax(checked.id);
        }
    });
    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;
    }
}
/***
*关闭上传文件窗口
***/
sharesee.closeWindow = function(flag){
	if(this.iframeDialog){
		this.iframeDialog.close().remove();
		this.iframeDialog = null ;
		if(flag){
			this.getList($("#H_currentPage").val());
		}
	}
}
var closeWindow = function(flag){
	sharesee.closeWindow(flag);
}
 sharesee.init();
 
                    </script>    