@model string
<div class="main no-border no-padding">
    <div class="alert alert-warning alert-dismissible" role="alert">
        说明：文件夹直点击可查看目录内文件，.cshtml模板文件直接点击文件名即可选择。
    </div>
    <table border=0 cellpadding=0 cellspacing=0 class="table table-bordered" style="margin-bottom:5px">
        <tr>
            <td align=left colspan="6"><span class="folder"></span><span class="lb_rootPath">@ViewBag.RootPath</span><span class="lb_currentPath" id="lbCurrentPath">Views</span> <span class="lb_back">[<a href="javascript:void(0)" onclick="GoBack()">返回上级</a>]</span></td>
        </tr>
    </table>
    <table border=0 cellpadding=0 cellspacing=0 class="table table-bordered" id="tb_list">
        <thead>
        <thead>
            <tr>
                <td align="center">名称</td>
            </tr>
        </thead>
        <tr class="item list-template-item" id="item_{id}">
            <td align=left>
                <span class="fa type-{Type}-icon"></span>
                <a href="javascript:void(0)" data-name="{name}" data-type="{Type}" class=" btn_select"><span issfile="{Type}" class="sp_name">{Name}</span></a>
                <a href="javascript:void(0)" class="btn btn-default" style="visibility:hidden">选择</a>
            </td>
        </tr>
    </table>
</div>

<script type="text/javascript">
    var objName = Request("objname");
    var $parentobj = parent.$(objName);
    if ($parentobj.length == 0) {
        $(".main").html("父级的objname对象未找到！");
    }
    var $lbCurrentPath = $("#lbCurrentPath");
    var $lb_back = $(".lb_back");

    //绑定数据
    function LoadData() {
        var path = $lbCurrentPath.text();
        var url = "@Url.ActionUrl("ListData")?path=" + encodeURIComponent(path) + "&_isload=1";
        $("#tb_list").ListBind({ url: url, callBack: "LoadedInit" });
    }

    function LoadedInit() {
        $(".type-1-icon").addClass("fa-file-o");
        $(".type-0-icon").addClass("fa-folder");
        var $lb_back = $(".lb_back");
        var currentPath = $lbCurrentPath.text();
        if (currentPath == "") {
            $lb_back.hide();
        }
        else {
            $lb_back.show();
        }
        $(".sp_name").each(function () {
            if ($(this).attr("issfile") == "1") {
            }
            else {
                $(this).attr("title", "打开文件夹")
            }
        })
    }
    LoadData();


    $(document).on("click", ".btn_select", function (event) {
        var $this = $(this);
        var name = $this.attr("data-name");
        var type = $this.attr("data-type");
        if (type == "0")
        {
            Open(name)
            return;
        }
        else if (name.indexOf(".cshtml") < 0 || name.indexOf("_") == 0)
        {
            Msg("此文件非模板文件");
            return;
        }
        var rootPath = "@ViewBag.RootPath";
        var currentPath = $lbCurrentPath.text();
        if (currentPath != "") {
            currentPath = currentPath + "/";
        }
        if (rootPath != "/Templates/") {
            currentPath = currentPath
        }
        var path = rootPath + currentPath + name;
        path = path.replace(/\/Templates\/.+\/Views\//g, "");
        $parentobj.val(path);

        if (document.all) {
            setTimeout(function () { $parentobj.triggerHandler("propertychange"); }, 10);
        }
        else {
            setTimeout(function () { $parentobj.triggerHandler("input"); }, 10);//延迟触发onput事件
        }
        CloseDialog();
    });



    //设置标签值
    function SetPath(path) {
        $lbCurrentPath.text(path);
    }


    function Open(thisPath) {
        var currentPath = $lbCurrentPath.text();
        if (currentPath != "") {
            thisPath = currentPath + "/" + thisPath;
        }
        SetPath(thisPath)
        LoadData();
    }

    function GoBack() {
        var currentPath = $lbCurrentPath.text()
        var arrCurrentPath = currentPath.split("/");
        var path = "";
        for (i = 0; i < arrCurrentPath.length - 1; i++) {
            if (path != "") {
                path += "/"
            }
            path += arrCurrentPath[i];
        }
        SetPath(path)
        LoadData();
    }

</script>


