<%@ Page CodeBehind="codelist.aspx.cs" Language="c#" AutoEventWireup="True" Inherits="Webdisk.codelist" %>
<%@ Import Namespace="Webdisk.DAL" %>
<div runat="server" id="divList"  class="menuBlock">
	<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>
	<div class="menubox">
		<input class="but5 cancel" id="cancelSend" value="取消提取" title="取消提取" name="" type="button" />
		<input class="but5 send" id="sendMsg" value="发送通知" title="发送通知" name="sssss" type="button" />
		
	</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="l1">取消</span>
		<span class="l3">失效时间</span> 
    </div>
    <ul class="menuList" id="codeList">
        <asp:repeater runat="server" id="rptCodeList">
            <ItemTemplate>
                <li>
                <span class="l1"><input name="checkItem" class="checkItem" type="checkbox" data-name='<%# DataBinder.Eval(Container.DataItem,"Filename")%>' value="<%# DataBinder.Eval(Container.DataItem,"id") %>"/></span>
                <span class="l5"><%# DataBinder.Eval(Container.DataItem,"Filename")%></span>
                <span class="l3"><%# DataBinder.Eval(Container.DataItem,"pickcode")%></span>
                <span class="l3" style="position:relative;"><a class="copyAddress linked" href="javascript:void(0);" data-copy="<%# Other.GetWebSite() %>/ExtractFiles.aspx?code=<%# DataBinder.Eval(Container.DataItem,"pickcode")%>">复制地址</a></span>
                <span class="l1 "><a class="cancel-send linked" href="javascript:void(0);">取消</a></span>
                <span class="l3"><%# DataBinder.Eval(Container.DataItem,"pickTime")%></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>
	<script type="text/javascript">
	var CodeList = {};
	CodeList.iframeDialog = null;
	/***
	*关闭上传文件窗口
	***/
	CodeList.closeUploadFile = function (flag) {
	    if (this.iframeDialog) {
	        this.iframeDialog.close().remove();
	        this.iframeDialog = null;
	    }
	    if (flag) {
	        var d = dialog({ content: flag });
	        d.showModal();
	        setTimeout(function () { flag.close().remove();}, 2000);
	    }
	}
/**
*关闭模态窗口
*/
	CodeList.closeWindow = function (flag) {
	    if (this.iframeDialog) {
	        this.iframeDialog.close().remove();
	        this.iframeDialog = null;
	    } 
        if (flag) {

	        setTimeout(function () { flag.close().remove(); }, 2000);
	    }
	}
CodeList.addEvent = function () {
    var that = this;
    //全选
    $("#codeCheckAll").click(function () {
        var checkTag = $("#codeList .checkItem");
        var flag = this.checked;
        checkTag.each(function () {
            this.checked = flag;
            $(this).parents("li")[flag ? "addClass" : "removeClass"]("checked");
        })
    });
    $("#codeList .checkItem").bind("click", function () {
        $(this).parents("li")[this.checked ? "addClass" : "removeClass"]("checked");
        checkAll();
    });
    $("#codeList>li").bind("click", function (event) {
        if (event.target.nodeName.toLowerCase() != "input" && event.target.nodeName.toLowerCase() != "a") {
            var tag = $(this).find(".checkItem")[0];
            tag.checked = !tag.checked;
            $(this)[tag.checked ? "addClass" : "removeClass"]("checked");
            checkAll();
        }
    });
    function checkAll() {
        $("#codeCheckAll")[0].checked = $("#codeList .checkItem").size() == $("#codeList .checkItem:checked").size();
    }
    //复制地址
    $('#codeList .copyAddress').each(function () {
        $(this).zclip({
            path: "js/ZeroClipboard.swf",
            copy: function () {
                //$(this).data("copy");alert(1)
                return $(this).data("copy");
            },
            afterCopy: function () {
                var d = dialog({
                    content: '复制成功'
                });
                d.showModal();
                setTimeout(function () {
                    d.close().remove();
                }, 2000);
            }
        });
    });
    //取消提取
    $("#codeList .cancel-send").bind("click", function () {
        var tag = $(this).parents("li").find(".checkItem");
        that.ajaxCancel(tag);
    });
    $("#cancelSend").bind("click", function () {
        var checkTag = $("#codeList .checkItem:checked");
        if (checkTag.size() > 0) {
            that.ajaxCancel(checkTag);
        } else {
            var d = dialog({ content: "您没有选择任何内容" }).showModal();
            that.closeWindow(d);
        }
    });
    $("#sendMsg").bind("click", function () {
        var checkTag = $("#codeList .checkItem:checked");
        if (checkTag.size() > 0) {
            that.showWindow("sendCode.aspx?type=1&id=" + checkTag.val(), "提取码");
        } else {
            var d = dialog({ content: "请先选择文件" }).showModal();
            that.closeWindow(d);
        }
    });
}
	CodeList.ajaxCancel = function(tag){
		var that = this;
		var filename = [];
		var _name = [],_id=[];
		tag.each(function(){
			_name.push($(this).data("name"));
			_id.push($(this).val());
		});
		var d = dialog({
			content:"您确定要取消“"+_name.join(";")+ "”的提取码?",
			title: "取消提取码",
			width : "300",
			button :[{
				value:"确认",
				callback :function(){
				    $.ajax({
				        url: "CodeListHandler.ashx?cmd=UpdatePickCode",
						cache:false,
				        data: { id: _id.join(","), user:encodeURI($("#hiddenUser").val())},
				        success: function () {
				            that.ajaxList($("#H_currentPage").val());
							d.close().remove();
				        }
				    });
					return false;
				},
				autofocus :true
			},{
				value:"取消",
				callback :function(){
				
				},
				autofocus :true
			}]
		});
		d.showModal();
	}
    CodeList.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();
    }
    CodeList.page = function () {
        var that = this;
        var maxlength = parseInt($("#H_itemtCount").val());
        var current = parseInt($("#H_currentPage").val());
        var pageSize = parseInt($("#H_pageSize").val());
        $("#page").pagination(maxlength, {
            prev_text: '< 上一页',
            next_text: '下一页 >',
            items_per_page: pageSize,
            num_display_entries: 5,
            current_page: current,
            num_edge_entries: 2,
            link_to: "javascript:void(0);",
            callback: function (page_id, panel) {
                var self = this;
                that.ajaxList(page_id);
            }
        });

    }
    CodeList.ajaxList = function (page_id) {
        
        $.ajax({
            url: "codelist.aspx",
            data: { pageIndex: page_id },
			cache:false,
            dataType: "html",
            success: function (data) {
                $("#wdContent").empty().append(data);
                d.close().remove();
            }
        });
    }
	CodeList.init = function(){
		this.page();
		this.addEvent();
	}
	CodeList.init();
	var closeWindow = function (flag) {
	    CodeList.closeUploadFile(flag);
	}
	</script>
</div>
