setPermission2.jsp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 href="../res/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />
  9. <script src="../res/js/plugins/bootstrap-table/bootstrap-table.js"></script>
  10. <script src="../res/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
  11. <script src="../res/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
  12. <script>
  13. var role_id = "${role.id}";
  14. var action_list;
  15. function stateFormatter(value, row, index) {
  16. if (row.set === 1) {
  17. return {
  18. checked: true
  19. };
  20. }
  21. if (row.set === 0) {
  22. return {
  23. checked: false
  24. }
  25. }
  26. return value;
  27. }
  28. function setActionVal(value,row,index){
  29. // if(parseInt(row.menu_pid) != 0){
  30. // return '<select id="action_select_' + row.menu_code + '" onclick="select_action(' + row.menu_code + ')">' +
  31. // '<option value="0"> --选择可以操作功能 -- </option>'
  32. // '</select>';
  33. // }
  34. // else{
  35. // return '';
  36. // }
  37. // var data = toJSON(${actionList});
  38. var _ret = '';
  39. for(var obj in action_list){
  40. if(action_list[obj].menu_code == row.menu_code){
  41. _ret += '<input type="checkbox" name="' + row.menu_code + '" value="' + action_list[obj].action_val + '" ';
  42. if(parseInt(action_list[obj].set) > 0){
  43. _ret += ' checked="checked" ';
  44. }
  45. _ret += '>' + action_list[obj].action_name;
  46. }
  47. }
  48. return _ret;
  49. }
  50. function select_action(menu_code){
  51. var _id = 'action_select_' + menu_code;
  52. if($('#'+_id + ' option').size() == 1){
  53. $.get('getMenuAction.cs?menuCode=' + menu_code, function(data){
  54. for(var obj in data){
  55. $('#' + _id).append('<option value="' + data[obj].val + '">' + data[obj].name + '</option>');
  56. // $('#' + _id).append('<input type="checkbox" >' + data[obj].name);
  57. }
  58. });
  59. }
  60. }
  61. function setPermission(){
  62. var acs = [];
  63. $($('#tab_menu').bootstrapTable('getSelections')).each(function() {
  64. var _t = {};
  65. _t.menu_code = this.menu_code;
  66. _t.action_val = 0;
  67. $('input[name="'+ this.menu_code +'"]:checked ').each(function(){
  68. _t.action_val += parseInt($(this).val());
  69. });
  70. acs.push(_t);
  71. // acs.push(JSON.stringify(_t));
  72. });
  73. $.post('setPermission.cs', { acs: JSON.stringify(acs),roleId:role_id },
  74. function (text, status)
  75. {
  76. closeCurrentDlg();
  77. }
  78. );
  79. }
  80. </script>
  81. </head>
  82. <body class="gray-bg">
  83. <div class="wrapper wrapper-content animated fadeInRight">
  84. <!-- <div class="ibox " style=""> -->
  85. <!-- <div class="ibox-content"> -->
  86. <script>
  87. $.get('getAllAction.cs?roleId=' + role_id, function(data){
  88. action_list = data;
  89. });
  90. </script>
  91. <div class="row row-lg">
  92. <div class="col-sm-12">
  93. <table id="tab_menu"
  94. data-toggle="table"
  95. data-url="getListMenu.cs?roleId=${role.id}"
  96. data-method="get"
  97. data-data-type="json"
  98. data-query-params="query"
  99. data-mobile-responsive="true"
  100. >
  101. <thead>
  102. <tr>
  103. <th data-checkbox="true" data-click-to-select="true" data-formatter="stateFormatter"></th>
  104. <th data-field="menu_id" >菜单id</th>
  105. <th data-field="menu_pid">上级菜单ID</th>
  106. <th data-field="menu_name">菜单名称</th>
  107. <th data-field="menu_code">代码</th>
  108. <th data-field="action_val" data-formatter="setActionVal">操作权限</th>
  109. </tr>
  110. </thead>
  111. </table>
  112. <button class="btn btn-primary" type="button" onclick="setPermission()"><i class="fa fa-info"></i>&nbsp;确定</button>
  113. </div>
  114. </div>
  115. <!-- </div> -->
  116. <!-- </div> -->
  117. </div>
  118. </body>
  119. </html>