123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <extend name="Public:base" />
- <block name="content">
-
- <div class="page-header">
- <h1>
- 权限分配
- <small>
- <i class="icon-double-angle-right"></i>
- {$crumbs}
- </small>
- </h1>
- <h2>
- <p>您正在为角色:<b>{$role.name}</b> 分配权限,项目和模块有全选和取消全选功能</p>
- </h2>
- </div>
-
- <div class="row">
- <div class="col-xs-12">
- <div class="table-responsive">
- <form id="assignForm">
- <table class="table table-striped table-bordered table-hover">
- <tbody>
- <volist name="nodes" id="group">
- <tr>
- <td style="font-size: 14px;"><label><input name="access[]" level="1" type="checkbox" obj="node_{$group.id}" value="{$group.id}:1:0"/> <b>[应用]</b> {$group.title}</label></td>
- </tr>
- <volist name="group['modules']" id="module">
- <tr>
- <td style="padding-left: 30px; font-size: 14px;"><label><input name="access[]" level="2" type="checkbox" obj="node_{$group.id}_{$module.id}" value="{$module.id}:2:{$module.pid}"/> <b>[模块]</b> {$module.title}</label></td>
- </tr>
- <tr>
- <td style="padding-left: 50px;">
- <volist name="module['actions']" id="action">
- <label><input name="access[]" level="3" type="checkbox" obj="node_{$group.id}_{$module.id}_{$action.id}" value="{$action.id}:3:{$action.pid}"/> {$action.title}</label>
- </volist>
- </td>
- </tr>
- </volist>
- </volist>
- </tbody>
- </table>
- <input type="hidden" name="id" value="{$role.id}"/>
- </form>
- <div class="commonBtnArea" >
- <button class="btn submit">提交</button>
- <button class="btn reset">恢复</button>
- <button class="btn empty">清空</button>
- </div>
- </div>
- </div>
- </div>
- </block>
- <block name="javascript">
- <script>
- //初始化数据
- function setAccess(){
- //清空所有已选中的
- $("input[type='checkbox']").prop("checked",false);
- var access=$.parseJSON('{$role.access}');
- var access_length=access.length;
- if(access_length>0){
- for(var i=0;i<access_length;i++){
- $("input[type='checkbox'][value='" + access[i].val + "']").prop("checked","checked");
- }
- }
- }
- $(function(){
- //执行初始化数据操作
- setAccess();
- //为项目时候全选本项目所有操作
- $("input[level='1']").click(function(){
- var obj=$(this).attr("obj")+"_";
- $("input[obj^='"+obj+"']").prop("checked",$(this).prop("checked"));
- });
- //为模块时候全选本模块所有操作
- $("input[level='2']").click(function(){
- var obj=$(this).attr("obj")+"_";
- $("input[obj^='"+obj+"']").prop("checked",$(this).prop("checked"));
- //分隔obj为数组
- var tem=obj.split("_");
- //将当前模块父级选中
- if($(this).prop('checked')){
- $("input[obj='node_"+tem[1]+"']").prop("checked","checked");
- }
- });
- //为操作时只要有勾选就选中所属模块和所属项目
- $("input[level='3']").click(function(){
- var tem=$(this).attr("obj").split("_");
- if($(this).prop('checked')){
- //所属项目
- $("input[obj='node_"+tem[1]+"']").prop("checked","checked");
- //所属模块
- $("input[obj='node_"+tem[1]+"_"+tem[2]+"']").prop("checked","checked");
- }
- });
- //重置初始状态,勾选错误时恢复
- $(".reset").click(function(){
- setAccess();
- });
- //清空当前已经选中的
- $(".empty").click(function(){
- $("input[type='checkbox']").prop("checked",false);
- });
- $(".submit").click(function(){
- var sub_url = "{:U('Roles/doAssignAccess')}";
- var post_data = $('#assignForm').serialize();
- $.ajax({
- url:sub_url,
- type:'post',
- data:post_data,
- success:function(res){
- console.log(res);
- }
- })
-
- });
- });
- </script>
- </block>
|