<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" id="form_view_id">
</div>
</div>
    <script id="form_tpl_id" type="text/html">
        <input type="hidden" name="id" value="{{d.menu.id}}" />
    <div class="layui-form-item">
        <label class="layui-form-label required">菜单标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" lay-reqtext="菜单标题不能为空" placeholder="请输入菜单标题" value="{{d.menu.title}}" class="layui-input">
            <tip>填写标题。</tip>
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label ">菜单链接</label>
        <div class="layui-input-block">
            <input type="text" name="href" placeholder="请输入菜单页面链接" value="{{d.menu.href}}" class="layui-input">
            <tip>推荐使用相对portal目录的路径，例如：page/upload.html</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label ">排序值</label>
        <div class="layui-input-block">
            <input type="text" name="sort_num" placeholder="请输入排序值，整数" value="{{d.menu.sort_num}}" class="layui-input">
            <tip>值越小越在前面</tip>
        </div>
    </div>

    <div class="layui-form-item" pane="">
        <label class="layui-form-label">菜单权限分配</label>
        <div class="layui-input-block">
	{{#  layui.each(d.menu.assign_admin_roles, function(index, item){ }}
		{{# if(item.role == 'super') { }}
			<input type="checkbox" name="assign_admin_roles[{{item.role}}]" lay-skin="primary" title="{{item.role_name}}" checked="" disabled="">
		{{#  } else { }}
			<input type="checkbox" name="assign_admin_roles[{{item.role}}]" lay-skin="primary" title="{{item.role_name}}" {{# if(item.on) { }} checked=""  {{# } }}>
		{{#  } }}
	{{#  }); }}	
            <br/><tip>超级管理员拥有全部菜单权限。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label ">管理员菜单权限</label>
        <div class="layui-input-block">
            <input type="text" name="assgin_admin_usernames" placeholder="请输入需要单独分配权限的管理员账号" value="{{d.menu.assgin_admin_usernames}}" class="layui-input">
            <tip>多个管理员账号，使用竖线|分开，例如：lucy|tony。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">修改菜单</button>
        </div>
    </div>
    </script>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['laytpl', 'form'], function () {
        var form = layui.form,
            layer = layui.layer,
            router = layui.router(),
            laytpl = layui.laytpl,
            $ = layui.$;

        var id = sessionStorage.getItem('edit_id'); // router.search.id
        $.getJSON('/?s=Portal.Page.GetMenu&id=' + id, function (data) {
            if (data.ret != 200 || !data.data.menu) {
                layer.msg(data.msg || '菜单不存在或已经删除');
            }

            var getTpl = form_tpl_id.innerHTML,
                view = document.getElementById('form_view_id');

            laytpl(getTpl).render(data.data, function(html){
                  view.innerHTML = html;
                  form.render('checkbox');
            });
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: '/?s=Portal.Page.UpdateMenu',
                type:'post',
                data: data.field,
                success:function(data){
                    if (data.ret != 200) {
                        layer.msg(data.msg);
                        return;
                    }

                    var index = layer.alert('菜单修改成功，请刷新', function () {
                        // 关闭弹出层
                        layer.close(index);

                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);

                        //window.location.reload();
                    });
                },
                complete: function () {
                }
            });

            return false;
        });

    });
</script>
</body>
</html>
