<%@ page language="VB" autoeventwireup="false" inherits="secure_serverFiles_getFiles, App_Web_nrcem01d" enableviewstate="False" enableviewstatemac="False" enableeventvalidation="False" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" href="/jslib/jquery/plugins/contextmenu/contextmenu.css" type="text/css" />
    <link href="/jslib/jquery/plugins/jquery.contextMenu-1.01/jquery.contextMenu.css"
        rel="stylesheet" type="text/css" />

    <script src="/jslib/requestUrl.js" type="text/javascript"></script>

    <style type="text/css">
        .f1
        {
            background-color: #f7f6f3;
            color: #1c94c4;
            padding: 2px;
        }
        .f2
        {
            background-color: white;
            color: #1c94c4;
            padding: 2px;
        }
        #fileList
        {
            list-style-type: none;
            padding: 0px;
            margin: 0px;
            border-collapse: collapse;
            color: #333333;
        }
        #fileList .ui-selecting
        {
            background: #FECA40;
        }
        #fileList .ui-selected
        {
            background: #F39814;
            color: white;
        }
        #fileList li
        {
            cursor: default;
            width: 100%;
            outline-style: none;
            outline-color: invert;
            outline-width: medium;
            padding: 1px;
            margin: 3px;
        }
        #fileList li input
        {
            overflow: visible;
        }
    </style>

    <script src="/jslib/jquery/jquery-lastest.js" type="text/javascript">
        //placeholder;
    </script>

    <script src="/jslib/jquery/plugins/contextmenu/jquery.contextmenu.js" type="text/javascript"></script>

    <script src="/jslib/jquery/plugins/jquery-ui-1.8/js/jquery-ui-1.8.custom.min.js"
        type="text/javascript"></script>

    <script type="text/javascript">

        function setOpenerUrl(srcEvent) {
            var t = $(srcEvent);
            var fileUrl = $("#rootPath").val() + $.trim(t.text());
            if (window.top.opener) { 
            window.top.opener.SetUrl(encodeURI(fileUrl).replace('#', '%23'));
            window.top.close();
            window.top.opener.focus();
            };
            
        }

        function preview(target) {

            var path = $("#rootPath").val() + target;
            window.open(path);

        };
        function deleteFiles() {
            var t = ""
            var selected = $("li[class*='ui-selected']").each(function(i) {
                t = t + "," + $.trim(this.innerText);
            });
            if (t == "") return;
            t = t.substr(1);
            if (confirm("删除文件会导致指向原文件的超级链接无效！\r\n该项操作不可恢复！确定删除吗？")) {
                $("#tb_data").val(t);
                document.getElementById("deleteFilesButton").click();
            };
        };
        function reName(srcEvent) {
            var t = $(srcEvent);
            var preName = $.trim(t.text());
            t.html("<input id='tb_newFileName' name='tb_newFileName' value='" + preName + "' />");
            $("#tb_data").val(preName);
            $("#tb_newFileName").one("blur", function() {
                var newName = $(this).val();
                if (newName != preName) {
                    if (confirm("修改文件名会导致指向原文件的超级链接无效！\r\n确定修改吗？")) {
                         document.getElementById("btn_reName").click();

                    } else { t.text(preName); };

                } else { t.text(preName); };

            }).bind("keypress", function(event) {
                if (event.keyCode == 27) {
                    t.text(preName); ; return false;
                };
                if (event.keyCode == 13) {
                    this.blur(); return false;
                };

            });
            document.getElementById("tb_newFileName").focus();
        };
        function cutFiles() {

            var t = ""
            var selected = $("li[class*='ui-selected']").each(function(i) {
                t = t + "," + $.trim(this.innerText);
            });
            if (t == "") return;
            t = t.substr(1);
            parent.action = "cutFiles";
            parent.data1 = requestQueryString("path");
            parent.data2 = t;
        };
        function copyFiles() {
            var t = ""
            var selected = $("li[class*='ui-selected']").each(function(i) {
                t = t + "," + $.trim(this.innerText);
            });
            if (t == "") return;
            t = t.substr(1);
            parent.action = "copyFiles";
            parent.data1 = requestQueryString("path");
            parent.data2 = t;
        };
        function pasteFiles() {
            $("#tb_data").val(parent.prePath);
            $("#tb_data2").val(parent.preFiles);
            if (parent.subAction == "copy")
                document.getElementById("btn_paste").click();
            if (parent.subAction == "cut")
                document.getElementById("btn_paste_cut").click();
            parent.subAction = null; parent.prePath = null; parent.preFiles = null;
        };
        $().ready(
        function() {
            $("#fileList").selectable();


            var option = { width: 90, items: [
                            { text: "预览", icon: "images/preview.png", alias: "1-6", action: menuAction },
                            { text: "选择", icon: "images/select.png", alias: "1-7", action: menuAction },

                            { text: "重命名", icon: "/paperStyle/images/edit.png", alias: "1-1", action: menuAction },

                            { text: "剪切", icon: "images/cut.png", alias: "1-2", action: menuAction },
                            { text: "复制", icon: "images/copy.png", alias: "1-3", action: menuAction },

                            { text: "删除", icon: "images/delete.png", alias: "1-5", action: menuAction }

                            ], onShow: applyrule,
                onContextMenu: BeforeContextMenu
            };
            function menuAction(e, target) {//this.data.alias

                if (this.data.alias == "1-7") { setOpenerUrl(target) };
                if (this.data.alias == "1-6") { preview($.trim(target.innerText)); };
                if (this.data.alias == "1-2") { cutFiles(); };
                if (this.data.alias == "1-3") { copyFiles(); };

                if (this.data.alias == "1-5") { deleteFiles(); };
                if (this.data.alias == "1-1") { reName(target); };

            }
            function applyrule(menu) {

                var selected = $("li[class*='ui-selected']");
                var name = "";
                var arr;

                if (selected.length == 1) { arr = []; name = "nn1" } else { arr = ["1-6", "1-7", "1-1"]; name = "nnn1" };

                menu.applyrule({ name: name,
                    disable: true,
                    items: arr
                });
            }
            function BeforeContextMenu() {
                if (event.srcElement.tagName != 'LI') return false;
                if ($(event.srcElement).attr("class").indexOf("ui-selected") == -1) {
                    $("li").removeClass("ui-selected");
                    $(event.srcElement).addClass("ui-selected");

                };



                return true;
            }

            $("#fileList LI").contextmenu(option)

        });
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <h3 style="width: 100%">
        <asp:Literal ID="Literal1" runat="server"></asp:Literal></h3>
    <div>
        <input type="hidden" id="rootPath" runat="server" /><input id="tb_data" name="tb_data"
            type="hidden" />
        <input id="tb_data2" name="tb_data2" type="hidden" />
        <input type="button" id="deleteFilesButton" runat="server" style="display: none" />
        <input type="button" id="btn_reName" runat="server" style="display: none" /><input
            type="button" id="btn_paste" runat="server" style="display: none" />
        <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
                <ul id="fileList">
            </HeaderTemplate>
            <ItemTemplate>
                <li title="文件操作请使用鼠标右键菜单" class="f1" ondblclick="preview($.trim(this.innerText));"><%#DataBinder.Eval(Container, "DataItem")%></li></ItemTemplate>
            <AlternatingItemTemplate>
                <li title="文件操作请使用鼠标右键菜单" class="f2" ondblclick="preview($.trim(this.innerText));"><%#DataBinder.Eval(Container, "DataItem")%></li></AlternatingItemTemplate>
            <FooterTemplate>
                </ul></FooterTemplate>
        </asp:Repeater>
        <div>
            <table>
                <tr>
                    <td>
                        上传文件
                    </td>
                    <td>
                        <asp:FileUpload ID="FileUpload1" runat="server" /><asp:RequiredFieldValidator ID="RequiredFieldValidator1"
                            runat="server" ErrorMessage="*" ControlToValidate="FileUpload1" ValidationGroup="up"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        重命名为
                    </td>
                    <td>
                        <asp:TextBox ID="TB_upFileName" runat="server"></asp:TextBox><asp:Button ID="btn_upload" runat="server" Text="开始上传" ValidationGroup="up" />
                    </td>
                </tr>
                <asp:Label ID="L_msg" runat="server" Text="" ForeColor="#CC0000" Visible="False"></asp:Label>
            </table>
            
        </div>
        
    </div>
    </form>
</body>
</html>
