setPermission.jsp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
  2. <!doctype html>
  3. <html>
  4. <head>
  5. <%@ include file="../../common/head.jsp"%>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  8. <link rel="stylesheet" href="../res/js/plugins/ztree/demo.css" type="text/css">
  9. <link rel="stylesheet" href="../res/js/plugins/ztree/metroStyle/metroStyle.css" type="text/css">
  10. <script type="text/javascript" src="../res/js/plugins/ztree/jquery.ztree.core.js"></script>
  11. <script type="text/javascript" src="../res/js/plugins/ztree/jquery.ztree.excheck.js"></script>
  12. <script type="text/javascript" src="../res/js/plugins/ztree/jquery.ztree.exedit.js"></script>
  13. <script>
  14. var role_id = "${role.id}";
  15. var zNodes;
  16. function stateFormatter(value, row, index) {
  17. if (row.set === 1) {
  18. return {
  19. checked: true
  20. };
  21. }
  22. if (row.set === 0) {
  23. return {
  24. checked: false
  25. }
  26. }
  27. return value;
  28. }
  29. var setting = {
  30. view: {
  31. // addHoverDom: addHoverDom,
  32. // removeHoverDom: removeHoverDom,
  33. selectedMulti: true
  34. },
  35. check: {
  36. enable: true
  37. },
  38. data: {
  39. simpleData: {
  40. enable: true
  41. }
  42. },
  43. edit: {
  44. enable: false
  45. },
  46. callback: {
  47. // onCheck: zTreeOnCheck
  48. }
  49. };
  50. $(document).ready(function(){
  51. $.get('getListMenu.cs?roleId=' + role_id,function(data){
  52. zNodes = data;
  53. $.fn.zTree.init($("#treePermission"), setting, zNodes);
  54. });
  55. });
  56. var newCount = 1;
  57. function addHoverDom(treeId, treeNode) {
  58. var sObj = $("#" + treeNode.tId + "_span");
  59. if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
  60. var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
  61. + "' title='add node' onfocus='this.blur();'></span>";
  62. sObj.after(addStr);
  63. var btn = $("#addBtn_"+treeNode.tId);
  64. if (btn) btn.bind("click", function(){
  65. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  66. zTree.addNodes(treeNode, {id:(100 + newCount), pId:treeNode.id, name:"new node" + (newCount++)});
  67. return false;
  68. });
  69. };
  70. function removeHoverDom(treeId, treeNode) {
  71. $("#addBtn_"+treeNode.tId).unbind().remove();
  72. };
  73. // function zTreeOnCheck(event, treeId, treeNode){
  74. // if(treeNode.level == 2 ){ //三级节点
  75. // parent_treeNode = treeNode.getParentNode();
  76. // if((parent_treeNode.val & treeNode.val) == 0 || parent_treeNode.val == 0){
  77. // if(treeNode.checked){
  78. // parent_treeNode.val += treeNode.val;
  79. // }
  80. // }
  81. // else if((parent_treeNode.val & treeNode.val) != 0){
  82. // if(!treeNode.checked){
  83. // parent_treeNode.val -= treeNode.val;
  84. // }
  85. // }
  86. // }
  87. // }
  88. function initNode_level1(){
  89. var nodes = $.fn.zTree.getZTreeObj("treePermission").getCheckedNodes(true);
  90. for(var i in nodes){
  91. var treeNode = nodes[i];
  92. if(treeNode.level == 1 ){ //三级节点
  93. treeNode.val = 0;
  94. }
  95. }
  96. for(var i in nodes){
  97. var treeNode = nodes[i];
  98. if(treeNode.level == 2 ){ //三级节点
  99. parent_treeNode = treeNode.getParentNode();
  100. if((parent_treeNode.val & treeNode.val) == 0 || parent_treeNode.val == 0){
  101. if(treeNode.checked){
  102. parent_treeNode.val += treeNode.val;
  103. }
  104. }
  105. }
  106. }
  107. }
  108. function setPermission(){
  109. var acs = [];
  110. initNode_level1();
  111. var nodes = $.fn.zTree.getZTreeObj("treePermission").getCheckedNodes(true);
  112. for(var i in nodes){
  113. var _t = {};
  114. if(nodes[i].level == 0){
  115. _t.menu_code = nodes[i].code;
  116. _t.action_val = 0;
  117. acs.push(_t);
  118. }
  119. else if(nodes[i].level == 1){
  120. _t.menu_code = nodes[i].code;
  121. _t.action_val = nodes[i].val;
  122. acs.push(_t);
  123. }
  124. }
  125. $.post('setPermission.cs', { acs: JSON.stringify(acs),roleId:role_id },
  126. function (text, status)
  127. {
  128. closeCurrentDlg();
  129. }
  130. );
  131. }
  132. </script>
  133. </head>
  134. <body class="gray-bg">
  135. <div class="wrapper wrapper-content animated fadeInRight">
  136. <div class="row row-lg">
  137. <div class="col-sm-1">
  138. <button class="btn btn-primary btn-sm" type="button" onclick="setPermission()">分配</button>
  139. <ul id="treePermission" class="ztree" style="width: 100%;"></ul>
  140. </div>
  141. </div>
  142. </div>
  143. </body>
  144. </html>