assign_access.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <extend name="Public:base" />
  2. <block name="content">
  3. <div class="page-header">
  4. <h1>
  5. 权限分配
  6. <small>
  7. <i class="icon-double-angle-right"></i>
  8. {$crumbs}
  9. </small>
  10. </h1>
  11. <h2>
  12. <p>您正在为角色:<b>{$role.name}</b> 分配权限,项目和模块有全选和取消全选功能</p>
  13. </h2>
  14. </div>
  15. <div class="row">
  16. <div class="col-xs-12">
  17. <div class="table-responsive">
  18. <form id="assignForm">
  19. <table class="table table-striped table-bordered table-hover">
  20. <tbody>
  21. <volist name="nodes" id="group">
  22. <tr>
  23. <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>
  24. </tr>
  25. <volist name="group['modules']" id="module">
  26. <tr>
  27. <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>
  28. </tr>
  29. <tr>
  30. <td style="padding-left: 50px;">
  31. <volist name="module['actions']" id="action">
  32. <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> &nbsp;&nbsp;&nbsp;
  33. </volist>
  34. </td>
  35. </tr>
  36. </volist>
  37. </volist>
  38. </tbody>
  39. </table>
  40. <input type="hidden" name="id" value="{$role.id}"/>
  41. </form>
  42. <div class="commonBtnArea" >
  43. <button class="btn submit">提交</button>
  44. <button class="btn reset">恢复</button>
  45. <button class="btn empty">清空</button>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </block>
  51. <block name="javascript">
  52. <script>
  53. //初始化数据
  54. function setAccess(){
  55. //清空所有已选中的
  56. $("input[type='checkbox']").prop("checked",false);
  57. var access=$.parseJSON('{$role.access}');
  58. var access_length=access.length;
  59. if(access_length>0){
  60. for(var i=0;i<access_length;i++){
  61. $("input[type='checkbox'][value='" + access[i].val + "']").prop("checked","checked");
  62. }
  63. }
  64. }
  65. $(function(){
  66. //执行初始化数据操作
  67. setAccess();
  68. //为项目时候全选本项目所有操作
  69. $("input[level='1']").click(function(){
  70. var obj=$(this).attr("obj")+"_";
  71. $("input[obj^='"+obj+"']").prop("checked",$(this).prop("checked"));
  72. });
  73. //为模块时候全选本模块所有操作
  74. $("input[level='2']").click(function(){
  75. var obj=$(this).attr("obj")+"_";
  76. $("input[obj^='"+obj+"']").prop("checked",$(this).prop("checked"));
  77. //分隔obj为数组
  78. var tem=obj.split("_");
  79. //将当前模块父级选中
  80. if($(this).prop('checked')){
  81. $("input[obj='node_"+tem[1]+"']").prop("checked","checked");
  82. }
  83. });
  84. //为操作时只要有勾选就选中所属模块和所属项目
  85. $("input[level='3']").click(function(){
  86. var tem=$(this).attr("obj").split("_");
  87. if($(this).prop('checked')){
  88. //所属项目
  89. $("input[obj='node_"+tem[1]+"']").prop("checked","checked");
  90. //所属模块
  91. $("input[obj='node_"+tem[1]+"_"+tem[2]+"']").prop("checked","checked");
  92. }
  93. });
  94. //重置初始状态,勾选错误时恢复
  95. $(".reset").click(function(){
  96. setAccess();
  97. });
  98. //清空当前已经选中的
  99. $(".empty").click(function(){
  100. $("input[type='checkbox']").prop("checked",false);
  101. });
  102. $(".submit").click(function(){
  103. var sub_url = "{:U('Roles/doAssignAccess')}";
  104. var post_data = $('#assignForm').serialize();
  105. $.ajax({
  106. url:sub_url,
  107. type:'post',
  108. data:post_data,
  109. success:function(res){
  110. console.log(res);
  111. }
  112. })
  113. });
  114. });
  115. </script>
  116. </block>