manage.jsp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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;
  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_USER_ID",
  27. index: "ADMIN_USER_ID",
  28. align: "center",
  29. sorttype: "string",
  30. editable: true,
  31. hidden: true
  32. //editoptions:{readonly:true} 如果要显示该列可以设置只读
  33. },
  34. {
  35. name: "ADMIN_USER_NAME",
  36. index: "ADMIN_USER_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: "ADMIN_NAME",
  48. index: "ADMIN_NAME",
  49. align: "center",
  50. sorttype: "string",
  51. editable: true,
  52. editrules: {required: true}
  53. },
  54. {
  55. name: "ADMIN_USER_PASSWORD",
  56. index: "ADMIN_USER_PASSWORD",
  57. align: "center",
  58. sorttype: "string",
  59. editable: true,
  60. editrules: {required: true},
  61. hidden: true
  62. },
  63. {
  64. name: "CREATE_DATETIME",
  65. index: "CREATE_DATETIME",
  66. align: "center",
  67. sorttype: "string"
  68. },
  69. {
  70. name: "CREATE_BY",
  71. index: "CREATE_BY",
  72. align: "center",
  73. sorttype: "string"
  74. },
  75. {
  76. name: "ADMIN_ROLE_NAME",
  77. index: "ADMIN_ROLE_NAME",
  78. align: "center",
  79. sorttype: "int",
  80. editable: true,
  81. edittype: "select",
  82. editoptions:{
  83. dataUrl: "${contextPath }/admin/adminuser/manageselect.html?type=0"
  84. }
  85. },
  86. {
  87. name: "IS_VALID", //对应数据库字段
  88. index: "IS_VALID", //按照哪个字段进行排序
  89. align: "center", //显示位置
  90. sorttype: "string", //字段类型
  91. editable: true, //是否可以编辑
  92. editrules: {required:true}, //验证规则
  93. formatter: "checkbox",
  94. formatoptions: {disabled:true},
  95. edittype: "checkbox", //可以编辑的类型。可选值:text, textarea, select, checkbox, password, button, image and file.
  96. editoptions: {value:"Yes:No"} //默认值 和下拉框的默认值不同
  97. }
  98. ],
  99. caption: "用户管理", //标题
  100. editurl: "${contextPath }/admin/adminuser/manageupdate.html", //编辑行后发送请求到服务器的url
  101. delurl: "${contextPath }/admin/adminuser/manageupdate.html", //删除行后发送请求到服务器的url
  102. pager: "#page", //#page分页控件绑定的位置对象
  103. rowNum: 100, //每页显示条数
  104. rowList: [100,200,300,400], //分页下拉选项内容
  105. rownumbers: true, //是否显示行数
  106. viewrecords: true, //是否显示总条数
  107. emptyrecords: "无数据", //服务器返回空列表时显示的内容
  108. autowidth: true, //自动调节宽度
  109. sortname: 'SORT', //按SORT进行排序 默认asc
  110. altRows: true, //设置表格是否允许行交替变色值
  111. altclass:"tdbgmouseover" //自定义隔行变色的样式
  112. });
  113. //获取数据集
  114. mydata = getLists();
  115. if(mydata!=null){
  116. for(var i=0;i<=mydata.length;i++){
  117. jQuery("#list").jqGrid('addRowData',i+1,mydata[i]);
  118. }
  119. jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
  120. }
  121. //绑定、设置工具栏
  122. jQuery("#list").jqGrid("navGrid","#page",{
  123. add: true, addtext: "添加",
  124. edit: true, edittext: "编辑",
  125. del: true, deltext: "删除",refresh: false,
  126. addfunc: addRow, //自定义添加方法
  127. editfunc: editRow, //自定义编辑方法
  128. delfunc: deleteRow, //自定义删除方法
  129. searchtext: "搜索",
  130. refreshtext: "刷新",
  131. alerttext:"请选择一条记录!"
  132. });
  133. }
  134. //获取服务器数据
  135. function getLists(){
  136. $.ajax({
  137. async: false,
  138. type: 'POST',
  139. dataType:'json', //返回类型json
  140. url: "${contextPath }/admin/adminuser/managelist.html",
  141. error: function(){alert("系统错误");},
  142. success: function(json){
  143. mydata = json;
  144. }
  145. });
  146. return mydata;
  147. }
  148. //自定义添加方法
  149. function addRow(){
  150. operType = "add"; //自定义验证时使用的参数
  151. $("#list").jqGrid("setColProp", "ADMIN_USER_PASSWORD", {hidden: false});
  152. $("#list").jqGrid("setColProp", "ADMIN_USER_PASSWORD", {editrules: {required: true}});
  153. $("#list").jqGrid("editGridRow","new",{
  154. closeAfterAdd: false, //编辑弹出层不关闭
  155. //reloadAfterSubmit: true, //如果不重载数据想看到新增后的数据改变样子就需要添加这个属性
  156. left:250, //弹出框左边距
  157. top:30, //弹出框上边距
  158. afterSubmit: function(response, postdata){
  159. var result = eval('(' + response.responseText + ')');
  160. var errors = "";
  161. if(result.status == "success"){
  162. $("#list").clearGridData(); //清空原grid数据
  163. loadList(); //重新载入服务器数据
  164. }
  165. //需要返回条新记录给jqgrid知道
  166. var newId = null;
  167. return [result.success, errors, newId];
  168. }
  169. });
  170. $("#list").jqGrid("setColProp", "ADMIN_USER_PASSWORD", {hidden: true});
  171. }
  172. //自定义编辑方法
  173. function editRow(){
  174. $("#list").jqGrid("setColProp", "ADMIN_USER_PASSWORD", {hidden: false});
  175. $("#list").jqGrid("setColProp", "ADMIN_USER_PASSWORD", {editrules: {required: false}});
  176. operType = "modif"; //自定义验证时使用的参数
  177. //$("#list").jqGrid("setCell", selId, "ADMIN_USER_PASSWORD", "1");
  178. var row = $("#list").jqGrid("getGridParam","selrow");
  179. $("#list").jqGrid("editGridRow",row,{closeAfterEdit: false,reloadAfterSubmit: false});
  180. $("#list").jqGrid("setColProp", "ADMIN_USER_PASSWORD", {hidden: true});
  181. }
  182. //自定义删除方法
  183. function deleteRow(){
  184. var row = $("#list").jqGrid("getGridParam","selrow");
  185. $("#list").jqGrid("delGridRow", row,{
  186. serializeDelData: function (postdata) {
  187. var rowData = $("#list").jqGrid("getRowData",postdata.id); //获取当前选中行真实对象
  188. //自定义配置提交到服务器时候的数据
  189. return{
  190. ADMIN_USER_ID: rowData.ADMIN_USER_ID,
  191. oper: postdata.oper,
  192. ADMIN_USER_NAME: rowData.ADMIN_USER_NAME,
  193. ADMIN_USER_PASSWORD: rowData.ADMIN_USER_PASSWORD,
  194. ADMIN_NAME: rowData.ADMIN_NAME,
  195. IS_VALID: rowData.IS_VALID,
  196. ADMIN_ROLE_NAME: rowData.ADMIN_ROLE_NAME
  197. };
  198. }
  199. });
  200. }
  201. //自定义验证名称是否存在方法
  202. function checkName(value, colname){
  203. var flag = 0;
  204. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  205. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  206. $.ajax({
  207. async: false,
  208. type: 'POST',
  209. data: "entityName="+value+"&type="+operType+"&entityId="+rowData.ADMIN_USER_ID,
  210. dataType: 'json',
  211. url: "${contextPath}/admin/adminuser/managecheck.html",
  212. error: function(){alert("系统错误");},
  213. success: function(json){
  214. flag = json.status;
  215. }
  216. });
  217. if(flag == 0){
  218. return [true,""];
  219. }else{
  220. return [false,"系统用户名称已经存在!"];
  221. }
  222. }
  223. </script>
  224. </head>
  225. <body style="background-color: #E0E0E0">
  226. <div>
  227. <div class="navfrm">
  228. <span>当前位置:</span>
  229. <span><a href="${contextPath }/admin/welcome.html">首页</a></span>
  230. <span>&nbsp;>>&nbsp;</span>
  231. <span>用户管理</span>
  232. </div>
  233. <table id="list"></table>
  234. <div id="page"></div>
  235. <div id="msgbox" title="" style="display:none"></div>
  236. </div>
  237. </body>
  238. </html>