<div class="main">

    <table class="table table-bordered">
        <thead>
            <tr>
                <td width="150px" align="left">选择表</td>
                <td>权限设置</td>
            </tr>
        </thead>

        <tr>
            <td class="leftNav">
                <div class="LeftNav-body">
                    <ul id="tableList" data-source="@Html.GetInfoTableListJson()">
                        <li data-tableId="{id}" class="item list-template-item">{remark}<b class="caret"></b></li>
                    </ul>
                </div>
            </td>
            <td>
                <div id="List" data-source="@Html.GetInfoTableListJson()">
                    <div class="item list-template-item" id="item_{id}" table_id="{id}" remark="{remark}" name="{name}" style="margin-bottom:5px;display:none">
                        <form id="form{id}" method="post" class=" form form-lg form-group-sm ui-validForm" action="@Url.ActionUrl()">
                            <div class="form-group">
                                <label class="control-label">{remark}</label>
                                <div class="controls radio">
                                    <span class="radio-inline"><input onclick="Show('{id}')" type="radio" id="Open" name="Open" value="1" />开启管理</span>
                                    <span class="radio-inline"><input onclick="Hide('{id}')" type="radio" id="Open" name="Open" value="0" checked />关闭管理</span>
                                    <span class="help-block"></span>
                                </div>
                            </div>

                            <div id="setbox_{id}" style="display:none">

                                <div class="form-group">
                                    <label class="control-label">添加权限</label>
                                    <div class="controls radio">
                                        <span class="radio-inline"><input type="radio" id="CanAdd" name="CanAdd" value="1" checked />是</span>
                                        <span class="radio-inline"><input type="radio" id="CanAdd" name="CanAdd" value="0" />否</span>
                                        <span class="help-block"></span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label">修改权限</label>
                                    <div class="controls radio">
                                        <span class="radio-inline"><input type="radio" id="CanEdit" name="CanEdit" value="2" checked />可修改所有信息</span>
                                        <span class="radio-inline"><input type="radio" id="CanEdit" name="CanEdit" value="1" />只能修改未审核信息</span>
                                        <span class="radio-inline"><input type="radio" id="CanEdit" name="CanEdit" value="0" />无</span>
                                        <span class="help-block"></span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label">删除权限</label>
                                    <div class="controls radio">
                                        <span class="radio-inline"><input type="radio" id="CanDelete" name="CanDelete" value="2" />可删除所有信息</span>
                                        <span class="radio-inline"><input type="radio" id="CanDelete" name="CanDelete" value="1" checked />只能删除未审核信息</span>
                                        <span class="radio-inline"><input type="radio" id="CanDelete" name="CanDelete" value="0" />无</span>
                                        <span class="help-block"></span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label">新增信息</label>
                                    <div class="controls radio">
                                        <span class="radio-inline"><input type="radio" id="AddDefaultState" name="AddDefaultState" value="1" />默认通过审核</span>
                                        <span class="radio-inline"><input type="radio" id="AddDefaultState" name="AddDefaultState" value="0" checked />需要审核</span>
                                        <span class="help-block"></span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label">修改已审核信息</label>
                                    <div class="controls checkbox">
                                        <span class="radio-inline"><input type="radio" id="EditDefaultState" name="EditDefaultState" value="1" />默认通过审核</span>
                                        <span class="radio-inline"><input type="radio" id="EditDefaultState" name="EditDefaultState" value="0" checked />需要重新审核</span>
                                        <span class="help-block"></span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label">退回的信息</label>
                                    <div class="controls">
                                        <span class="radio-inline"><input type="radio" id="CanResubmitCheck" name="CanResubmitCheck" value="1" />可重新提交审核</span>
                                        <span class="radio-inline"><input type="radio" id="CanResubmitCheck" name="CanResubmitCheck" value="0" checked />不可再提交进行审核</span>
                                        <span class="help-block"></span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label">发布页属性设置</label>
                                    <div class="controls">
                                        <span class="checkbox-inline"><input type="checkbox" id="CanSetGoodProperty" name="CanSetGoodProperty" value="1" />推荐属性</span>
                                        <span class="checkbox-inline"><input type="checkbox" id="CanSetHotProperty" name="CanSetHotProperty" value="1" />热门属性</span>
                                        <span class="checkbox-inline"><input type="checkbox" id="CanSetTopProperty" name="CanSetTopProperty" value="1" />置顶属性</span>
                                        <span class="help-block"></span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label">最大信息发布数</label>
                                    <div class="controls">
                                        <input type="text" class="form-control form-control-xs" id="MaxNum" name="MaxNum" value="0" maxlength="8" />
                                        <span class="help-block">0则表示不限制</span>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label">信息栏目权限</label>
                                    <div class="controls">
                                        <select name="ColumnIds" id="ColumnIds" class="form-control ColumnIds_{id}" multiple style="height:150px">
                                            <option value="">所有栏目</option>
                                        </select>
                                        <span class="help-block">不设置则默认有所有栏目权限</span>
                                    </div>
                                </div>
                            </div>


                            <div class="form-group">
                                <div class="controls">
                                    @Html.AntiForgeryToken()
                                    <input type="hidden" name="TableId" id="TableId" value="{id}" />
                                    <input type="hidden" name="MemberGroupId" id="MemberGroupId" value="@Request.QueryString["MemberGroupId"]" />
                                    <button type="button" class="btn btn-primary btn-sm" onclick="SaveSet('{id}')">保存</button>
                                    <button type="button" class="btn btn-sm btn-default ui-closeDialog">关闭</button>
                                    <span class="help-block"></span>
                                </div>
                            </div>
                        </form>

                    </div>
                </div>

            </td>
        </tr>
    </table>
