<%@ Page CodeBehind="uploadcodelist.aspx.cs" Language="c#" AutoEventWireup="True"
    Inherits="Webdisk.uploadcodelist" %>

<%@ Import Namespace="Webdisk" %>
<link href="<%=xml.GetStyle()%>" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript" src="js/function.js"></script>
<div 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="Submit2" type="button" value="取消选中" name="submit2" />
        <input class="but5 send" id="Submit" type="button" value="发送上传码通知" name="Submit" />
        <input id="HdnSelectedValues" type="hidden" name="HdnSelectedValues" runat="server" />
    </div>
	<div class="menuBox2">
    <div class="mListT">
        <span class="l1">
            <input type="checkbox" id="CheckBox2" /></span> <span class="l5">
                <%=postion%>上传路径</span> <span class="l3">
                    <%=pickcode%>上传密码</span> <span class="l3">
                        <%=picktime%>失效时间</span> <span class="l6">复制地址</span> <span class="l6">取消</span>
    </div>
    <div id="content">
    </div>
    <div class="pageList" id="page">
    </div>
    <input type="hidden" id="hiddenUser" value='<%=Session["username"]==null?"":Session["username"].ToString() %>' />
</div></div>
<script type="text/javascript">
    var UploadCode = {};
    UploadCode.iframeDialog = null;

    /**
    *初始化
    **/
    UploadCode.init = function () {
        this.addEvent();
        this.page();
    }
    UploadCode.addEvent = function () {
        var that = this;
        $("#CheckBox2").click(function () {
            var flag = this.checked;
            $(".checkItem").each(function () {
                this.checked = flag;
                $(this).parents("li")[flag ? "addClass" : "removeClass"]("checked");
            });
        });
        $("#Submit2").click(function () {
            var cTag = $(".checkItem:checked");
            if (cTag.size() == 0) {
                var d = dialog({ content: "请先选择文件" }).showModal();
                that.autoClose(d);
            } else {
                that.submitCancel(cTag);
            }
        });
        $("#Submit").click(function () {
            var cTag = $(".checkItem:checked");
            if (cTag.size() == 0) {
                var d = dialog({ content: "请先选择上传路径" }).showModal();
                that.autoClose(d);
            } else {
                that.submitSend(cTag);
            }
        });
    }
    /**
    *取消选中
    ***/
    UploadCode.submitCancel = function (cTag) {
        var that = this
        var d = dialog().showModal();
        var _id = [];
        cTag.each(function () {
            _id.push(this.value)
        });
        $.ajax({
            url: "CodeListHandler.ashx?cmd=UpdateUploadCode",
            data: { user: $("#hiddenUser").val(), id: _id.join(",") },
            dataType: "json",
            type: "POST",
			cache:false,
            success: function (data) {
                d.content(data.msg);
                that.autoClose(d);
                if (data.code == 0) {
                    cTag.parents("li").remove();
                    if ($('#fileList li').size() == 0) {
                        that.page($("#H_currentPage").val());
                    }
                }
            }
        });
    }
    /**
    *发送上传码通知
    ***/
    UploadCode.submitSend = function (cTag) {
        var that = this
        var _id = [];
        cTag.each(function () {
            _id.push(this.value)
        });
        this.iframeDialog = dialog({
            title: "发送上传码通知消息 ",
            content: "<iframe src='sendcode.aspx?type=2&id=" + _id.join(",") + "' style='border:none;width:800px;height:500px;'></iframe>"
        }).showModal();
    }
    UploadCode.addListEvent = function () {
        var that = this;
        $(".checkItem").click(function () {
            var flag = $(".checkItem").size() == $(".checkItem:checked").size();
            $("#CheckBox2")[0].checked = flag;
            $(this).parents()[this.checked ? "addClass" : "removeClass"]("checked");
        });
        $('#fileList li').click(function (event) {
            if (event.target.nodeName.toLowerCase() != "input" && event.target.nodeName.toLowerCase() != "a") {
                var tag = $(this).find(".checkItem")[0].click();
                $(this)[tag.checked ? "addClass" : "removeClass"]("checked");
            }
        });
        //复制地址
        $('#fileList .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);
                }
            });
        });
        //取消选中
    }
    UploadCode.autoClose = function (d) {
        setTimeout(function () {
            d.close().remove();
        }, 2000);
    }
    /**
    *加载分页
    **/
    UploadCode.page = function (currentPage) {
        var that = this;
        currentPage = currentPage ? currentPage : 0;
        function ajax(pageIndex, callback) {
            //var d = dialog();
            $.ajax({
                url: "uploadcodeList_s.aspx",
                data: { pageIndex: pageIndex },
				cache:false,
                beforeSend: function () {
                  //  d.showModal();
                },
                success: function (data) {
                   // d.close().remove();
                    $("#content").empty().append(data);
                    that.addListEvent();
                    typeof callback == "function" && callback();
                }
            });
        }
        ajax(currentPage, function () {
            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 () {
                        self.maxentries = parseInt($("#H_itemtCount").val());
                    });
                }
            });
        });
    };
    UploadCode.del = function (fileId, user) {
        var page = 0, d = dialog();
        function ajax(fileId, callback) {
            $.ajax({
                url: "uploadcodeList.aspx",
                data: { page: page + 1, type: type, asc: asc },
				cache:false,
                beforeSend: function () {
                    d.showModal();
                },
                success: function (data) {
                    d.close().remove();
                    typeof callback == "function" && callback(data);
                }
            });
        }
        function del(fileId, user, callback) {
            $.ajax({
                url: "CodeListHandler.ashx?cmd=UpdateUploadCode",
				cache:false,
                data: { id: fileId, user: user },
                success: function (data) {
                    typeof callback == "function" && callback(data);
                }
            });
        }
        del(fileId, user, function () {
            //            ajax(page, function (data) {
            //                html(data);
            //            });
            UploadCode.page();
        });
    }
    UploadCode.sendNotify = function () {
        var d = this.iframeDialog = dialog({
            content: "<iframe src='sendcode.aspx?type=2&id='" + document.all.HdnSelectedValues.value.substr(1) + "' style='border:none;width:800px;height:500px;'></iframe>",
            title: "发送通知"
        });
        function sendNotify() {
            d.showModal();
        }
        sendNotify();
    }
    /**
    *关闭模态窗口
    */
    UploadCode.closeWindow = function (flag) {
        if (this.iframeDialog) {
            this.iframeDialog.close().remove();
            this.iframeDialog = null;
        }
    }
    var closeWindow = function (flag) {
        UploadCode.closeWindow(flag);
    }
    UploadCode.init();
</script>
