@using PageAdmin.Common;using PageAdmin.ORM;using PageAdmin.Utils;
@{
    int fieldId = StringHelper.Format<int>(Request.QueryString["field_id"]);
    string parentGuid = Request.QueryString["parent_guid"];
    int parentId = StringHelper.Format<int>(Request.QueryString["parent_id"]);
    User currentUser = ViewBag.CurrentUser;
    dynamic fieldSet = ViewBag.FieldSet;
    string fieldType= fieldSet.field_type;
    string mimeTypes = "image/*";
    if (fieldType == "files")
    {
        mimeTypes = "*/*";
    }
    string table= fieldSet.table_name;
    string field = fieldSet.name;
}
<style type="text/css">
    .thumbnail {
        max-width: 100px;
        height: 30px;
    }
</style>
<div class="main">
    <input type="hidden" name="@field" id="@field" value="0" data-custom-params="uid:'@currentUser.Uid',userName:'@currentUser.UserName',siteId:'@ViewBag.SiteId',table:'@table',field:'@field',fieldType:'@fieldType',reName:'@fieldSet.rename',watermark:@fieldSet.watermark,thumbnail:@fieldSet.thumbnail,mimeTypes:'@mimeTypes',fileNumLimit:@fieldSet.max_num,fileSingleSizeLimit:'@fieldSet.upload_maxsize',extensions:'@fieldSet.upload_ext',parentGuid:'@parentGuid',parentId:'@parentId'">
    <table border=0 cellpadding=0 cellspacing=0 class="tb-head form-inline form-group-sm">
        <tr>
            <td>
                <div class="control-group">
                    <div class="btn-group left">
                        <button type="button" class="btn btn-default btn-sm ui-selectInvert">反选</button>
                        <button type="button" class="btn btn-default dropdown-toggle btn-sm" data-toggle="dropdown" aria-expanded="false">
                            菜单
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" role="menu">
                            <li><a href="javascript:void(0)" class="ui-dialog" data-custom-params='title:"添加",url:"@Url.Action("index","UploadPanel",new { area = "" })?objid=@field", width: "70%", height: "400px",target: "self", beforeExecute:"CheckMax"'>添加</a></li>
                            <li class="divider"></li>
                            <li><a href="javascript:void(0)" class="ui-updateMultiple" data-custom-params="url:'@Url.Action("UpdateList")?table=@ViewBag.Table',callBack:'LoadData',successMsg:'更新成功!'">更新</a></li>
                            <li class="divider"></li>
                            <li><a href="javascript:void(0)" class="ui-deleteMultiple" data-custom-params="url:'@Url.Action("Delete")?table=@ViewBag.Table&parent_guid=@parentGuid',callBack:'LoadData'">删除</a></li>
                        </ul>
                    </div>
                </div>
            </td>
        </tr>
    </table>
    <table border=0 cellpadding=0 cellspacing=0 class="table table-bordered form-inline form-group-sm" id="tb_list">
        <thead><tr>
            <td style="width:30px"><input type="checkbox" title="选择" class="ui-selectInvert" data-custom-params="isReverse:false"></td>
            <td align="center">文件</td>
            <td align="center">文件名</td>
            @*<td align="center">简介</td>*@
            <td align="center">大小</td>
            <td align="center">序号</td>
            <td align="center">管理</td>
        </tr>
        <tr class="item" id="item_{id}">
            <td align="center"><input type="checkbox"class="checked-item" value="{id}"></td>
            @if (fieldType == "images")
            {
                <td align="center"><a href="{path}" target="_blank"><img src="{thumbnail}" class="thumbnail" border="0" /></a></td>
            }
            else
            {
                <td align=left><a href="#" target="_blank" data-path="{path}" class="path"><span class="glyphicon glyphicon-paperclip"></span></a></td>
            }
            <td align="center"><input type="text" name="title" id="title" maxlength="100" style="width:95%" class="form-control"></td>
            @*<td align="center"><textarea name="content" id="content" style="height:60px;width:95%" class="form-control"></textarea></td>*@
            <td align="center">{filesize}kb</td>
            <td align="center">
                <input type="text" name="xuhao" id="xuhao" class="ui-listXuhao form-control" value='{xuhao}' style="width:50px" maxlength="3" />
            </td>
            <td align="center">
                <input type="hidden" id="guid" name="guid" value="{guid}" />
                <div class="btn-group btn-group-sm">
                    <button type="button" class="btn btn-default btn-sm ui-dialog" data-custom-params='title:"修改文件",url:"@Url.Action("index","UploadPanel",new { area = "" })?objid=@field&delid={id}", width: "70%", height: "400px",target: "self"'>修改</button>
                    <button type="button" class="btn btn-default btn-sm ui-deleteSingle" data-custom-params="url:'@Url.Action("Delete")?table=@ViewBag.Table',id:'{id}',addParams:'guid={guid}',callBack:'LoadData'">删除</button>
                </div>
            </td>
        </tr>
    </table>
</div>

<script type="text/javascript">

    //判断适合和父级页面域名一样
    if (document.domain != parent.document.domain) {
        $("#uploader").html("非法请求！");
    }

    function init() {
        $path = $(".path");
        $path.each(function () {
            var $this = $(this);
            var path = $this.attr("data-path");
            var arrPath=path.split("/");
            $this.attr("href", path);
            $this.children().eq(0).text(arrPath[arrPath.length-1]);
        });
    }

    var maxNum=@fieldSet.max_num
    var $fieldObj = $("#@field");
    function SetParent() {
        var parent = Parent();
        var objId = "@Request.QueryString["objid"]";
        var recordCounts = $("#lb_recordcount").html();
        $fieldObj.val(recordCounts);
        if (objId != "") {
            $parentFieldObj = parent.$("#" + objId);
        }
        if ($parentFieldObj.length > 0) {
            $parentFieldObj.html(recordCounts);
        }
    }

    var $tbList = $("#tb_list");
    var url = "@Url.Action("ListData")?field_id=@fieldId&table=@ViewBag.Table&parent_guid=@parentGuid&parent_id=@parentId";
    function LoadData() {
        $tbList.ListBind(url, {callBack: "LoadedInit" });
    }
    function LoadedInit()
    {
        init();
        SetParent();
    }
    LoadData();

    function CheckMax()
    {
        if(maxNum>0)
        {
            var uploadedNum=parseInt($fieldObj.val());
            if(uploadedNum>=maxNum)
            {
                Msg("最多只能发布" + maxNum + "个文件！");
                return false;
            }
        }
        return true;
    }
</script>