@model string
@{
    string Id = Request.QueryString["id"];
}
<div class="main">
    <form class="form-horizontal form-group-sm form ui-validForm" method="post">
        <div class="control-group">
            <label class="control-label" for="name">菜单名称</label>
            <div class="controls">
                <input type="text" name="name" id="name" maxlength="30" data-validate="dataType:'*" nullMsg:'请填写菜单名称" class="form-control">
            </div>
            <span class="help-block"></span>
        </div>

        <div class="control-group top_menu_disable">
            <label class="control-label" for="is_final">菜单类型</label>
            <div class="controls radio">
                <label class="radio-inline"><input type="radio" name="is_final" id="is_final" value="1" checked>最终菜单</label>
                <label class="radio-inline"><input type="radio" name="is_final" id="is_final" value="0">分类节点</label>
                <span class="help-block"></span>
            </div>
        </div>

        <div class="control-group top_menu_disable is_final_1_disable">
            <label class="control-label" for="is_expand">子级默认展开</label>
            <div class="controls radio">
                <label class="radio-inline"><input type="radio" name="is_expand" id="is_expand" value="1" checked>是</label>
                <label class="radio-inline"><input type="radio" name="is_expand" id="is_expand" value="0">否</label>
                <span class="help-block">用于设置包含的子菜单的展开方式</span>
            </div>
        </div>

        <div class="control-group top_menu_disable is_final_0_disable">
            <label class="control-label" for="url">菜单项目</label>
            <div class="controls">
                <textarea id="items" name="items" class="form-control textarea" data-validate="dataType:'*" nullMsg:'请填写菜单项目"></textarea>
                <span class="help-block">格式：控制器名.方法名,中文菜单,每行一组，默认显示第一个页面</span>
            </div>
        </div>

        <div class="control-group">
            <label class="control-label" for="show">系统菜单</label>
            <div class="controls radio">
                <label class="radio-inline"><input type="radio" name="is_sys" id="is_sys" value="1" checked>是</label>
                <label class="radio-inline"><input type="radio" name="is_sys" id="is_sys" value="0">否</label>
                <span class="help-block">系统菜单增加后不可以直接删除，只能修改为非系统字段后再删除</span>
            </div>
        </div>

        <div class="control-group">
            <label class="control-label" for="show">是否启用</label>
                <div class="controls radio">
                    <label class="radio-inline"><input type="radio" name="show" id="show" value="1" checked>是</label>
                    <label class="radio-inline"><input type="radio" name="show" id="show" value="0">否</label>
                </div>
                <span class="help-block"></span>
        </div>

        <div class="control-group">
            <label class="control-label" for="xuhao">序号：</label>
            <div class="controls">
                <input type="text" name="xuhao" id="xuhao" style="width:50px" maxlength="3" value="1" class="form-control" data-validate="dataType:'n">
                <span class="help-block"></span>
            </div>
        </div>

        <div class="control-group postarea">
            <div class="controls">
                <!--@Html.AntiForgeryToken()   控制器中使用[ValidateAntiForgeryToken]特性防止CSRF攻击-->
                <input type="hidden" name="level" id="level" value="" />
                <input type="hidden"  name="parent_guid" id="parent_guid" value="@Request.QueryString["parent_guid"]" />
                <input type="hidden" name="guid" id="guid" value="@Guid.NewGuid().ToString("N")" />
                <button type="button" class="btn btn-primary ui-pagePost" data-custom-params="url:'@Url.Action()',callBack:'PostRefreshBack'">提交</button>
                <button type="button" class="btn btn-primary ui-closeDialog">关闭</button>
                <span class="help-block"></span>
            </div>
        </div>
</form>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        AutoDialog()
    }
    );
    //设置菜单类型控制tr的显示或影藏，顶部菜单或左侧菜单
    function SetTr(parent_guid) {
        if (parent_guid == "")
        {
            $(".top_menu_disable").hide();
            $(".top_menu_disable").find("input,select,textarea").removeAttr("datatype");
        }
    }
    var $menu_items = $("#items");
    //根据isfinal类型来控制tr显示或影藏
    function ChangFinal(isFinal) {
        $(".is_final_0_disable").hide();
        $(".is_final_1_disable").hide();
        $menu_items.removeAttr("datatype").val("");
        if (isFinal == "0") {
            $(".is_final_1_disable").show();
        }
        else
        {
            $(".is_final_0_disable").show();
            $menu_items.attr("datatype", "*");
        }
    }
    //给is_final表单注册点击事件
    $("input[name='is_final']").click(function () {
        ChangFinal($(this).val());
    })
    var parent_guid = "@Request.QueryString["parent_guid"]";
    var id=Request("id");
    if(IsInt(id))
    {
        var serverData =@Html.Raw(Model??"null");
        var jsonData = serverData[0];
        parent_guid = jsonData["parent_guid"];
        var isFinal = jsonData["is_final"];
        $("input[name='is_final']").attr("disabled","disabled");
        ChangFinal(isFinal);
        $(".form").setForm(jsonData);
    }
    else
    {
        ChangFinal("1");
    }
    SetTr(parent_guid);
</script>
