authority2.vm 4.74 KB

#macro(makeRoleauthority $tree)
    #foreach(${item} in ${tree})
        <div class="authority_item">
            <div class="authority_header">
                <input type="checkbox" name="authority" value="menu:${item.id}"
                        #if(${menuRoles.contains(${item.id})})
                            checked="checked"
                        #end
                        >
                $!{item.label}
                <a href="javascript:;" class="selectAll">全选</a>
                <a href="javascript:;" class="notSelectAll">全不选</a>
            </div>
            <div style="padding-left: 15px" class="authority_body">
        #if(${item.type} != 1)
            #makeRoleauthority(${item.children})
        #else
            #foreach($res in $menuResrouceMap.get($item))
                <span style="display: inline-block;">
                    <input type="checkbox" name="authority" value="res:$res.id"
                        #if(${assignedMap.containsKey(${res.id})})
                           checked="checked"
                        #end
                            >
                    $res.resourceName
                </span>
            #end
        #end
            </div>
        </div>
    #end
#end


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

#set($url_authority = "/role/authority.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_authority">
            	<input type="hidden" value="$roleId" name="id">
            	<input type="hidden" value="" name="resourceIds">
##				#foreach($navKey in $model.keySet())
##					<div><strong>$navKey.projectName</strong></div>
##						#foreach($resource in $model.get($navKey))
##							<div>&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" #if($assignedMap[$resource.id]) checked #end value="$resource.id" name="resourceIds">$resource.resourceName [类别:#if($!{resource.type} == 2) API #elseif($!{resource.type} == 3) FRAGMENT #else URL #end] </div>
##						#end
##				#end

                <div id="resTree">
                #makeRoleauthority($menus)
                </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>

<script type="text/javascript">
    $(function(){
        $("#resTree input[type=checkbox]").click(function(){
            var val = $(this).attr("checked");
            //0未选中,1选中,2选中有子项目没有选中
            var type = $(this).attr("ty");
            if(type == null || type == undefined) {
                type = 0;
                $(this).attr("ty", 0);
            }
            if(val == "checked") {
                val = true;
            } else {
                val = false;
            }

            var parent = $(this).parents(".authority_item").first();
            var
            //未选中
            if(val == false && type == 0) {
                $(this).attr("ty", 1);
                parent.find("input[type=checkout]").each(function(){
                    $(this).attr("checked", "checked");
                    $(this).attr("ty", 1);
                });
            }
            //选中
            if(val == true && type == 1) {
                $(this).attr("ty", 0);
                parent.find("input[type=checkout]").each(function(){
                    $(this).attr("checked", "false");
                    $(this).attr("ty", 0);
                });
            }
            //选中有子项目没有选中
            if(val ==true && type == 2) {
                $(this).attr("ty", 1);
                parent.find("input[type=checkout]").each(function(){
                    $(this).attr("checked", "checked");
                    $(this).attr("ty", 1);
                });
            }


//            var i =$(this).parentsUntil(".authority_item").first().first();
        });

    });
</script>