roleMenu.vm 3.07 KB

#set($page_title="编辑")
#set($crumbs="首页:/home,角色列表:/role/list.do")

#set($url_roleMenu = "/role/roleMenu.do")

<div class="page-content">
    <div class="page-header">
        <h1>
            <small>
                <i class="icon-double-angle-right"></i>
            分配菜单
            </small>
        </h1>
    </div>
    <!-- /.page-header -->

    <div class="row">
        <div class="col-xs-12">
            <!-- PAGE CONTENT BEGINS -->

            <form class="form-horizontal" role="form" method="post" action="$url_roleMenu">
                #if($obj.id)
                <input type="hidden" value="$obj.id" name="id">
                #end
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right"
                               for="form-field-1"> 菜单: </label>

                        <div class="col-xs-12 col-sm-4">
                            <div id="ztree" class="ztree"></div>
                        </div>
                    </div>
                <div id="formHidden"></div>

                <div class="clearfix form-actions">
                    <div class="col-md-offset-3 col-md-9">
                        <button class="btn btn-info" type="submit" id="submitbtn">
                            <i class="icon-ok bigger-110"></i>
                            提交
                        </button>

                        &nbsp; &nbsp; &nbsp;
                        <a class="btn btn-info" href="javascript:history.back()">
                            <i class="icon-undo bigger-110"></i>
                            返回
                        </a>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<link rel="stylesheet" href="/static/module/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="/static/module/ztree/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="/static/module/ztree/js/jquery.ztree.excheck-3.5.js"></script>


#macro(makeRoleTree $tree)
#foreach(${item} in ${tree})
    #if($velocityCount> 1),#end{
        id:$!{item.id}
        , name: "$!{item.label}"
        #if(${roles.contains(${item.id})})
        , checked: true
        #end
        #if(${item.type} != 1)
            ,open:true
            ,isParent: true
            , children: [
                #makeRoleTree(${item.children})
            ]
        #end
    }
#end
#end
<script type="text/javascript">
    var znodes = [
        #makeRoleTree($tree)
    ];
    var setting = {
        check: {
            enable: true
        }
    }

    $(function(){
        var tree = $.fn.zTree.init($("#ztree"), setting, znodes);
        $("#submitbtn").click(function(){
            var div = $("#formHidden");
            div.html("");
            var items = tree.getCheckedNodes();
            for(var i in items) {
                var item = items[i];
                var hi = "<input type='hidden' name='roleMenus' value='"+item.id+"'>"
                div.append(hi);
            }
        });
    })

</script>