</div>

<script type="text/javascript">

    $("#tableList").ListBind({ dataSourceFrom: "attr", showFooter: false});

    var memberGroupId = "@Request.QueryString["memberGroupId"]";
    function LoadData() {
        $("#List").ListBind({ dataSourceFrom: "attr", showFooter: false, callBack: "LoadedInit" });
    }
    LoadData();

    function LoadedInit() {
        var $item = $("#List").children(".item");
        $item.each(function () {
            var $this = $(this);
            var remark = $this.attr("remark");
            var tableId = $this.attr("table_id");
            var columnUrl = "/E/Column/GetList?tableId=" + tableId;
            var columnData = Ajax({ type: "get", url: columnUrl, async: false });
            $this.find("#ColumnIds").SelectBind({isTree:true},columnData);

            var ajaxUrl = "@Url.ActionUrl("GetSet")?memberGroupId=" + memberGroupId + "&tableId=" + tableId;
            var data = Ajax({ type: "get", url: ajaxUrl, async: false });
            $this.FormBind({},data);
            if ($this.find("#Open").GetChecked() == "1") {
                $("#setbox_" + tableId).show();
            }
        });
    }


    function Show(id) {
        var $obj = $("#setbox_" + id);
        $obj.show();
    }

    function Hide(id) {
        var $obj = $("#setbox_" + id);
        $obj.hide();
    }

    var prevIndex = 0;
    var setAdminInfoPermissionsIndex = GetLocalStorage("SetAdminInfoPermissionsIndex"); //html5本地储存
    if (setAdminInfoPermissionsIndex != "") {
        prevIndex = parseInt(setAdminInfoPermissionsIndex);
    }

    function RegMenu() {
        var $TbListItem = $("#tableList").children("li");
        var $item = $("#List").children(".item");
        $TbListItem.each(function (index) {
            var $this = $(this);
            $this.click(function () {
                var $this = $(this);
                var tbId = $this.attr("data-tableId");
                $this.addClass("current").siblings().removeClass("current");
                $item.hide();
                $("#item_" + tbId).show();
                SetLocalStorage("SetAdminInfoPermissionsIndex", index);
            });

        });
        $TbListItem.eq(prevIndex).click();
    }
    RegMenu();

    function SaveSet(id) {
        var ajaxUrl = "@Url.ActionUrl("SaveSet")";
        var $form = $("#form" + id);
        Loading();
        $.post(ajaxUrl, $form.Serialize(), function (data) {
            CloseLoading();
            data = JsonParse(data)
            var msg = data.Msg;
            if (msg == "success")
            {
                msg = "保存成功！";
            }
            Msg(msg);
        }, "json");
    }
</script>
