role.jsp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <%@ page contentType="text/html; charset=utf-8" session="false" %>
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
  4. <head>
  5. <title>我的工作台</title>
  6. <%@ include file="../common/header.jsp" %>
  7. <script type="text/javascript">
  8. var mydata,operType,loadCount = 0;
  9. $(document).ready( function() {
  10. loadList(); //加载jqgrid
  11. $("#list").jqGrid("setGridHeight",$(window).height() - 105);
  12. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
  13. });
  14. $(window).resize(function(){
  15. $("#list").jqGrid("setGridHeight",$(window).height() - 105);
  16. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
  17. });
  18. //jqgrid初始化
  19. function loadList(){
  20. jQuery("#list").jqGrid({
  21. datatype: "local", //从服务器端返回的数据类型,(表格期望接收的数据类型)。可选类型:xml,xmlstring,json,local,function
  22. height: "70%", //高度
  23. colNames:["主键","角色名称", "创建时间", "创建人", "是否启用"], //列名
  24. colModel:[
  25. {
  26. name: "ADMIN_ROLE_ID",
  27. index: "ADMIN_ROLE_ID",
  28. align: "center",
  29. sorttype: "string",
  30. editable: true,
  31. hidden: true
  32. //editoptions:{readonly:true} 如果要显示该列可以设置只读
  33. },
  34. {
  35. name: "ADMIN_ROLE_NAME",
  36. index: "ADMIN_ROLE_NAME",
  37. align: "center",
  38. sorttype: "string",
  39. editable: true,
  40. editrules:{
  41. required: true,
  42. custom: true,
  43. custom_func: checkName
  44. }
  45. },
  46. {
  47. name: "CREATE_DATETIME",
  48. index: "CREATE_DATETIME",
  49. align: "center",
  50. sorttype: "string"
  51. },
  52. {
  53. name: "CREATE_BY",
  54. index: "CREATE_BY",
  55. align: "center",
  56. sorttype: "string"
  57. },
  58. {
  59. name: "IS_VALID", //对应数据库字段
  60. index: "IS_VALID", //按照哪个字段进行排序
  61. align: "center", //显示位置
  62. sorttype: "string", //字段类型
  63. editable: true, //是否可以编辑
  64. editrules: {required:true}, //验证规则
  65. formatter: "checkbox",
  66. formatoptions: {disabled:true},
  67. edittype: "checkbox", //可以编辑的类型。可选值:text, textarea, select, checkbox, password, button, image and file.
  68. editoptions: {value:"Yes:No"} //默认值 和下拉框的默认值不同
  69. }
  70. ],
  71. caption: "角色管理", //标题
  72. editurl: "${contextPath }/admin/adminuser/roleupdate.html", //编辑行后发送请求到服务器的url
  73. delurl: "${contextPath }/admin/adminuser/roleupdate.html", //删除行后发送请求到服务器的url
  74. pager: "#page", //#page分页控件绑定的位置对象
  75. rowNum: 100, //每页显示条数
  76. rowList: [100,200,300,400], //分页下拉选项内容
  77. rownumbers: true, //是否显示行数
  78. viewrecords: true, //是否显示总条数
  79. emptyrecords: "无数据", //服务器返回空列表时显示的内容
  80. autowidth: true, //自动调节宽度
  81. sortname: "SORT", //按SORT进行排序 默认asc
  82. altRows: true, //设置表格是否允许行交替变色值
  83. altclass: "tdbgmouseover" //自定义隔行变色的样式
  84. });
  85. //获取数据集
  86. mydata = getLists();
  87. if(mydata!=null){
  88. for(var i=0;i<=mydata.length;i++){
  89. jQuery("#list").jqGrid('addRowData',i+1,mydata[i]);
  90. }
  91. jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
  92. }
  93. //绑定、设置工具栏
  94. jQuery("#list").jqGrid("navGrid","#page",{
  95. add: true, addtext: "添加",
  96. edit: true, edittext: "编辑",
  97. del: true, deltext: "删除",refresh: false,search: false,
  98. addfunc: addRow, //自定义添加方法
  99. editfunc: editRow, //自定义编辑方法
  100. delfunc: deleteRow, //自定义删除方法
  101. searchtext: "搜索",
  102. refreshtext: "刷新",
  103. alerttext:"请选择一条记录!"
  104. });
  105. if(loadCount == 0){
  106. $("#list").navButtonAdd("#page",{
  107. caption:"页面权限",
  108. buttonicon:"ui-icon-document",
  109. position: "last",
  110. title:"页面权限",
  111. cursor: "pointer", //光标类型
  112. onClickButton: viewRow
  113. });
  114. $("#list").navButtonAdd("#page",{
  115. caption:"栏舍权限",
  116. buttonicon:"ui-icon-document",
  117. position: "last",
  118. title:"栏舍权限",
  119. cursor: "pointer", //光标类型
  120. onClickButton: feedpRow
  121. });
  122. }
  123. }
  124. //获取服务器数据
  125. function getLists(){
  126. $.ajax({
  127. async: false,
  128. type: 'POST',
  129. dataType:'json', //返回类型json
  130. url: "${contextPath }/admin/adminuser/rolelist.html",
  131. error: function(){alert("系统错误");},
  132. success: function(json){
  133. mydata = json;
  134. }
  135. });
  136. return mydata;
  137. }
  138. //自定义添加方法
  139. function addRow(){
  140. loadCount = 1;
  141. operType = "add"; //自定义验证时使用的参数
  142. $("#list").jqGrid("editGridRow","new",{
  143. closeAfterAdd: false, //编辑弹出层不关闭
  144. //reloadAfterSubmit: true, //如果不重载数据想看到新增后的数据改变样子就需要添加这个属性
  145. afterSubmit: function(response, postdata){
  146. var result = eval('(' + response.responseText + ')');
  147. var errors = "";
  148. if(result.status == "success"){
  149. $("#list").clearGridData(); //清空原grid数据
  150. loadList(); //重新载入服务器数据
  151. }
  152. //需要返回条新记录给jqgrid知道
  153. var newId = null;
  154. return [result.success, errors, newId];
  155. }
  156. });
  157. }
  158. //自定义编辑方法
  159. function editRow(){
  160. operType = "modif"; //自定义验证时使用的参数
  161. var row = $("#list").jqGrid("getGridParam","selrow");
  162. $("#list").jqGrid("editGridRow",row,{closeAfterEdit: false,reloadAfterSubmit: false});
  163. }
  164. //自定义删除方法
  165. function deleteRow(){
  166. var row = $("#list").jqGrid("getGridParam","selrow");
  167. $("#list").jqGrid("delGridRow", row,{
  168. serializeDelData: function (postdata) {
  169. var rowData = $("#list").jqGrid("getRowData",postdata.id); //获取当前选中行真实对象
  170. //自定义配置提交到服务器时候的数据
  171. return{
  172. ADMIN_ROLE_ID: rowData.ADMIN_ROLE_ID,
  173. oper: postdata.oper,
  174. ADMIN_ROLE_NAME: rowData.ADMIN_ROLE_NAME,
  175. IS_VALID: rowData.IS_VALID
  176. };
  177. }
  178. });
  179. }
  180. //页面权限
  181. function viewRow(){
  182. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  183. if(selId!=null){
  184. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  185. document.location.href="${contextPath}/admin/adminuser/privilege.html?adminRoleId="+rowData.ADMIN_ROLE_ID+"&type=1";
  186. }else{
  187. alert("请选择角色");
  188. }
  189. }
  190. //栏舍权限
  191. function feedpRow(){
  192. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  193. if(selId!=null){
  194. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  195. document.location.href="${contextPath}/admin/adminuser/feedprow.html?adminRoleId="+rowData.ADMIN_ROLE_ID+"&type=1";
  196. }else{
  197. alert("请选择角色");
  198. }
  199. }
  200. //自定义验证名称是否存在方法
  201. function checkName(value, colname){
  202. var flag = 0;
  203. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  204. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  205. $.ajax({
  206. async: false,
  207. type: 'POST',
  208. data: "entityName="+value+"&type="+operType+"&entityId="+rowData.ADMIN_ROLE_ID,
  209. dataType: 'json',
  210. url: "${contextPath}/admin/adminuser/rolecheck.html",
  211. error: function(){alert("系统错误");},
  212. success: function(json){
  213. flag = json.status;
  214. }
  215. });
  216. if(flag == 0){
  217. return [true,""];
  218. }else{
  219. return [false,"角色名称已经存在!"];
  220. }
  221. }
  222. </script>
  223. </head>
  224. <body style="background-color: #E0E0E0">
  225. <div>
  226. <div class="navfrm">
  227. <span>当前位置:</span>
  228. <span><a href="${contextPath }/admin/welcome.html">首页</a></span>
  229. <span>&nbsp;>>&nbsp;</span>
  230. <span>角色管理</span>
  231. </div>
  232. <table id="list"></table>
  233. <div id="page"></div>
  234. <div id="msgbox" title="" style="display:none"></div>
  235. </div>
  236. </body>
  237. </html>