<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('NavMenu/index',['nav_id'=>$nav_id])}">导航菜单</a></li>
        <li class="active"><a>{:lang('ADMIN_MENU_ADD')}</a></li>
    </ul>

    <form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('NavMenu/addPost')}">
        <fieldset>
            <div class="form-group">
                <label class="col-sm-2 control-label">上级:</label>
                <div class="col-md-6 col-sm-10">
                    <select name="parent_id" class="form-control">
                        <option value="0">/</option>
                        {$nav_trees}
                    </select>
                </div>
            </div>
            <div class="form-group form-inline">
                <label class="col-sm-2 control-label"><span class="form-required">*</span>地址:</label>
                <div class="col-md-6 col-sm-10">
                    <input type="radio" id="external-link-radio">
                    <input type="text" class="form-control" name="href" id="external-link-input">
                    <input type="radio" id="select-href-radio">
                    <select name="href" id="select-href" class="form-control">
                        <option value="{:base64_encode('home')}" data-name="首页">首页</option>
                        <foreach name="navs" item="vo">
                            <optgroup label="{$vo.name}">
                                {$vo.html}
                            </optgroup>
                        </foreach>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label"><span class="form-required">*</span>菜单名称:</label>
                <div class="col-md-6 col-sm-10">
                    <input type="text" class="form-control" name="name" id="name-input">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">打开方式:</label>
                <div class="col-md-6 col-sm-10">
                    <select class="form-control" name="target">
                        <option value="">默认方式</option>
                        <option value="_blank">新窗口打开</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">图标:</label>
                <div class="col-md-6 col-sm-10">
                    <input type="text" class="form-control" name="icon" value="">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">显示:</label>
                <div class="col-md-6 col-sm-10">
                    <select name="status" class="form-control">
                        <option value="1">显示</option>
                        <option value="0">隐藏</option>
                    </select>
                </div>
            </div>
        </fieldset>

        <div class="col-sm-offset-2 col-sm-10">
            <input type="hidden" name="nav_id" value="{$nav_id}"/>
            <button type="submit" class="btn btn-primary js-ajax-submit">{:lang("SAVE")}</button>
            <a class="btn btn-default" href="{:url('NavMenu/index',['nav_id'=>$nav_id])}">返回</a>
        </div>
    </form>

</div>
<script src="__STATIC__/js/admin.js"></script>
<script>
    $(function () {
        $("#select-href,#select-href-radio").click(function () {
            checkChange(2);
        });

        $("#select-href").change(function () {
            var $this = $(this);
            var label = $this.find("option[value='" + $this.val() + "']").data('name');
            $('#name-input').val(label);
        });

        $("#external-link-input,#external-link-radio").click(function () {
            checkChange(1);
        });

        function checkChange(i) {
            if (i == 1) {
                //自动输入url
                $('#external-link-input').attr('name', 'external_href');
                $('#select-href').removeAttr('name');
                $('#select-href-radio').prop('checked', false);
                $('#external-link-radio').prop('checked', true);
            } else {
                //选择链接url
                $('#select-href').attr('name', 'href');
                $('#external-link-input').removeAttr('name');
                $('#select-href-radio').prop('checked', true);
                $('#external-link-radio').prop('checked', false);
            }
        }
    });
</script>
</body>
</html>