人人商城

perms.html 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <div class="form-group">
  2. <label class="col-sm-2 control-label">可用权限</label>
  3. <div class="col-sm-10 col-xs-12">
  4. <div id="accordion" class="panel-group">
  5. <div class='panel panel-default' >{php $i=0}
  6. {loop $perms['parent'] $key $value}
  7. <div class='panel-heading' style='background:#f8f8f8' >
  8. <a class="btn btn-link btn-sm pull-right" data-toggle="collapse" data-parent="#accordion" href="#collapse{$key}"><i class='fa fa-angle-down'></i> 展开</a>
  9. <label class='checkbox-inline'>
  10. <input type='checkbox' id="perm_{$key}" value='{$key}' class='perm-all perms' data-group='{$key}'
  11. {if in_array($key,$role_perms) || in_array($key,$user_perms) } checked{/if}
  12. {if in_array($key,$role_perms) && $_W['action']=='perm.user'} disabled{/if}
  13. /> {$value['text']}
  14. </label>
  15. </div>
  16. <div id="collapse{$key}" class="panel-collapse {if $i==0}in{else}collapse{/if}">
  17. <div class='panel-body perm-group'>
  18. {if count($perms['parent'][$key]) >1}
  19. <span>
  20. {loop $perms['parent'][$key] $ke $val}
  21. {if $ke != 'text'}
  22. <label class='checkbox-inline'>
  23. <input type='checkbox' value='{$key}.{$ke}' class='perm-item perms'
  24. data-group='{$key}' data-parent='text'
  25. {if in_array($key.".".$ke,$role_perms) || in_array($key.".".$ke,$user_perms)} checked{/if}
  26. {if in_array($key.".".$ke,$role_perms) && $_W['action']=='perm.user'} disabled{/if}
  27. /> {php echo str_replace("-log", "", $val)}
  28. </label>
  29. {else}
  30. <label class='checkbox-inline'>
  31. <input type='checkbox' value='{$key}' class='perm-all-item perms'
  32. data-group='{$key}' data-parent='text'
  33. {if in_array($key,$role_perms) || in_array($key,$user_perms)} checked{/if}
  34. {if in_array($key,$role_perms) && $_W['action']=='perm.user'} disabled{/if}
  35. /> <b>{php echo str_replace("-log", "", $val)}</b>
  36. </label>
  37. {/if}
  38. {/loop}
  39. </span>
  40. <br>
  41. {/if}
  42. {loop $perms['son'][$key] $ke $val}
  43. {if count($val) >1}
  44. <span>
  45. {loop $val $k $v}
  46. {if $k != 'text'}
  47. <label class='checkbox-inline'>
  48. <input type='checkbox' value='{$key}.{$ke}.{$k}' class='perm-item perms'
  49. data-group='{$key}' data-parent='{$ke}' data-son="{$k}"
  50. {if in_array($key.".".$ke.".".$k,$role_perms) || in_array($key.".".$ke.".".$k,$user_perms)} checked{/if}
  51. {if in_array($key.".".$ke.".".$k,$role_perms) && $_W['action']=='perm.user'} disabled{/if}
  52. /> {php echo str_replace("-log", "", $v)}
  53. </label>
  54. {else}
  55. <label class='checkbox-inline'>
  56. <input type='checkbox' value='{$key}.{$ke}' class='perm-all-item perms'
  57. data-group='{$key}' data-parent='{$ke}' data-son="{$k}"
  58. {if in_array($key.".".$ke,$role_perms) || in_array($key.".".$ke,$user_perms)} checked{/if}
  59. {if in_array($key.".".$ke,$role_perms) && $_W['action']=='perm.user'} disabled{/if}
  60. /> <b>{php echo str_replace("-log", "", $v)}</b>
  61. </label>
  62. {/if}
  63. {/loop}
  64. </span>
  65. <br>
  66. {/if}
  67. {/loop}
  68. {loop $perms['grandson'][$key] $ke $val}
  69. {loop $val $k $v}
  70. {if count($v) >1}
  71. <span>
  72. {loop $v $kk $vv}
  73. {if $kk != 'text'}
  74. <label class='checkbox-inline'>
  75. <input type='checkbox' value='{$key}.{$ke}.{$k}.{$kk}' class='perm-item perms'
  76. data-group='{$key}' data-parent='{$ke}' data-son="{$k}" data-grandson="{$kk}"
  77. {if in_array($key.".".$ke.".".$k.".".$kk,$role_perms) || in_array($key.".".$ke.".".$k.".".$kk,$user_perms)} checked{/if}
  78. {if in_array($key.".".$ke.".".$k.".".$kk,$role_perms) && $_W['action']=='perm.user'} disabled{/if}
  79. /> {php echo str_replace("-log", "", $vv)}
  80. </label>
  81. {else}
  82. <label class='checkbox-inline'>
  83. <input type='checkbox' value='{$key}.{$ke}.{$k}' class='perm-all-item perms'
  84. data-group='{$key}' data-parent='{$ke}' data-son="{$k}" data-grandson="{$kk}"
  85. {if in_array($key.".".$ke.".".$k,$role_perms) || in_array($key.".".$ke.".".$k,$user_perms)} checked{/if}
  86. {if in_array($key.".".$ke.".".$k,$role_perms) && $_W['action']=='perm.user'} disabled{/if}
  87. /> <b>{php echo str_replace("-log", "", $vv)}</b>
  88. </label>
  89. {/if}
  90. {/loop}
  91. </span>
  92. <br>
  93. {/if}
  94. {/loop}
  95. {/loop}
  96. </div>
  97. </div>
  98. {php $i++}
  99. {/loop}
  100. </div>
  101. </div>
  102. </div>
  103. <input type="hidden" name="permsarray" value="">
  104. </div>
  105. <script language="javascript">
  106. $(function () {
  107. $('.perm-all').click(function () {
  108. var checked = $(this).get(0).checked;
  109. var group = $(this).data('group');
  110. $(".perm-item[data-group='" + group + "'],.perm-all-item[data-group='" + group + "']").each(function () {
  111. $(this).get(0).checked = checked;
  112. })
  113. })
  114. $('.perm-all-item').click(function () {
  115. var checked = $(this).get(0).checked;
  116. var group = $(this).data('group');
  117. var parent = $(this).data('parent');
  118. var son = $(this).data('son');
  119. var grandson = $(this).data('grandson');
  120. $(this).parents("span").find(".perm-item").each(function () {
  121. $(this).get(0).checked = checked;
  122. });
  123. group_check(this);
  124. });
  125. $('.perm-item').click(function () {
  126. var group = $(this).data('group');
  127. var parent = $(this).data('parent');
  128. var son = $(this).data('son');
  129. var grandson = $(this).data('grandson');
  130. var check = false;
  131. $(this).closest('span').find(".perm-item").each(function () {
  132. if ($(this).get(0).checked) {
  133. check = true;
  134. return false;
  135. }
  136. });
  137. var allitem = $(this).parents("span").find(".perm-all-item");
  138. if (allitem.length == 1) {
  139. allitem.get(0).checked = check;
  140. }
  141. group_check(this);
  142. });
  143. $(".panel-body").find("span").each(function (index, item) {
  144. if ($(this).find("label").length != 1) {
  145. $($(this).find("label").get(0)).wrap("<div class='col-sm-2' style='white-space:nowrap;'></div>");
  146. $($(this).find("label").not($(this).find("label").get(0))).wrapAll("<div class='col-sm-10'></div>");
  147. }
  148. else {
  149. $($(this).find("label").get(0)).wrap("<div class='col-sm-12'></div>");
  150. }
  151. });
  152. $("form").submit(function () {
  153. $(this).attr('stop',1);
  154. var perms = [];
  155. $(".perms:checked").each(function (index,e) {
  156. perms[index]=$(this).val();
  157. });
  158. perms = perms.join(',')
  159. $("input[name=permsarray]").val(perms);
  160. $(this).attr('stop',0);
  161. return true;
  162. });
  163. });
  164. function group_check(obj) {
  165. var check = false;
  166. $(obj).parents('.perm-group').find(":checkbox").each(function (index, item) {
  167. if (item.checked) {
  168. check = true;
  169. }
  170. });
  171. var group = $(obj).eq(0).data('group');
  172. $(".perm-all[data-group=" + group + "]").get(0).checked = check;
  173. }
  174. </script>